Use API proxying for markasread requests in the front end

This will prevent these requests from being blocked by browser plugins
like Privacy Badger and AdBlock.

I believe this eliminates the last foreign requests in the front end, so
we should clean up and simplify the now largely unused hierarchy of
API-related classes.

Bug: T121930
Change-Id: I74c22514409ad7e206a413306065a0c62d2e793d
This commit is contained in:
Roan Kattouw 2018-09-03 09:31:01 -07:00
parent 55a5823d45
commit 871a5282d0
3 changed files with 20 additions and 7 deletions

View file

@ -182,6 +182,7 @@
/**
* Mark all notifications as read
*
* @param {string} source Wiki name
* @param {string|string[]} type Notification type 'message', 'alert' or 'all'.
* @return {jQuery.Promise} A promise that resolves when all notifications
* are marked as read.
@ -192,6 +193,7 @@
* Mark multiple notification items as read using specific IDs
*
* @abstract
* @param {string} source Wiki name
* @param {string[]} itemIdArray An array of notification item IDs
* @param {boolean} [isRead] Item's new read state; true for marking the item
* as read, false for marking the item as unread

View file

@ -239,7 +239,8 @@
* for that type in the given source
*/
mw.echo.api.EchoApi.prototype.markItemsRead = function ( itemIds, source, isRead ) {
return this.network.getApiHandler( source ).markItemsRead( itemIds, isRead );
// markasread is proxied via the local API
return this.network.getApiHandler( 'local' ).markItemsRead( source, itemIds, isRead );
};
/**
@ -252,7 +253,8 @@
* for that type in the given source
*/
mw.echo.api.EchoApi.prototype.markAllRead = function ( source, type ) {
return this.network.getApiHandler( source ).markAllRead( type );
// markasread is proxied via the local API
return this.network.getApiHandler( 'local' ).markAllRead( source, type );
};
/**

View file

@ -53,13 +53,18 @@
/**
* @inheritdoc
*/
mw.echo.api.LocalAPIHandler.prototype.markAllRead = function ( type ) {
mw.echo.api.LocalAPIHandler.prototype.markAllRead = function ( source, type ) {
var data;
type = Array.isArray( type ) ? type : [ type ];
return this.api.postWithToken( 'csrf', {
data = {
action: 'echomarkread',
sections: type.join( '|' )
} )
};
if ( !this.isSourceLocal( source ) ) {
data.wikis = source;
}
return this.api.postWithToken( 'csrf', data )
.then( function ( result ) {
return OO.getProp( result.query, 'echomarkread', type, 'rawcount' ) || 0;
} );
@ -68,11 +73,15 @@
/**
* @inheritdoc
*/
mw.echo.api.LocalAPIHandler.prototype.markItemsRead = function ( itemIdArray, isRead ) {
mw.echo.api.LocalAPIHandler.prototype.markItemsRead = function ( source, itemIdArray, isRead ) {
var data = {
action: 'echomarkread'
};
if ( !this.isSourceLocal( source ) ) {
data.wikis = source;
}
if ( isRead ) {
data.list = itemIdArray.join( '|' );
} else {