sync() public method

Sync a notification so that it is visible to the specified users, and not visible to anyone else. If it is being made visible for the first time, attempt to send the user an email.
public sync ( Flarum\Core\Notification\BlueprintInterface $blueprint, array $users ) : void
$blueprint Flarum\Core\Notification\BlueprintInterface
$users array
return void
コード例 #1
0
 /**
  * @param PostWasPosted $event
  */
 public function whenPostWasPosted(PostWasPosted $event)
 {
     $post = $event->post;
     $discussion = $post->discussion;
     $notify = $discussion->readers()->where('users.id', '!=', $post->user_id)->where('users_discussions.subscription', 'follow')->where('users_discussions.read_number', $discussion->last_post_number)->get();
     $this->notifications->sync($this->getNotification($event->post), $notify->all());
 }
コード例 #2
0
 /**
  * @param Discussion $discussion
  * @param User $user
  * @param $isLocked
  */
 protected function lockedChanged(Discussion $discussion, User $user, $isLocked)
 {
     $post = DiscussionLockedPost::reply($discussion->id, $user->id, $isLocked);
     $post = $discussion->mergePost($post);
     if ($discussion->start_user_id !== $user->id) {
         $notification = new DiscussionLockedBlueprint($post);
         $this->notifications->sync($notification, $post->exists ? [$discussion->startUser] : []);
     }
 }
コード例 #3
0
 /**
  * @param \Flarum\Event\DiscussionWasRenamed $event
  */
 public function whenDiscussionWasRenamed(DiscussionWasRenamed $event)
 {
     $post = DiscussionRenamedPost::reply($event->discussion->id, $event->actor->id, $event->oldTitle, $event->discussion->title);
     $post = $event->discussion->mergePost($post);
     if ($event->discussion->start_user_id !== $event->actor->id) {
         $blueprint = new DiscussionRenamedBlueprint($post);
         if ($post->exists) {
             $this->notifications->sync($blueprint, [$event->discussion->startUser]);
         } else {
             $this->notifications->delete($blueprint);
         }
     }
 }
コード例 #4
0
 /**
  * @param Post $post
  * @param array $mentioned
  */
 protected function sync(Post $post, array $mentioned)
 {
     $post->mentionsUsers()->sync($mentioned);
     $users = User::whereIn('id', $mentioned)->get()->filter(function ($user) use($post) {
         return $post->isVisibleTo($user) && $user->id !== $post->user->id;
     })->all();
     $this->notifications->sync(new UserMentionedBlueprint($post), $users);
 }
コード例 #5
0
 /**
  * @param Post $reply
  * @param array $mentioned
  */
 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 && $post->user->id !== $reply->user_id;
     })->all();
     foreach ($posts as $post) {
         $this->notifications->sync(new PostMentionedBlueprint($post, $reply), [$post->user]);
     }
 }
コード例 #6
0
 /**
  * @param Post $post
  * @param User $user
  * @param array $recipients
  */
 public function sync(Post $post, User $user, array $recipients)
 {
     if ($post->user->id != $user->id) {
         $this->notifications->sync(new PostLikedBlueprint($post, $user), $recipients);
     }
 }