/**
  * @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);
     }
 }
 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());
 }
 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);
     }
 }
 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 function updateSessionId(User $user, $oldUserId)
 {
     SessionDAO::create()->dropByUserId($oldUserId);
     $session = SessionDAO::create()->getByUserId($user->getId());
     $session->setSessionId($user->getWSRequest()->getCookie('token'))->setAccessTime(date(self::TIMESTAMP))->setUserId($user->getId());
     $session->save();
     PropertiesDAO::create()->dropByUserId($oldUserId);
     UserBlacklistDAO::create()->dropByUserId($oldUserId);
     NameChangeDAO::create()->dropByUserId($oldUserId);
     UserDAO::create()->dropById($oldUserId);
 }
Beispiel #6
0
 public function run(User $user, $args)
 {
     $users = DI::get()->getUsers()->getAll();
     $logger = DI::get()->getLogger();
     /** @var User $user */
     foreach ($users as $user) {
         $user->save(true);
         $logger->info('User data for ' . $user->getId() . ' is saved.');
     }
     return ['User data has flushed to disk!', true];
 }
 /**
  * @param User $user
  * @param array $timers
  * @return array
  */
 private function setTimer(User $user, array &$timers)
 {
     $container = DI::get()->container();
     $loop = $container->get('eventloop');
     $config = $container->get('config');
     $timeout = $config->flood->timeout;
     $penalty = $config->flood->penalty;
     $timerCallback = function () use($user, &$timers) {
         unset($timers[$user->getId()]);
     };
     if (isset($timers[$user->getId()])) {
         $loop->cancelTimer($timers[$user->getId()]);
         $timeout += $penalty;
     }
     $timer = $loop->addTimer($timeout, $timerCallback);
     $timers[$user->getId()] = $timer;
 }
 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);
 }
 private function searchUser(User $from, $userId)
 {
     if ($userId == '') {
         return null;
     }
     if ($userId == $from->getId()) {
         return $from;
     }
     $form = (new Form())->import([UserDAO::ID => $userId])->addRule(UserDAO::ID, Rules::isUserOnline(), $from->getLang()->getPhrase('UserIsNotOnline'));
     if (!$form->validate()) {
         RespondError::make($from, $form->getErrors());
         DI::get()->getLogger()->warn("Trying to find userId = {$userId} for private message but not found", [__CLASS__]);
         return false;
     }
     $recipient = $form->getResult(UserDAO::ID);
     /* @var $recipient User */
     return $recipient;
 }
 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);
 }
