Ejemplo n.º 1
0
 /**
  * Bans an user by message ID.
  *
  * @param integer $messageId
  * @param WiseChatChannel $channel
  * @param string $durationString
  *
  * @throws Exception If the message or user was not found
  */
 public function banByMessageId($messageId, $channel, $durationString = '1d')
 {
     $message = $this->messagesDAO->get($messageId);
     if ($message === null) {
         throw new Exception('Message was not found');
     }
     $channelUser = $this->channelUsersDAO->getByUserIdAndChannelId($message->getUserId(), $channel->getId());
     if ($channelUser !== null) {
         $user = $this->usersDAO->get($message->getUserId());
         if ($user !== null) {
             $duration = $this->getDurationFromString($durationString);
             $this->banIpAddress($user->getIp(), $duration);
             return;
         }
     }
     throw new Exception('User was not found in this channel');
 }
Ejemplo n.º 2
0
 /**
  * Marks presence of the current user in the given channel.
  *
  * @param WiseChatChannel $channel
  *
  * @return null
  */
 private function markPresenceInChannel($channel)
 {
     $user = $this->authentication->getUser();
     if ($user !== null) {
         $channelUser = $this->channelUsersDAO->getByUserIdAndChannelId($user->getId(), $channel->getId());
         if ($channelUser === null) {
             $channelUser = new WiseChatChannelUser();
             $channelUser->setActive(true);
             $channelUser->setLastActivityTime(time());
             $channelUser->setUserId($user->getId());
             $channelUser->setChannelId($channel->getId());
             $this->channelUsersDAO->save($channelUser);
         } else {
             $channelUser->setActive(true);
             $channelUser->setLastActivityTime(time());
             $this->channelUsersDAO->save($channelUser);
         }
     }
 }