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);
 }
示例#2
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;
 }
 private static function checkRestrictions(ChainContainer $chain, UserCollection $users)
 {
     $user = $chain->getFrom();
     $request = $chain->getRequest();
     $lang = $user->getLang();
     if (!isset($request[PropertiesDAO::USER_ID])) {
         RespondError::make($user);
         return;
     }
     if (!($desiredUser = $users->getClientById($request[PropertiesDAO::USER_ID]))) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('ThatUserNotFound')]);
         return;
     }
     if ($desiredUser->getId() == $user->getId()) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('CantDoToYourself')]);
         return;
     }
     if ($desiredUser->isInPrivateChat()) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('UserAlreadyInPrivate')]);
         return;
     }
     if ($user->isInPrivateChat()) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('YouAlreadyInPrivate')]);
         return;
     }
     return $desiredUser;
 }