public function pushToHistory(MessageResponse $response)
 {
     if (!isset($this->channels[$response->getChannelId()])) {
         throw new BaseException('Channel id = ' . $response->getChannelId() . ' has not been initialized');
     }
     /* @var $channel Channel */
     $channel = $this->channels[$response->getChannelId()];
     return $channel->pushResponse($response);
 }
Example #2
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());
 }
Example #3
0
 /**
  * @param MessageResponse $response
  * @return array
  */
 private function makeRecord(MessageResponse $response)
 {
     $record = [self::FROM_USER_ID => null, self::FROM_NAME => $response->getFromName(), self::TIME => $response->getTime(), self::MSG => $response->getFilteredMsg() ?: $response->getMsg()];
     if ($from = $response->getFrom()) {
         $dir = DI::get()->getConfig()->uploads->avatars->wwwfolder . DIRECTORY_SEPARATOR;
         $info = [self::FROM_USER_ID => $response->getFrom()->getId(), self::TIM => $from->getProperties()->getTim()->getName(), self::SEX => $from->getProperties()->getSex()->getName()];
         if ($from->getProperties()->getAvatarThumb()) {
             $info += [self::AVATAR_THUMB => $dir . $from->getProperties()->getAvatarThumb()];
         }
         $record += [self::USER_INFO => $info];
         $record[self::FROM_USER_ID] = $response->getFrom()->getId();
     }
     if ($response->getToUserName()) {
         $record += [self::TO_NAME => $response->getToUserName()];
         return $record;
     }
     return $record;
 }