A notification record is associated with a user, and shows up in their notification list. A notification indicates that something has happened that the user should know about, like if a user's discussion was renamed by someone else. Each notification record has a *type*. The type determines how the record looks in the notifications list, and what *subject* is associated with it. For example, the 'discussionRenamed' notification type represents that someone renamed a user's discussion. Its subject is a discussion, of which the ID is stored in the subject_id column.
Inheritance: extends Flarum\Database\AbstractModel
Ejemplo n.º 1
0
 /**
  * @param ReadNotification $command
  * @return \Flarum\Core\Notification
  * @throws \Flarum\Core\Exception\PermissionDeniedException
  */
 public function handle(ReadNotification $command)
 {
     $actor = $command->actor;
     $this->assertRegistered($actor);
     $notification = Notification::where('user_id', $actor->id)->findOrFail($command->notificationId);
     Notification::where(['user_id' => $actor->id, 'type' => $notification->type, 'subject_id' => $notification->subject_id])->update(['is_read' => true]);
     $notification->is_read = true;
     return $notification;
 }
Ejemplo n.º 2
0
 /**
  * Register notification types.
  */
 public function registerNotificationTypes()
 {
     $blueprints = ['Flarum\\Core\\Notification\\DiscussionRenamedBlueprint' => ['alert']];
     $this->app->make('events')->fire(new ConfigureNotificationTypes($blueprints));
     foreach ($blueprints as $blueprint => $enabled) {
         Notification::setSubjectModel($type = $blueprint::getType(), $blueprint::getSubjectModel());
         User::addPreference(User::getNotificationPreferenceKey($type, 'alert'), 'boolval', in_array('alert', $enabled));
         if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\\Core\\Notification\\MailableInterface')) {
             User::addPreference(User::getNotificationPreferenceKey($type, 'email'), 'boolval', in_array('email', $enabled));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Get the notification types that should be alerted to this user, according
  * to their preferences.
  *
  * @return array
  */
 public function getAlertableNotificationTypes()
 {
     $types = array_keys(Notification::getSubjectModels());
     return array_filter($types, [$this, 'shouldAlert']);
 }
Ejemplo n.º 4
0
 /**
  * Set the deleted status of a list of notification records.
  *
  * @param int[] $ids
  * @param bool $isDeleted
  */
 protected function setDeleted(array $ids, $isDeleted)
 {
     Notification::whereIn('id', $ids)->update(['is_deleted' => $isDeleted]);
 }
Ejemplo n.º 5
0
 /**
  * Mark all of a user's notifications as read.
  *
  * @param User $user
  *
  * @return void
  */
 public function markAllAsRead(User $user)
 {
     Notification::where('user_id', $user->id)->update(['is_read' => true]);
 }