mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-12 09:26:05 +00:00
ba957d399a
Adds EchoEventPresentationModel::canRender() for notification types to indicate that something can't be rendered if for example, a page is deleted. In that case, the notification is marked as read in a deferred update. All callers were also updated to check if the notification was formatted properly. Bug: T116888 Change-Id: Idb975feaec893ef86c41cc487102e3539c07e328
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Mark event notifications as read at the end of a request. Used to queue up
|
|
* individual events to mark due to formatting failures or other uses.
|
|
*/
|
|
class EchoDeferredMarkAsReadUpdate implements DeferrableUpdate {
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $events = array();
|
|
|
|
/**
|
|
* @param EchoEvent $event
|
|
* @param User $user
|
|
*/
|
|
public static function add( EchoEvent $event, User $user ) {
|
|
static $update;
|
|
if ( $update === null ) {
|
|
$update = new self();
|
|
DeferredUpdates::addUpdate( $update );
|
|
}
|
|
$update->addInternal( $event, $user );
|
|
}
|
|
|
|
/**
|
|
* @param EchoEvent $event
|
|
* @param User $user
|
|
*/
|
|
private function addInternal( EchoEvent $event, User $user ) {
|
|
$uid = $user->getId();
|
|
if ( isset( $this->events[$uid] ) ) {
|
|
$this->events[$uid]['eventIds'][] = $event->getId();
|
|
} else {
|
|
$this->events[$uid] = array(
|
|
'user' => $user,
|
|
'eventIds' => array( $event->getId() ),
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Mark's all queue'd notifications as read.
|
|
* Satisfies DeferrableUpdate interface
|
|
*/
|
|
public function doUpdate() {
|
|
foreach ( $this->events as $data ) {
|
|
MWEchoNotifUser::newFromUser( $data['user'] )->markRead( $data['eventIds'] );
|
|
}
|
|
$this->events = array();
|
|
}
|
|
}
|