Merge "Mark notifications as read if they fail rendering"

This commit is contained in:
jenkins-bot 2014-09-08 21:27:26 +00:00 committed by Gerrit Code Review
commit 91d102131e
3 changed files with 72 additions and 5 deletions

View file

@ -109,6 +109,9 @@ $wgJobClasses['EchoNotificationJob'] = 'EchoNotificationJob';
$wgAutoloadClasses['MWEchoNotificationEmailBundleJob'] = $dir . 'jobs/NotificationEmailBundleJob.php'; $wgAutoloadClasses['MWEchoNotificationEmailBundleJob'] = $dir . 'jobs/NotificationEmailBundleJob.php';
$wgJobClasses['MWEchoNotificationEmailBundleJob'] = 'MWEchoNotificationEmailBundleJob'; $wgJobClasses['MWEchoNotificationEmailBundleJob'] = 'MWEchoNotificationEmailBundleJob';
// Deferred execution
$wgAutoloadClasses['EchoDeferredMarkAsReadUpdate'] = $dir . '/includes/DeferredMarkAsReadUpdate.php';
// API // API
$wgAutoloadClasses['ApiEchoNotifications'] = $dir . 'api/ApiEchoNotifications.php'; $wgAutoloadClasses['ApiEchoNotifications'] = $dir . 'api/ApiEchoNotifications.php';
$wgAPIMetaModules['notifications'] = 'ApiEchoNotifications'; $wgAPIMetaModules['notifications'] = 'ApiEchoNotifications';

View file

@ -18,6 +18,13 @@ class EchoNotificationController {
*/ */
static protected $userWhitelist; static protected $userWhitelist;
/**
* Queue's that failed formatting and marks them as read at end of request.
*
* @var DeferredMarkAsReadUpdate|null
*/
static protected $markAsRead;
/** /**
* Format the notification count with Language::formatNum(). In addition, for large count, * Format the notification count with Language::formatNum(). In addition, for large count,
* return abbreviated version, e.g. 99+ * return abbreviated version, e.g. 99+
@ -330,12 +337,30 @@ class EchoNotificationController {
restore_error_handler(); restore_error_handler();
} }
if ( $res ) { if ( $res === '' ) {
return $res; self::failFormatting( $event, $user );
} else {
return Xml::tags( 'span', array( 'class' => 'error' ),
wfMessage( 'echo-error-no-formatter', $event->getType() )->escaped() );
} }
return $res;
}
/**
* Event has failed to format for the given user. Mark it as read so
* we do not continue to notify them about this broken event.
*
* @param EchoEvent $event
* @param User $user
*/
protected static function failFormatting( EchoEvent $event, $user ) {
// FIXME: The only issue is that the badge count won't be up to date
// till you refresh the page. Probably we could do this in the browser
// so that if the formatting is empty and the notif is unread, put it
// in the auto-mark-read API
if ( self::$markAsRead === null ) {
self::$markAsRead = new EchoDeferredMarkAsReadUpdate();
DeferredUpdates::addUpdate( self::$markAsRead );
}
self::$markAsRead->add( $event, $user );
} }
/** /**

View file

@ -0,0 +1,39 @@
<?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();
}
}