mirror of
https://github.com/flarum/core.git
synced 2025-10-19 18:56:44 +02:00
It turns out that the idea of “sending” a notification is flawed. (What happens if the notification subject is deleted shortly after? The notified user would end up with a dud notification which would be confusing. What about if a post is edited to mention an extra user? If you sent out notifications, the users who’ve already been mentioned would get a duplicate notification.) Instead, I’ve introduced the idea of notification “syncing”. Whenever a change is made to a piece of data (e.g. a post is created, edited, or deleted), you make a common notification and “sync” it to a set of users. The users who’ve received this notification before won’t get it again. It will be sent out to new users, and hidden from users who’ve received it before but are no longer recipients (e.g. users who’ve been “unmentioned” in a post). To keep track of this, we use the existing notifications database table, with an added `is_deleted` column. The syncing/diffing is handled all behind the scenes; the API is extremely simple (see Core\Notifications\DiscussionRenamedNotification + Core\Events\Handlers\DiscussionRenamedNotifier)
55 lines
1006 B
PHP
55 lines
1006 B
PHP
<?php namespace Flarum\Core\Notifications;
|
|
|
|
abstract class NotificationAbstract implements NotificationInterface
|
|
{
|
|
/**
|
|
* Get the user that sent the notification.
|
|
*
|
|
* @return \Flarum\Core\Models\User|null
|
|
*/
|
|
public function getSender()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get the data to be stored in the notification.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getData()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get the name of the view to construct a notification email with.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getEmailView()
|
|
{
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Get the subject line for a notification email.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getEmailSubject()
|
|
{
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Whether or not the notification is able to be sent as an email.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public static function isEmailable()
|
|
{
|
|
return false;
|
|
}
|
|
}
|