public function testRemoveUser() { $chat = new ChatRoom(); $user = new User(1); $chat->addUser($user); $chat->addUser(new User(2)); $chat->addUser(new User(3)); $chat->removeUser($user); $this->assertEquals(2, sizeof($chat->getUsers()), 'Chat should contain 2 users'); $this->assertNotContains($user, $chat->getUsers(), 'User should be removed from chat'); }
/** * 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); }
/** * 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()); } }
/** * Set chat room for user * * @access public * @param \jones\wschat\components\ChatRoom $chat * @return void */ public function setChat(ChatRoom $chat) { $this->chat = $chat; $this->chat->addUser($this); }