protected function sync(Post $reply, array $mentioned)
 {
     $reply->mentionsPosts()->sync($mentioned);
     $posts = Post::with('user')->whereIn('id', $mentioned)->get()->filter(function ($post) use($reply) {
         return $post->user->id !== $reply->user->id;
     })->all();
     foreach ($posts as $post) {
         $this->notifications->sync(new PostMentionedBlueprint($post, $reply), [$post->user]);
     }
 }
示例#2
0
 /**
  * Find posts by their IDs, optionally making sure they are visible to a
  * certain user.
  *
  * @param array $ids
  * @param \Flarum\Core\Users\User|null $actor
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function findByIds(array $ids, User $actor = null)
 {
     $visibleIds = $this->filterDiscussionVisibleTo($ids, $actor);
     $posts = Post::with('discussion')->whereIn('id', $visibleIds)->get();
     $posts = $posts->sort(function ($a, $b) use($ids) {
         $aPos = array_search($a->id, $ids);
         $bPos = array_search($b->id, $ids);
         if ($aPos === $bPos) {
             return 0;
         }
         return $aPos < $bPos ? -1 : 1;
     });
     return $this->filterVisibleTo($posts, $actor);
 }