mediawiki-extensions-Echo/modules/api/mw.echo.api.LocalAPIHandler.js
Moriel Schottlender 8657ef5e90 Allow mark-as-unread in notifications
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
2016-03-11 14:05:10 -08:00

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 );