Beispiel #11
0
 /**
  * @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();
 }
Beispiel #12
0
 public function run(User $user, $args)
 {
     return ['<b><i>' . $user->getProperties()->getName() . ' ' . $args . '</i></b>', false];
 }
 private function checkReferral(User $user)
 {
     $ref = ReferralDAO::create()->getFirstRefByUserId($user->getId());
     if (!$ref) {
         return;
     }
     $users = DI::get()->getUsers();
     if ($refUserOnline = $users->getClientById($ref->getRefUserId())) {
         $refUser = $refUserOnline->getUserDAO();
     } else {
         $refUser = UserDAO::create()->getById($ref->getRefUserId());
     }
     if (!$refUser->getId()) {
         return;
     }
     $mark = UserKarmaDAO::create()->setUserId($refUser->getId())->setEvaluator($user)->setMark(5)->setDateRegister(DbQueryHelper::timestamp2date());
     $mark->save();
     $props = $refUser->getPropeties();
     $props->setKarma($props->getKarma() + 5);
     if ($refUserOnline) {
         $refUserOnline->save();
         $response = (new MessageResponse())->setGuests($users->getUsersByChatId($refUserOnline->getChannelId()))->setChannelId($refUserOnline->getChannelId())->setTime(null);
         $users->setResponse($response)->notify();
         $response = (new MessageResponse())->setMsg(MsgToken::create('profile.referralKarma'))->setChannelId($refUserOnline->getChannelId())->setTime(null);
         (new UserCollection())->attach($refUserOnline)->setResponse($response)->notify(false);
     } else {
         $props->save(false);
     }
     DI::get()->getLogger()->info('Added karma to referral userId ' . $props->getUserId());
 }
 public function setUserProps(User $user)
 {
     $properties = $user->getProperties();
     $dir = DI::get()->getConfig()->uploads->avatars->wwwfolder . DIRECTORY_SEPARATOR;
     $this->setId($user->getId())->setEmail($user->getUserDAO()->getEmail())->setSex($properties->getSex()->getId())->setTim($properties->getTim()->getId())->setName($properties->getName())->setAbout($properties->getAbout())->setAvatarImg($properties->getAvatarImg() ? $dir . $properties->getAvatarImg() : null)->setAvatarThumb($properties->getAvatarThumb() ? $dir . $properties->getAvatarThumb() : null)->setYear($properties->getBirthday())->setCity($properties->getCity())->setCensor($properties->hasCensor())->setNotifyVisual($properties->hasNotifyVisual())->setNotifySound($properties->hasNotifySound())->setLineBreakType($properties->getLineBreakType())->setOnlineNotifyLimit($properties->getOnlineNotificationLimit())->setSubscription($properties->hasSubscription())->setMsgAnimationType($properties->getMessageAnimationType());
     return $this;
 }
Beispiel #15
0
 public function setUser(User $user)
 {
     $this[self::NAME] = $user->getProperties()->getName();
     return $this;
 }
 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);
 }
 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);
 }
 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);
 }
 private function isCorrectUser(User $user)
 {
     return $user->getProperties()->getTim()->getId() != TimEnum::ANY && $user->getProperties()->getSex()->getId() != SexEnum::ANONYM;
 }
 private function handleNameChange(User $user, $request)
 {
     $name = $request[PropertiesDAO::NAME];
     $guestName = $user->getLang()->getPhrase('Guest');
     $nameChangeFreq = DI::get()->getConfig()->nameChangeFreq;
     $isNewbie = mb_strpos($name, $guestName) !== false;
     $changeLog = NameChangeDAO::create()->getLastByUser($user);
     $hasNameChanged = $name != $user->getProperties()->getName();
     if ($isNewbie) {
         $newname = str_replace($guestName, TimEnum::create($request[PropertiesDAO::TIM])->getShortName(), $name);
         $duplUser = PropertiesDAO::create()->getByUserName($newname);
         if (!($duplUser->getId() && $duplUser->getUserId() != $user->getId())) {
             $name = $newname;
         }
     } elseif ($changeLog && $hasNameChanged && !$this->isExpired($changeLog, $nameChangeFreq)) {
         RespondError::make($user, $user->getLang()->getPhrase('NameChangePolicy', date('Y-m-d H:i', $changeLog->getDate() + $nameChangeFreq)));
         return;
     }
     if ($changeLog = NameChangeDAO::create()->getLastByName($name)) {
         if ($changeLog->getUserId() != $user->getId()) {
             if (!$this->isExpired($changeLog, $nameChangeFreq)) {
                 RespondError::make($user, $user->getLang()->getPhrase('NameTakePolicy', date('Y-m-d H:i', $changeLog->getDate() + $nameChangeFreq)));
                 return;
             }
         }
     }
     if ($hasNameChanged && !$isNewbie) {
         NameChangeDAO::create()->setUser($user)->save();
     }
 }
 /**
  * @param Lang $lang
  * @param Logger $logger
  * @param User $newUserWrapper
  * @param Request $socketRequest
  * @return UserDAO
  */
 private function createNewUser(Lang $lang, Logger $logger, User $newUserWrapper, Request $socketRequest)
 {
     $user = UserDAO::create()->setChatId(1)->setDateRegister(DbQueryHelper::timestamp2date())->setRole(UserRoleEnum::USER)->setBanned(false)->setImprint(null);
     try {
         $user->save();
     } catch (\PDOException $e) {
         $logger->error("PDO Exception: " . $e->getMessage() . ': ' . $e->getTraceAsString(), [__METHOD__]);
     }
     $id = $user->getId();
     $guestName = $lang->getPhrase('Guest') . $id;
     if (PropertiesDAO::create()->getByUserName($guestName)->getName()) {
         $guestName = $lang->getPhrase('Guest') . ' ' . $id;
     }
     $properties = $user->getPropeties();
     $properties->setUserId($user->getId())->setName($guestName)->setSex(SexEnum::create(SexEnum::ANONYM))->setTim(TimEnum::create(TimEnum::ANY))->setBirthday(Rules::LOWEST_YEAR)->setOptions([PropertiesDAO::CENSOR => true])->setOnlineCount(0)->setMusicCount(0)->setWordsCount(0)->setRudeCount(0)->setKarma(0)->setMessagesCount(0)->setSubscription(true);
     try {
         $properties->save();
     } catch (\PDOException $e) {
         $logger->error("PDO Exception: " . $e->getTraceAsString(), [__CLASS__]);
     }
     if ($refUserId = $socketRequest->getCookie('refUserId')) {
         $ref = ReferralDAO::create()->getByUserId($user->getId(), $refUserId);
         if (!$ref) {
             $ref = ReferralDAO::create()->setUserId($user->getId())->setRefUserId($refUserId)->setDateRegister(DbQueryHelper::timestamp2date());
             $ref->save();
             $logger->info('Found referral userId ' . $refUserId . ' for guest userId ' . $user->getId());
         }
     }
     $logger->info("Created new user with id = {$id} for connectionId = {$newUserWrapper->getConnectionId()}", [__CLASS__]);
     return $user;
 }
 /**
  * @param User $user
  * @return $this
  */
 public function getLastByUser(User $user)
 {
     $list = $this->getListByQuery("SELECT * FROM {$this->dbTable} WHERE " . self::USER_ID . " = :user_id ORDER BY " . self::DATE_CHANGE . " DESC LIMIT 1", ['user_id' => $user->getId()]);
     return !empty($list) ? $list[0] : null;
 }
 private function traitGuestInfo(Response $response, User $user)
 {
     if ($guests = $response->getGuests()) {
         foreach ($guests as &$guest) {
             if ($user->getBlacklist()->isBanned($guest[PropertiesDAO::USER_ID])) {
                 $guest += ['banned' => $user->getId()];
             }
             if ($note = $user->getUserNotes()->getNote($guest[PropertiesDAO::USER_ID])) {
                 $guest += ['note' => $note];
             }
         }
         $response->setGuestsRaw($guests);
     }
 }
 protected function getToken(User $userInviter, User $desiredUser)
 {
     return $userInviter->getId() < $desiredUser->getId() ? $userInviter->getId() . '.' . $desiredUser->getId() : $desiredUser->getId() . '.' . $userInviter->getId();
 }
Beispiel #25
0
 public function isAllowed(User $user)
 {
     return $user->getRole()->isAdmin();
 }
Beispiel #26
0
 public function setFrom(User $user)
 {
     $this->from = $user;
     $this->fromName = $user->getProperties()->getName();
     return $this;
 }
 public function setEvaluator(User $user)
 {
     $this[self::EVALUATOR_ID] = $user->getId();
     return $this;
 }
 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);
 }
Beispiel #29
0
    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);
    }
 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();
 }