2016-04-21 10:28:32 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-01-15 22:11:33 +00:00
|
|
|
/**
|
|
|
|
* Notification API handler
|
|
|
|
*
|
|
|
|
* @class
|
2016-05-11 20:33:17 +00:00
|
|
|
* @extends mw.echo.api.APIHandler
|
2016-01-15 22:11:33 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration object
|
|
|
|
*/
|
|
|
|
mw.echo.api.LocalAPIHandler = function MwEchoApiLocalAPIHandler( config ) {
|
|
|
|
// Parent constructor
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.api.LocalAPIHandler.super.call( this,
|
2016-05-06 13:02:33 +00:00
|
|
|
new mw.Api( { ajax: { cache: false } } ),
|
|
|
|
config
|
|
|
|
);
|
2016-01-15 22:11:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.api.LocalAPIHandler, mw.echo.api.APIHandler );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2016-05-19 20:49:09 +00:00
|
|
|
mw.echo.api.LocalAPIHandler.prototype.fetchNotifications = function ( type, source, isForced, overrideParams ) {
|
|
|
|
if ( overrideParams ) {
|
|
|
|
return this.createNewFetchNotificationPromise( type, source, overrideParams );
|
2016-05-31 22:32:16 +00:00
|
|
|
} else if ( isForced || this.isFetchingErrorState( type, source ) ) {
|
2016-01-15 22:11:33 +00:00
|
|
|
// Force new promise
|
2016-05-31 22:32:16 +00:00
|
|
|
return this.createNewFetchNotificationPromise( type, source, overrideParams );
|
2016-01-15 22:11:33 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 20:49:09 +00:00
|
|
|
return this.getFetchNotificationPromise( type, source, overrideParams );
|
2016-01-15 22:11:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
mw.echo.api.LocalAPIHandler.prototype.updateSeenTime = function ( type ) {
|
2016-07-08 22:56:01 +00:00
|
|
|
type = Array.isArray( type ) ? type : [ type ];
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
return this.api.postWithToken( 'csrf', {
|
2016-01-15 22:11:33 +00:00
|
|
|
action: 'echomarkseen',
|
2016-07-22 18:59:10 +00:00
|
|
|
type: type.length === 1 ? type[ 0 ] : 'all',
|
|
|
|
timestampFormat: 'ISO_8601'
|
2016-01-15 22:11:33 +00:00
|
|
|
} )
|
|
|
|
.then( function ( data ) {
|
|
|
|
return data.query.echomarkseen.timestamp;
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
mw.echo.api.LocalAPIHandler.prototype.markAllRead = function ( type ) {
|
2016-06-29 23:36:03 +00:00
|
|
|
type = Array.isArray( type ) ? type : [ type ];
|
2016-01-15 22:11:33 +00:00
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
return this.api.postWithToken( 'csrf', {
|
|
|
|
action: 'echomarkread',
|
|
|
|
sections: type.join( '|' )
|
|
|
|
} )
|
2016-01-15 22:11:33 +00:00
|
|
|
.then( function ( result ) {
|
|
|
|
return OO.getProp( result.query, 'echomarkread', type, 'rawcount' ) || 0;
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2016-03-04 22:44:22 +00:00
|
|
|
mw.echo.api.LocalAPIHandler.prototype.markItemsRead = function ( itemIdArray, isRead ) {
|
2016-01-15 22:11:33 +00:00
|
|
|
var data = {
|
2016-11-18 21:16:43 +00:00
|
|
|
action: 'echomarkread'
|
|
|
|
};
|
2016-01-15 22:11:33 +00:00
|
|
|
|
2016-03-04 22:44:22 +00:00
|
|
|
if ( isRead ) {
|
|
|
|
data.list = itemIdArray.join( '|' );
|
|
|
|
} else {
|
|
|
|
data.unreadlist = itemIdArray.join( '|' );
|
|
|
|
}
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
return this.api.postWithToken( 'csrf', data );
|
2016-01-15 22:11:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-06-29 23:36:03 +00:00
|
|
|
* Fetch the number of unread notifications.
|
|
|
|
*
|
|
|
|
* @param {string} type Notification type, 'alert', 'message' or 'all'
|
|
|
|
* @param {boolean} [ignoreCrossWiki] Ignore cross-wiki notifications when fetching the count.
|
|
|
|
* If set to false (by default) it counts notifications across all wikis.
|
2016-11-18 21:16:43 +00:00
|
|
|
* @return {jQuery.Promise} Promise which resolves with the unread count
|
2016-01-15 22:11:33 +00:00
|
|
|
*/
|
2016-06-29 23:36:03 +00:00
|
|
|
mw.echo.api.LocalAPIHandler.prototype.fetchUnreadCount = function ( type, ignoreCrossWiki ) {
|
2016-01-15 22:11:33 +00:00
|
|
|
var normalizedType = this.normalizedType[ type ],
|
|
|
|
apiData = {
|
|
|
|
action: 'query',
|
|
|
|
meta: 'notifications',
|
|
|
|
notsections: normalizedType,
|
|
|
|
notgroupbysection: 1,
|
|
|
|
notmessageunreadfirst: 1,
|
|
|
|
notlimit: this.limit,
|
|
|
|
notprop: 'count',
|
|
|
|
uselang: this.userLang
|
|
|
|
};
|
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
if ( !ignoreCrossWiki ) {
|
|
|
|
apiData.notcrosswikisummary = 1;
|
|
|
|
}
|
|
|
|
|
2016-01-15 22:11:33 +00:00
|
|
|
return this.api.get( apiData )
|
|
|
|
.then( function ( result ) {
|
2016-03-15 21:13:19 +00:00
|
|
|
if ( type === 'message' || type === 'alert' ) {
|
|
|
|
return OO.getProp( result.query, 'notifications', normalizedType, 'rawcount' ) || 0;
|
|
|
|
} else {
|
|
|
|
return OO.getProp( result.query, 'notifications', 'rawcount' ) || 0;
|
|
|
|
}
|
2016-01-15 22:11:33 +00:00
|
|
|
} );
|
|
|
|
};
|
2016-04-21 10:28:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
mw.echo.api.LocalAPIHandler.prototype.getTypeParams = function ( type ) {
|
|
|
|
return $.extend( {}, this.typeParams[ type ], {
|
|
|
|
notcrosswikisummary: 1
|
|
|
|
} );
|
|
|
|
};
|
2016-11-18 21:16:43 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|