mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-12 09:26:05 +00:00
97417af20c
The only issue is that the badge is not up to date till you refresh the page, I think that's fine for now Change-Id: I585b4cc185bf859ddb06829df75309ff3d56d8b8
40 lines
927 B
PHP
40 lines
927 B
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 function add( 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();
|
|
}
|
|
}
|