/**
  * @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();
     }
 }
示例#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());
 }
 public static function updateGuestsList(UserCollection $userCollection, $channelId)
 {
     $userCollection->setResponse((new MessageResponse())->setGuests($userCollection->getUsersByChatId($channelId))->setChannelId($channelId))->notify(false);
 }