コード例 #1
0
 public static function uploadHistory(User $user, $clear = null)
 {
     $channel = ChannelsCollection::get()->getChannelById($user->getChannelId());
     if (!$channel) {
         $channel = new Channel($user->getChannelId(), 'Приват_' . $user->getChannelId());
         $channel->setOwnerId($user->getId());
         ChannelsCollection::get()->addChannel($channel);
     }
     $log = $channel->getHistory($user->getLastMsgId());
     $client = (new UserCollection())->attach($user);
     $historyResponse = (new HistoryResponse())->setChannelId($user->getChannelId());
     if (!$user->getLastMsgId()) {
         $historyResponse->setClear($clear);
     }
     foreach ($log as $response) {
         if ($user->getBlacklist()->isBanned($response[Channel::FROM_USER_ID])) {
             continue;
         }
         if (isset($response[Channel::TO_NAME])) {
             if ($response[Channel::FROM_USER_ID] == $user->getId() || $response[Channel::TO_NAME] == $user->getProperties()->getName()) {
                 $historyResponse->addResponse($response);
             }
             continue;
         }
         $historyResponse->addResponse($response);
     }
     $historyResponse->setLastMsgId($channel->getLastMsgId());
     $client->setResponse($historyResponse)->notify(false);
 }
コード例 #2
0
 private function unbanResponse(User $user, UserDAO $unBanUserDAO)
 {
     $response = (new MessageResponse())->setMsg(MsgToken::create('UserIsUnbanned', $unBanUserDAO->getPropeties()->getName()))->setTime(null)->setChannelId($user->getChannelId())->setGuests(DI::get()->getUsers()->getUsersByChatId($user->getChannelId()));
     (new UserCollection())->attach($user)->setResponse($response)->notify(false);
     if ($unBanUser = DI::get()->getUsers()->getClientById($unBanUserDAO->getId())) {
         $response = (new MessageResponse())->setMsg(MsgToken::create('UserUnbannedYou', $user->getProperties()->getName()))->setChannelId($unBanUser->getChannelId())->setTime(null);
         (new UserCollection())->attach($unBanUser)->setResponse($response)->notify(false);
     }
 }
コード例 #3
0
 public function getHistory(User $user)
 {
     if (!isset($this->channels[$user->getChannelId()])) {
         return [];
     }
     $channel = $this->channels[$user->getChannelId()];
     /* @var $channel Channel */
     return $channel->getHistory($user->getLastMsgId());
 }
コード例 #4
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());
 }
コード例 #5
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);
     }
 }
コード例 #6
0
 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();
 }
コード例 #7
0
ファイル: Chat.php プロジェクト: jackblackjack/sociochat
 /**
  * @param User $from
  */
 private function respondOnMalformedJSON(User $from)
 {
     $response = (new ErrorResponse())->setErrors(['request' => $from->getLang()->getPhrase('MalformedJsonRequest')])->setChannelId($from->getChannelId());
     (new UserCollection())->attach($from)->setResponse($response)->notify();
 }
コード例 #8
0
 /**
  * @param User $user
  */
 private function respondFloodError(User $user)
 {
     $response = (new ErrorResponse())->setChannelId($user->getChannelId())->setErrors(['flood' => $user->getLang()->getPhrase('FloodDetected')]);
     (new UserCollection())->setResponse($response)->attach($user)->notify(false);
 }
コード例 #9
0
 private static function informOnPendingExit(User $user)
 {
     $response = (new MessageResponse())->setChannelId($user->getChannelId())->setTime(null)->setDualChat('exit')->setMsg(MsgToken::create('ExitDualQueue'));
     (new UserCollection())->attach($user)->setResponse($response)->notify(false);
 }
コード例 #10
0
 private function guestsUpdateResponse(User $user, $oldName)
 {
     $response = (new MessageResponse())->setGuests(DI::get()->getUsers()->getUsersByChatId($user->getChannelId()))->setChannelId($user->getChannelId())->setTime(null);
     $props = $user->getProperties();
     if ($props->getName() != $oldName) {
         $response->setMsg(MsgToken::create('UserChangedName', $oldName, $props->getName()));
     }
     DI::get()->getUsers()->setResponse($response)->notify();
 }
コード例 #11
0
 private static function sendPendingResponse(User $user, MsgContainer $msg)
 {
     $response = (new MessageResponse())->setMsg($msg)->setTime(null)->setChannelId($user->getChannelId())->setDualChat('init');
     (new UserCollection())->attach($user)->setResponse($response)->notify(false);
 }
コード例 #12
0
 private function guestResponse(User $user)
 {
     $response = (new MessageResponse())->setMsg(MsgRaw::create(''))->setTime(null)->setChannelId($user->getChannelId())->setGuests(DI::get()->getUsers()->getUsersByChatId($user->getChannelId()));
     (new UserCollection())->attach($user)->setResponse($response)->notify(false);
 }
コード例 #13
0
 private static function informYouselfOnExit(User $user)
 {
     $response = (new MessageResponse())->setChannelId($user->getChannelId())->setTime(null)->setDualChat('exit')->setMsg(MsgToken::create('ReturnedToMainChat'));
     (new UserCollection())->attach($user)->setResponse($response)->notify(false);
 }
コード例 #14
0
 /**
  * @param $user
  */
 private function sendNotifyResponse(User $user)
 {
     $response = (new MessageResponse())->setChannelId($user->getChannelId())->setTime(null)->setMsg(MsgToken::create('ProfileUpdated'));
     (new UserCollection())->attach($user)->setResponse($response)->notify(false);
     $response = (new UserPropetiesResponse())->setUserProps($user)->setChannelId($user->getChannelId());
     (new UserCollection())->attach($user)->setResponse($response)->notify(false);
 }
コード例 #15
0
 private static function sendPendingResponse(User $user, MsgContainer $msg)
 {
     $response = (new MessageResponse())->setMsg($msg)->setTime(null)->setGuests(DI::get()->getUsers()->getUsersByChatId($user->getChannelId()))->setChannelId($user->getChannelId());
     (new UserCollection())->attach($user)->setResponse($response)->notify(false);
 }
コード例 #16
0
ファイル: AdsFilter.php プロジェクト: jackblackjack/sociochat
    private function showAd(User $user)
    {
        $msg = MsgRaw::create('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
						<ins class="adsbygoogle"
						     style="display:inline-block;width:320px;height:50px"
						     data-ad-client="ca-pub-1352019659330191"
						     data-ad-slot="9172675664"></ins>
						<script>
							(adsbygoogle = window.adsbygoogle || []).push({});
						</script>');
        $response = (new MessageResponse())->setChannelId($user->getChannelId())->setMsg($msg);
        (new UserCollection())->setResponse($response)->attach($user)->notify(false);
    }
コード例 #17
0
 public static function make(User $user, $errors = null)
 {
     $response = (new ErrorResponse())->setErrors(is_array($errors) ? $errors : [$errors ?: $user->getLang()->getPhrase('RequiredActionNotSpecified')])->setChannelId($user->getChannelId());
     (new UserCollection())->attach($user)->setResponse($response)->notify();
 }