protected function sync(Post $post, array $mentioned) { $post->mentionsUsers()->sync($mentioned); $users = User::whereIn('id', $mentioned)->get()->filter(function ($user) use($post) { return $user->id !== $post->user->id; })->all(); $this->notifications->sync(new UserMentionedBlueprint($post), $users); }
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]); } }
/** * Register post types. * * @return void */ public function registerPostTypes() { $models = ['Flarum\\Core\\Posts\\CommentPost', 'Flarum\\Core\\Posts\\DiscussionRenamedPost']; event(new RegisterPostTypes($models)); foreach ($models as $model) { Post::setModel($model::$type, $model); } }
/** * {@inheritdoc} */ public function match($string) { $discussionIds = Post::where('type', 'comment')->where('content', 'like', "%{$string}%")->lists('discussion_id', 'id'); $relevantPostIds = []; foreach ($discussionIds as $postId => $discussionId) { $relevantPostIds[$discussionId][] = $postId; } return $relevantPostIds; }
public function saveAfter(Post $previous) { // If the previous post is another 'discussion locked' post, and it's // by the same user, then we can merge this post into it. If we find // that we've in fact reverted the locked status, delete it. Otherwise, // update its content. if ($previous instanceof static && $this->user_id === $previous->user_id) { if ($previous->content['locked'] != $this->content['locked']) { $previous->delete(); } else { $previous->content = $this->content; $previous->save(); } return $previous; } $this->save(); return $this; }
/** * {@inheritdoc} */ public function match($string) { $discussionIds = Post::where('type', 'comment')->whereRaw('MATCH (`content`) AGAINST (? IN BOOLEAN MODE)', [$string])->orderByRaw('MATCH (`content`) AGAINST (?) DESC', [$string])->lists('discussion_id', 'id'); $relevantPostIds = []; foreach ($discussionIds as $postId => $discussionId) { $relevantPostIds[$discussionId][] = $postId; } return $relevantPostIds; }
public function saveAfter(Post $previous) { // If the previous post is another 'discussion tagged' post, and it's // by the same user, then we can merge this post into it. If we find // that we've in fact reverted the tag changes, delete it. Otherwise, // update its content. if ($previous instanceof static && $this->user_id === $previous->user_id) { if ($previous->content[0] == $this->content[1]) { $previous->delete(); } else { $previous->content = static::buildContent($previous->content[0], $this->content[1]); $previous->time = $this->time; $previous->save(); } return $previous; } $this->save(); return $this; }
/** * 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); }