summaryrefslogtreecommitdiff
blob: 16d19a8b187af957596aa3ba4aa77d7fe775aa04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
( function () {
	/**
	 * Foreign notification API handler
	 *
	 * @class
	 * @extends mw.echo.api.LocalAPIHandler
	 *
	 * @constructor
	 * @param {string} apiUrl A url for the access point of the
	 *  foreign API.
	 * @param {Object} [config] Configuration object
	 * @cfg {boolean} [unreadOnly] Whether this handler should request unread
	 *  notifications by default.
	 */
	mw.echo.api.ForeignAPIHandler = function MwEchoApiForeignAPIHandler( apiUrl, config ) {
		config = config || {};

		// Parent constructor
		mw.echo.api.ForeignAPIHandler.super.call( this, config );

		this.api = new mw.ForeignApi( apiUrl );
		this.unreadOnly = config.unreadOnly !== undefined ? !!config.unreadOnly : false;
	};

	/* Setup */

	OO.inheritClass( mw.echo.api.ForeignAPIHandler, mw.echo.api.LocalAPIHandler );

	/**
	 * @inheritdoc
	 */
	mw.echo.api.ForeignAPIHandler.prototype.getTypeParams = function ( type ) {
		var params = {
			// Backwards compatibility
			notforn: 1
		};

		if ( this.unreadOnly ) {
			params = $.extend( {}, params, { notfilter: '!read' } );
		}

		return $.extend( {}, this.typeParams[ type ], params );
	};
}() );