public function __construct(array $data, ChatRoom $room) { parent::__construct($data, $room->getIdentifier()->getHost()); $this->room = $room; $this->userId = $data['user_id']; $this->userName = $data['user_name']; }
public function __construct(array $data, ChatRoom $room) { parent::__construct($data, $room->getIdentifier()->getHost()); $this->userId = (int) $data['user_id']; $this->userName = (string) $data['user_name']; $this->roomId = (int) $data['room_id']; $this->roomName = (string) $data['room_name']; }
public function __construct(array $data, ChatRoom $room) { parent::__construct($data, $room->getIdentifier()->getHost()); $this->room = $room; $this->messageId = $data['message_id']; $this->content = $data['content']; $this->numberOfStars = $data['message_stars'] ?? 0; $this->pinned = isset($data['message_owner_stars']); }
public function __construct(array $data, ChatRoom $room) { parent::__construct($data, $room->getIdentifier()->getHost()); $this->room = $room; $this->userId = (int) $data['user_id']; $this->userName = (string) $data['user_name']; $this->messageId = (int) $data['message_id']; $this->messageContent = domdocument_load_html((string) ($data['content'] ?? ''), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $this->parentId = (int) ($data['parent_id'] ?? -1); $this->showParent = (bool) ($data['show_parent'] ?? false); }
private function leaveRoom(Room $room) : Promise { assert(!$room->isPermanent(), new InvalidRoomException('Cannot leave a permanent room')); $this->storage->setApproved($room->getIdentifier(), false); $this->removeScheduledActionsForUnapprovedRoom($room->getIdentifier()); $body = (new FormBody())->addField('fkey', $room->getSession()->getFKey())->addField('quiet', 'true'); $request = (new HttpRequest())->setMethod('POST')->setUri($this->urlResolver->getEndpointURL($room, Endpoint::CHATROOM_LEAVE))->setBody($body); $this->storage->removeRoom($room->getIdentifier()); $room->getWebsocketHandler()->getEndpoint()->close(); return $this->httpClient->request($request); }
public function postMessage(ChatRoom $room, string $text, int $flags = PostFlags::NONE) : Promise { return resolve(function () use($room, $text, $flags) { // the order of these two conditions is very important! MUST short circuit on $flags or new rooms will block on the welcome message! if (!($flags & PostFlags::FORCE) && !(yield $room->isApproved())) { throw new RoomNotApprovedException('Bot is not approved for message posting in this room'); } $text = $this->applyPostFlagsToText($text, $flags); $body = (new FormBody())->addField("text", $text)->addField("fkey", (string) $room->getSession()->getFKey()); $url = $this->urlResolver->getEndpointURL($room, ChatRoomEndpoint::CHATROOM_POST_MESSAGE); $request = (new HttpRequest())->setUri($url)->setMethod("POST")->setBody($body); $action = $this->actionFactory->createPostMessageAction($request, $room, $text); $this->actionExecutor->enqueue($action); return $action->promise(); }); }
public function __construct(array $data, ChatRoom $room) { parent::__construct($data, $room->getIdentifier()->getHost()); }
private function getClientForRoom(ChatRoom $room) { if (isset($this->clients[$room->getIdentifier()->getIdentString()])) { return $this->clients[$room->getIdentifier()->getIdentString()]; } $keys = ['oauth.access_token', 'oauth.access_token_secret']; $config = []; foreach ($keys as $key) { if (!(yield $this->keyValueStore->exists($key, $room))) { throw new NotConfiguredException('Missing config key: ' . $key); } $config[$key] = (yield $this->keyValueStore->get($key, $room)); } $accessToken = $this->accessTokenFactory->create($config['oauth.access_token'], $config['oauth.access_token_secret']); $this->clients[$room->getIdentifier()->getIdentString()] = $this->apiClientFactory->create($accessToken); return $this->clients[$room->getIdentifier()->getIdentString()]; }