mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-01 02:46:46 +00:00
c0a464e425
* Add ISO 8601 date format to notification output This is actually supposed to be the only output date format used, per https://www.mediawiki.org/wiki/API:Data_formats#Timestamps , but I'm not doing anything to deprecate the others right now. * Change wgEchoSeenTime to use ISO 8601. mwgrep and extension grep do not show any usages. However, since it is a breaking change, to minimize disruption, I'm also using this opportunity to change 'message' to 'notice'. * Remove wgEchoInitialNotifCount. I was going to also change 'message' to 'notice' here too, but then I saw it was totally unused. (It was read in Echo to populate a JS variable, but then it was unused.) * Make sure the Special:Notifications page aggregation by days is done by local days, even though the timestamp per item is still UTC. This is to make sure the days are displayed correctly in the local timezone. * Change all reverse sorting callbacks to handle comparisons of ISO 8601. Bug: T141413 Change-Id: I20271345c7d350dc3e7f467288e5cdc98e6250cc
130 lines
3.3 KiB
JavaScript
130 lines
3.3 KiB
JavaScript
( function ( mw, $ ) {
|
|
/**
|
|
* Notification API handler
|
|
*
|
|
* @class
|
|
* @extends mw.echo.api.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,
|
|
new mw.Api( { ajax: { cache: false } } ),
|
|
config
|
|
);
|
|
};
|
|
|
|
/* Setup */
|
|
|
|
OO.inheritClass( mw.echo.api.LocalAPIHandler, mw.echo.api.APIHandler );
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.fetchNotifications = function ( type, source, isForced, overrideParams ) {
|
|
if ( overrideParams ) {
|
|
return this.createNewFetchNotificationPromise( type, source, overrideParams );
|
|
} else if ( isForced || this.isFetchingErrorState( type, source ) ) {
|
|
// Force new promise
|
|
return this.createNewFetchNotificationPromise( type, source, overrideParams );
|
|
}
|
|
|
|
return this.getFetchNotificationPromise( type, source, overrideParams );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.updateSeenTime = function ( type ) {
|
|
type = Array.isArray( type ) ? type : [ type ];
|
|
|
|
return this.api.postWithToken( 'csrf', {
|
|
action: 'echomarkseen',
|
|
type: type.length === 1 ? type[ 0 ] : 'all',
|
|
timestampFormat: 'ISO_8601'
|
|
} )
|
|
.then( function ( data ) {
|
|
return data.query.echomarkseen.timestamp;
|
|
} );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.markAllRead = function ( type ) {
|
|
type = Array.isArray( type ) ? type : [ type ];
|
|
|
|
return this.api.postWithToken( 'csrf', {
|
|
action: 'echomarkread',
|
|
sections: type.join( '|' )
|
|
} )
|
|
.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( 'csrf', data );
|
|
};
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.fetchUnreadCount = function ( type, ignoreCrossWiki ) {
|
|
var normalizedType = this.normalizedType[ type ],
|
|
apiData = {
|
|
action: 'query',
|
|
meta: 'notifications',
|
|
notsections: normalizedType,
|
|
notgroupbysection: 1,
|
|
notmessageunreadfirst: 1,
|
|
notlimit: this.limit,
|
|
notprop: 'count',
|
|
uselang: this.userLang
|
|
};
|
|
|
|
if ( !ignoreCrossWiki ) {
|
|
apiData.notcrosswikisummary = 1;
|
|
}
|
|
|
|
return this.api.get( apiData )
|
|
.then( function ( result ) {
|
|
if ( type === 'message' || type === 'alert' ) {
|
|
return OO.getProp( result.query, 'notifications', normalizedType, 'rawcount' ) || 0;
|
|
} else {
|
|
return OO.getProp( result.query, 'notifications', 'rawcount' ) || 0;
|
|
}
|
|
} );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
mw.echo.api.LocalAPIHandler.prototype.getTypeParams = function ( type ) {
|
|
return $.extend( {}, this.typeParams[ type ], {
|
|
notcrosswikisummary: 1
|
|
} );
|
|
};
|
|
} )( mediaWiki, jQuery );
|