private function sendPrivate(User $from, User $recipient, $msg) { $log = false; $response = (new MessageResponse())->setMsg(Msg::create($msg))->setFilteredMsg(Msg::create(RudeFilter::parse($msg)))->setTime(null)->setChannelId($from->getChannelId()); $sender = new UserCollection(); if ($from->getId() != $recipient->getId()) { $response->setFrom($from)->setToUserName($recipient->getProperties()->getName()); $sender->attach($recipient); $log = true; } $sender->attach($from)->setResponse($response)->notify($log); }
/** * @param User $user * @param UserCollection $userCollection */ public function notifyChat(User $user, UserCollection $userCollection) { $channelId = $user->getChannelId(); DI::get()->getLogger()->info("Total user count {$userCollection->getTotalCount()}", [__CLASS__]); if ($user->isInPrivateChat()) { $dualUsers = new UserCollection(); $dualUsers->attach($user); $response = (new MessageResponse())->setTime(null)->setGuests($userCollection->getUsersByChatId($channelId))->setChannelId($channelId); if ($userCollection->getClientsCount($channelId) > 1) { $dualUsers = $userCollection; $response->setMsg(MsgToken::create('PartnerIsOnline'))->setDualChat('match'); } elseif ($num = PendingDuals::get()->getUserPosition($user)) { $response->setMsg(MsgToken::create('StillInDualSearch', $num))->setDualChat('init'); } else { $response->setMsg(MsgToken::create('YouAreAlone'))->setDualChat('match'); } if ($user->getLastMsgId()) { $response->setMsg(Msg::create(null)); } $dualUsers->setResponse($response)->notify(false); } else { ChannelNotifier::welcome($user, $userCollection); ChannelNotifier::indentifyChat($user, $userCollection, true); } }
private static function sendRenewPositions(array $userIds, UserCollection $users) { if (empty($userIds)) { return; } $notification = new UserCollection(); foreach ($userIds as $userId) { $user = $users->getClientById($userId); $response = (new MessageResponse())->setGuests(DI::get()->getUsers()->getUsersByChatId($user->getChannelId()))->setChannelId($user->getChannelId()); $notification->attach($user)->setResponse($response); } $notification->notify(false); }
private static function sendMatchResponse(array $users, MsgContainer $msg) { $notification = new UserCollection(); foreach ($users as $user) { $notification->attach($user); } $user = $users[0]; /* @var $user User */ $response = (new MessageResponse())->setDualChat('match')->setMsg($msg)->setChannelId($user->getChannelId())->setGuests($users); $notification->setResponse($response)->notify(); }