/**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $actor = $request->getAttribute('actor');
     if (!$request->getAttribute('bypassFloodgate')) {
         $this->floodgate->assertNotFlooding($actor);
     }
     $discussion = $this->bus->dispatch(new StartDiscussion($actor, array_get($request->getParsedBody(), 'data', [])));
     // After creating the discussion, we assume that the user has seen all
     // of the posts in the discussion; thus, we will mark the discussion
     // as read if they are logged in.
     if ($actor->exists) {
         $this->bus->dispatch(new ReadDiscussion($discussion->id, $actor, 1));
     }
     return $discussion;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $actor = $request->getAttribute('actor');
     $data = array_get($request->getParsedBody(), 'data', []);
     $discussionId = array_get($data, 'relationships.discussion.data.id');
     $ipAddress = array_get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
     if (!$request->getAttribute('bypassFloodgate')) {
         $this->floodgate->assertNotFlooding($actor);
     }
     $post = $this->bus->dispatch(new PostReply($discussionId, $actor, $data, $ipAddress));
     // After replying, we assume that the user has seen all of the posts
     // in the discussion; thus, we will mark the discussion as read if
     // they are logged in.
     if ($actor->exists) {
         $this->bus->dispatch(new ReadDiscussion($discussionId, $actor, $post->number));
     }
     $discussion = $post->discussion;
     $discussion->posts = $discussion->postsVisibleTo($actor)->orderBy('time')->lists('id');
     return $post;
 }