Emit sortChange only for read/unread actions

Do not emit sortChange for toggleSeen, because every sortChange
creates a fake widget with a flipped 'read' state. There is no
reason to emit the sortChange event in toggleSeen anyways so it
is safer when only emitted in togglRead.

Also, make sure the controller always updates the correct seenTime
from the API when fetching local notifications. This was done for
the special page method but was overlooked for the fetching of local
notifications. For the most part, it shouldn't be affecting too much
because the SeenTimeModel is initialized with wgEchoSeenTime (which
is local) but updating the controller with the API response is the
safe thing to do, and will also cover cases where a tab was open,
notifications were seen in a different tab, and now the popup was
reopened in a "stale" tab again.

Bug: T143067
Change-Id: Ie261e32db28926d04fe14f7badd9d287ddc52749
This commit is contained in:
Moriel Schottlender 2016-08-15 16:53:09 -07:00
parent 6eb2743dae
commit 951f146b54
3 changed files with 33 additions and 5 deletions

View file

@ -277,6 +277,17 @@
notifData = data.list[ i ];
content = notifData[ '*' ] || {};
// Set source's seenTime
controller.manager.getSeenTimeModel().setSeenTimeForSource(
'local',
controller.getTypes().length > 1 ?
(
data.seenTime.alert < data.seenTime.notice ?
data.seenTime.notice : data.seenTime.alert
) :
data.seenTime[ controller.getTypeString() ]
);
// Collect common data
newNotifData = controller.createNotificationData( notifData );
if ( notifData.type === 'foreign' ) {

View file

@ -74,16 +74,27 @@
};
/**
* Update item state when the item model changes.
* Extend 'toggleRead' to emit sortChange so the item can be sorted
* when its read state was updated
*
* @fires sortChange
*/
mw.echo.ui.SingleNotificationItemWidget.prototype.toggleRead = function ( read ) {
var oldState = this.read;
// Parent
mw.echo.ui.SingleNotificationItemWidget.parent.prototype.toggleRead.call( this, read );
if ( oldState !== read ) {
this.emit( 'sortChange' );
}
};
/**
* Update item state when the item model changes.
*/
mw.echo.ui.SingleNotificationItemWidget.prototype.updateDataFromModel = function () {
this.toggleRead( this.model.isRead() );
this.toggleSeen( this.model.isSeen() );
// Emit 'sortChange' so the SortedList can update this
// item's place in the list
this.emit( 'sortChange' );
};
} )( mediaWiki );

View file

@ -60,6 +60,12 @@
item.$element.clone( true ),
{
id: item.getId() + '.42',
// HACK: We are assuming that the item sort change
// is triggered when the item is marked read/unread
// This is a generally correct assumption, but it may
// cause issues when the case is unclear. We should try
// and come up with a good way to measure the previous
// state of the item instead
read: !item.isRead(),
foreign: item.isForeign(),
timestamp: item.getTimestamp()