示例#1
0
 public function testUserChat()
 {
     $user = new User($this->id);
     $user->setChat(new ChatRoom());
     $chat = $user->getChat();
     $this->assertInstanceOf('jones\\wschat\\components\\ChatRoom', $chat, 'Chat should be instance of jones\\wschat\\components\\ChatRoom');
     $users = $chat->getUsers();
     $this->assertEquals(1, sizeof($users), 'Chat should contain only one user');
     $this->assertTrue(isset($users[$this->id]), 'User should be in chat');
     $this->assertInstanceOf('jones\\wschat\\components\\User', $users[$this->id], 'Chat user should be instance of jones\\wschat\\components\\User');
 }
示例#2
0
 /**
  * Store chat message
  *
  * @access public
  * @param \jones\wschat\components\User $user
  * @param \jones\wschat\components\ChatRoom $chat
  * @param string $message
  */
 public function storeMessage(User $user, ChatRoom $chat, $message)
 {
     $params = ['chat_id' => $chat->getUid(), 'chat_title' => $chat->title, 'user_id' => $user->getId(), 'username' => $user->username, 'avatar_16' => $user->avatar_16, 'avatar_32' => $user->avatar_32, 'message' => $message['message'], 'timestamp' => $message['timestamp']];
     AbstractStorage::factory()->storeMessage($params);
 }
示例#3
0
 /**
  * Store chat message
  *
  * @access public
  * @param \jones\wschat\components\User $user
  * @param \jones\wschat\components\ChatRoom $chat
  * @param string $message
  */
 public function storeMessage(User $user, ChatRoom $chat, $message)
 {
     try {
         /** @var \yii\mongodb\Collection $collection */
         $collection = Yii::$app->mongodb->getCollection(History::collectionName());
         $collection->insert(['chat_id' => $chat->getUid(), 'chat_title' => $chat->title, 'user_id' => $user->getId(), 'username' => $user->username, 'avatar_16' => $user->avatar_16, 'avatar_32' => $user->avatar_32, 'message' => $message['message'], 'timestamp' => $message['timestamp']]);
     } catch (Exception $e) {
         Yii::error($e->getMessage());
     }
 }