示例#1
0
 /**
  * Add the given comment to the content.
  *
  * @param string                          $text
  * @param \Fahita\RealTime\Content                 $content
  * @param \Fahita\Contracts\UserInterface $user
  *
  * @return array|null
  */
 public function add($text, Content $content, UserInterface $user)
 {
     if ($this->validator->validateAdding(compact('text'))) {
         // store the comment in the database
         $comment = $this->comments->create($text, $content->type(), $content->id(), $user);
         // cache the created comment
         return $this->cache->add($comment, $content);
     }
 }
示例#2
0
 /**
  * Add a comment.
  *
  * @param array     $args
  * @param \Vinelab\Minion\Dictionary $data
  *
  * @return array
  */
 public function add($args, Dictionary $data)
 {
     if (TokenAuth::loginWithToken($data->access_token)) {
         $content = Content::make($data);
         $comment = $this->comments->add($data->comment, $content, TokenAuth::user());
         $response = (array) Api::content(['CommentMapper', 'mapNewInstance'], $comment);
         $this->publish($this->getContentActionKey($content->id(), 'add'), [], $response['data']);
         $this->publishToModeration('add', $response['data']);
         return $response;
     }
     throw new UnAuthorizedException();
 }