2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
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 ];
|
|
|
|
|
2020-01-11 00:12:18 +00:00
|
|
|
// This is a GET request, not a POST request, for multi-DC support (see T222851)
|
|
|
|
return this.api.get( {
|
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
|
|
|
} )
|
2024-06-03 12:26:18 +00:00
|
|
|
.then( ( data ) => data.query.echomarkseen.timestamp );
|
2016-01-15 22:11:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2018-09-03 16:31:01 +00:00
|
|
|
mw.echo.api.LocalAPIHandler.prototype.markAllRead = function ( source, type ) {
|
2024-06-03 12:22:48 +00:00
|
|
|
const data = {
|
2022-04-20 12:57:12 +00:00
|
|
|
action: 'echomarkread'
|
2018-09-03 16:31:01 +00:00
|
|
|
};
|
2022-04-20 12:57:12 +00:00
|
|
|
type = Array.isArray( type ) ? type : [ type ];
|
|
|
|
if ( type.indexOf( 'all' ) !== -1 ) {
|
|
|
|
// As specified in the documentation of the parent function, the type parameter can be
|
|
|
|
// 'all'. We especially handle that case here to match the PHP API. Note: Other values
|
|
|
|
// of the array will be ignored.
|
|
|
|
data.all = true;
|
|
|
|
} else {
|
2023-04-11 18:55:09 +00:00
|
|
|
data.sections = type;
|
2022-04-20 12:57:12 +00:00
|
|
|
}
|
2018-09-03 16:31:01 +00:00
|
|
|
if ( !this.isSourceLocal( source ) ) {
|
|
|
|
data.wikis = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.api.postWithToken( 'csrf', data )
|
2024-06-03 12:26:18 +00:00
|
|
|
.then( ( result ) => OO.getProp( result.query, 'echomarkread', type, 'rawcount' ) || 0 );
|
2016-01-15 22:11:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2018-09-03 16:31:01 +00:00
|
|
|
mw.echo.api.LocalAPIHandler.prototype.markItemsRead = function ( source, itemIdArray, isRead ) {
|
2024-06-03 12:22:48 +00:00
|
|
|
const data = {
|
2016-11-18 21:16:43 +00:00
|
|
|
action: 'echomarkread'
|
|
|
|
};
|
2016-01-15 22:11:33 +00:00
|
|
|
|
2018-09-03 16:31:01 +00:00
|
|
|
if ( !this.isSourceLocal( source ) ) {
|
|
|
|
data.wikis = source;
|
|
|
|
}
|
|
|
|
|
2016-03-04 22:44:22 +00:00
|
|
|
if ( isRead ) {
|
2023-04-11 18:55:09 +00:00
|
|
|
data.list = itemIdArray;
|
2016-03-04 22:44:22 +00:00
|
|
|
} else {
|
2023-04-11 18:55:09 +00:00
|
|
|
data.unreadlist = itemIdArray;
|
2016-03-04 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
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 ) {
|
2024-06-03 12:22:48 +00:00
|
|
|
const normalizedType = this.normalizedType[ type ],
|
2016-01-15 22:11:33 +00:00
|
|
|
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 )
|
2024-06-03 12:26:18 +00:00
|
|
|
.then( ( 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
|
|
|
|
} );
|
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|