/** * Handles the command execution. * * @param UploadImage $command * @return null|string * * @todo check permission */ public function handle(PostChat $command) { // check if the user can upload images, otherwise return $this->assertCan($command->actor, 'pushedx.chat.post'); $msg = ['actorId' => $command->actor->id, 'message' => $command->msg]; $id = FetchChatController::UpdateMessages($msg); $msg['id'] = $id; $pusher = $this->getPusher(); $pusher->trigger('public', 'newChat', $msg); return $command->msg; }
/** * Get the data to be serialized and assigned to the response document. * * @param ServerRequestInterface $request * @param Document $document * @return mixed */ protected function data(ServerRequestInterface $request, Document $document) { $id = $request->getParsedBody()['id']; $msgs = FetchChatController::GetMessages(FetchChatController::GetDB(), $id); return $this->bus->dispatch(new FetchChat($msgs)); }