Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/284682
Change subject: Let frontend always query local for foreign sources, instead of
those foreign APIs
......................................................................
Let frontend always query local for foreign sources, instead of those foreign
APIs
Bug: T130636
Change-Id: I7bdbb5ed80a514fddc0aba604dc19ada5de13b42
---
M modules/api/mw.echo.api.EchoApi.js
M modules/api/mw.echo.api.ForeignAPIHandler.js
M modules/api/mw.echo.api.NetworkHandler.js
3 files changed, 24 insertions(+), 39 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/82/284682/1
diff --git a/modules/api/mw.echo.api.EchoApi.js
b/modules/api/mw.echo.api.EchoApi.js
index 18fe23d..ab64649 100644
--- a/modules/api/mw.echo.api.EchoApi.js
+++ b/modules/api/mw.echo.api.EchoApi.js
@@ -15,12 +15,12 @@
/**
* Register a set of sources.
*
- * @param {Object} sources Object mapping source names to config objects
+ * @param {string[]} sources List of foreign wikis
*/
mw.echo.api.EchoApi.prototype.registerForeignSources = function (
sources ) {
- var s;
- for ( s in sources ) {
- this.network.addApiHandler( s, sources[ s ], true );
+ var handler = new mw.echo.api.ForeignAPIHandler( Object.keys(
sources ) ), wiki;
+ for ( wiki in sources ) {
+ this.network.addApiHandler( wiki, handler );
}
};
@@ -39,6 +39,17 @@
return this.network.getApiHandler( source ).fetchNotifications(
type, isForced )
.then( function ( result ) {
return OO.getProp( result.query,
'notifications' );
+ } )
+ .then( function ( result ) {
+ // we've fetched results for a lot of different
sources as once,
+ // but we want this one to only include
notifications from this
+ // one specific source, so we'll filter out all
the rest
+ var clone = OO.cloneObject( result );
+ clone.list = clone.list.filter( function (
value ) {
+ return source === 'local' || value.wiki
=== source;
+ } );
+
+ return clone;
} );
};
diff --git a/modules/api/mw.echo.api.ForeignAPIHandler.js
b/modules/api/mw.echo.api.ForeignAPIHandler.js
index 5c89667..493ee00 100644
--- a/modules/api/mw.echo.api.ForeignAPIHandler.js
+++ b/modules/api/mw.echo.api.ForeignAPIHandler.js
@@ -6,17 +6,16 @@
* @extends mw.echo.api.LocalAPIHandler
*
* @constructor
- * @param {string} apiUrl A url for the access point of the
- * foreign API.
+ * @param {string[]} wikis List of foreign wikis.
* @param {Object} [config] Configuration object
*/
- mw.echo.api.ForeignAPIHandler = function MwEchoApiForeignAPIHandler(
apiUrl, config ) {
+ mw.echo.api.ForeignAPIHandler = function MwEchoApiForeignAPIHandler(
wikis, config ) {
config = config || {};
// Parent constructor
mw.echo.api.ForeignAPIHandler.parent.call( this, config );
- this.api = new mw.ForeignApi( apiUrl );
+ this.wikis = wikis;
};
/* Setup */
@@ -28,7 +27,8 @@
*/
mw.echo.api.ForeignAPIHandler.prototype.getTypeParams = function ( type
) {
return $.extend( {}, this.typeParams[ type ], {
- notfilter: '!read'
+ notfilter: '!read',
+ notwikis: this.wikis
} );
}
} )( mediaWiki, jQuery );
diff --git a/modules/api/mw.echo.api.NetworkHandler.js
b/modules/api/mw.echo.api.NetworkHandler.js
index b47cb0a..ca54d4d 100644
--- a/modules/api/mw.echo.api.NetworkHandler.js
+++ b/modules/api/mw.echo.api.NetworkHandler.js
@@ -11,7 +11,7 @@
this.handlers = {};
// Add initial local handler
- this.addApiHandler( 'local', {} );
+ this.addApiHandler( 'local', new mw.echo.api.LocalAPIHandler()
);
};
/* Setup */
@@ -63,39 +63,13 @@
};
/**
- * Add an API handler
- *
- * @param {string} name Symbolic name
- * @param {Object} config Configuration details
- * @param {boolean} isForeign Is a foreign API
- * @throws {Error} If no URL was given for a foreign API
- */
- mw.echo.api.NetworkHandler.prototype.addApiHandler = function ( name,
config, isForeign ) {
- // This must be here so that it short-circuits the object
construction below
- if ( this.handlers[ name ] ) {
- return;
- }
-
- if ( isForeign ) {
- if ( !config.url ) {
- throw new Error( 'Foreign APIs must have a
valid url.' );
- }
- this.addCustomApiHandler( name, new
mw.echo.api.ForeignAPIHandler( config.url, config ) );
- } else {
- this.addCustomApiHandler( name, new
mw.echo.api.LocalAPIHandler( config ) );
- }
- };
-
- /**
- * Add a custom API handler by passing in an instance of an
mw.echo.api.APIHandler subclass directly.
+ * Add an API handler by passing in an instance of an
mw.echo.api.APIHandler subclass directly.
*
* @param {string} name Symbolic name
* @param {mw.echo.api.APIHandler} handler Handler object
*/
- mw.echo.api.NetworkHandler.prototype.addCustomApiHandler = function (
name, handler ) {
- if ( !this.handlers[ name ] ) {
- this.handlers[ name ] = handler;
- }
+ mw.echo.api.NetworkHandler.prototype.addApiHandler = function ( name,
handler ) {
+ this.handlers[ name ] = handler;
};
} )( mediaWiki, jQuery );
--
To view, visit https://gerrit.wikimedia.org/r/284682
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7bdbb5ed80a514fddc0aba604dc19ada5de13b42
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits