Esempio n. 1
0
 /**
  * @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);
     }
 }
 /**
  * @param User $user
  * @param UserCollection $users
  */
 private static function moveUsersToPublic(User $user, UserCollection $users)
 {
     $partners = $users->getUsersByChatId($user->getChannelId());
     $response = (new MessageResponse())->setTime(null)->setMsg(MsgToken::create('UserLeftPrivate', $user->getProperties()->getName()))->setDualChat('exit')->setChannelId($user->getChannelId());
     $users->setResponse($response)->notify();
     foreach ($partners as $pUser) {
         $pUser->setChannelId(1);
         $pUser->save();
     }
 }
Esempio n. 3
0
 private function notifyOnClose(User $user, UserCollection $clients)
 {
     $response = new MessageResponse();
     if ($user->isAsyncDetach()) {
         $response->setMsg(MsgToken::create('LeavesUs', $user->getProperties()->getName()));
     }
     $response->setTime(null)->setGuests($clients->getUsersByChatId($user->getChannelId()))->setChannelId($user->getChannelId());
     $clients->setResponse($response)->notify();
     ChannelNotifier::updateChannelInfo($clients, ChannelsCollection::get());
 }
 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 function sendPublic(UserCollection $clients, User $user, $msg, $isSelf)
 {
     $props = $user->getProperties();
     $filteredMsg = RudeFilter::parse($msg);
     if (mb_strlen($filteredMsg) != mb_strlen($msg)) {
         $props->setRudeCount($props->getRudeCount() + 1);
     }
     $props->setWordsCount($props->getWordsCount() + mb_substr_count($msg, ' ') + 1);
     $response = (new MessageResponse())->setMsg(Msg::create($msg))->setFilteredMsg(Msg::create($filteredMsg))->setTime(null)->setChannelId($user->getChannelId());
     if (!$isSelf) {
         $response->setFrom($user);
     }
     $clients->setResponse($response)->notify();
 }
Esempio n. 6
0
 /**
  * @param $sessionInfo
  * @param UserCollection $clients
  * @param Logger $logger
  * @param User $newUserWrapper
  * @return UserDAO
  */
 private function handleKnownUser($sessionInfo, UserCollection $clients, Logger $logger, User $newUserWrapper)
 {
     $user = UserDAO::create()->getById($sessionInfo['user_id']);
     $lang = $newUserWrapper->getLang();
     if ($oldClient = $clients->getClientById($user->getId())) {
         if ($timer = $oldClient->getDisconnectTimer()) {
             DI::get()->container()->get('eventloop')->cancelTimer($timer);
             $logger->info("Deffered disconnection timer canceled: connection_id = {$newUserWrapper->getConnectionId()} for user_id = {$sessionInfo['user_id']}", [__METHOD__]);
             if ($oldClient->getConnectionId()) {
                 $oldClient->setAsyncDetach(false)->send(['disconnect' => 1]);
                 $clients->detach($oldClient);
                 $newUserWrapper->setLastMsgId(-1);
             }
         } elseif ($oldClient->getConnectionId()) {
             // If there is no timer set, then
             // 1) it's regular user visit
             // 2) an attempt to open another browser tab
             // 3) window reload
             $oldClient->setAsyncDetach(false)->send(['msg' => $lang->getPhrase('DuplicateConnection'), 'disconnect' => 1]);
             $clients->detach($oldClient);
             if ($oldClient->getIp() == $newUserWrapper->getIp()) {
                 $newUserWrapper->setLastMsgId(-1);
             }
             $logger->info("Probably tabs duplication detected: detaching = {$oldClient->getConnectionId()} for user_id = {$oldClient->getId()}}", [__METHOD__]);
         }
         if ($newUserWrapper->getLastMsgId()) {
             $logger->info("Re-established connection for user_id = {$sessionInfo['user_id']}, lastMsgId = {$newUserWrapper->getLastMsgId()}", [__METHOD__]);
         }
     }
     return $user;
 }
 public static function updateGuestsList(UserCollection $userCollection, $channelId)
 {
     $userCollection->setResponse((new MessageResponse())->setGuests($userCollection->getUsersByChatId($channelId))->setChannelId($channelId))->notify(false);
 }
Esempio n. 8
0
 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();
 }