mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-29 01:54:33 +00:00
8657ef5e90
Add a 'mark as unread' to all unread notifications and allow them to be marked unread. These notifications will no longer be automatically marked as read when the pages they refer to are visited. Bug: T73564 Change-Id: I677d3c0399e46fd7c35531df1cc0e61db2d4eb1b
103 lines
2.3 KiB
JavaScript
103 lines
2.3 KiB
JavaScript
( function ( mw ) {
|
|
/**
|
|
* Notification API handler
|
|
*
|
|
* @class
|
|
* @extends mw.echo.dm.APIHandler
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Configuration object
|
|
*/
|
|
mw.echo.api.LocalAPIHandler = function MwEchoApiLocalAPIHandler( config ) {
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
mw.echo.api.LocalAPIHandler.parent.call( this, config );
|
|
|
|
this.api = new mw.Api( { ajax: { cache: false } } );
|
|
};
|
|
|
|
/* Setup */
|
|
|
|
OO.inheritClass( mw.echo.api.LocalAPIHandler, mw.echo.api.APIHandler );
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.fetchNotifications = function ( type, isForced ) {
|
|
if ( isForced || this.isFetchingErrorState( type ) ) {
|
|
// Force new promise
|
|
this.createNewFetchNotificationPromise( type );
|
|
}
|
|
|
|
return this.getFetchNotificationPromise( type );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.updateSeenTime = function ( type ) {
|
|
return this.api.postWithToken( 'edit', {
|
|
action: 'echomarkseen',
|
|
type: this.normalizedType[ type ]
|
|
} )
|
|
.then( function ( data ) {
|
|
return data.query.echomarkseen.timestamp;
|
|
} );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.markAllRead = function ( type ) {
|
|
var data = {
|
|
action: 'echomarkread',
|
|
sections: this.normalizedType[ type ]
|
|
};
|
|
|
|
return this.api.postWithToken( 'edit', data )
|
|
.then( function ( result ) {
|
|
return OO.getProp( result.query, 'echomarkread', type, 'rawcount' ) || 0;
|
|
} );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.markItemsRead = function ( itemIdArray, isRead ) {
|
|
var data = {
|
|
action: 'echomarkread'
|
|
};
|
|
|
|
if ( isRead ) {
|
|
data.list = itemIdArray.join( '|' );
|
|
} else {
|
|
data.unreadlist = itemIdArray.join( '|' );
|
|
}
|
|
|
|
return this.api.postWithToken( 'edit', data );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.fetchUnreadCount = function ( type ) {
|
|
var normalizedType = this.normalizedType[ type ],
|
|
apiData = {
|
|
action: 'query',
|
|
meta: 'notifications',
|
|
notsections: normalizedType,
|
|
notgroupbysection: 1,
|
|
notmessageunreadfirst: 1,
|
|
notlimit: this.limit,
|
|
notprop: 'count',
|
|
uselang: this.userLang
|
|
};
|
|
|
|
return this.api.get( apiData )
|
|
.then( function ( result ) {
|
|
return OO.getProp( result.query, 'notifications', normalizedType, 'rawcount' ) || 0;
|
|
} );
|
|
};
|
|
} )( mediaWiki );
|