Skip to content

Commit 6c0ecef

Browse files
committed
Remove unnecessary closures
Bug: T50886 Change-Id: I59b61593f42e776709c1d8979cfc685dde855f88
1 parent cf87533 commit 6c0ecef

File tree

49 files changed

+7930
-8047
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+7930
-8047
lines changed

modules/api/mw.echo.api.APIHandler.js

Lines changed: 236 additions & 238 deletions
Large diffs are not rendered by default.

modules/api/mw.echo.api.EchoApi.js

Lines changed: 325 additions & 327 deletions
Large diffs are not rendered by default.
Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
1-
( function () {
2-
/**
3-
* Foreign notification API handler
4-
*
5-
* @class
6-
* @extends mw.echo.api.LocalAPIHandler
7-
*
8-
* @constructor
9-
* @param {string} apiUrl A url for the access point of the
10-
* foreign API.
11-
* @param {Object} [config] Configuration object
12-
* @param {boolean} [config.unreadOnly] Whether this handler should request unread
13-
* notifications by default.
14-
*/
15-
mw.echo.api.ForeignAPIHandler = function MwEchoApiForeignAPIHandler( apiUrl, config ) {
16-
config = config || {};
1+
/**
2+
* Foreign notification API handler
3+
*
4+
* @class
5+
* @extends mw.echo.api.LocalAPIHandler
6+
*
7+
* @constructor
8+
* @param {string} apiUrl A url for the access point of the
9+
* foreign API.
10+
* @param {Object} [config] Configuration object
11+
* @param {boolean} [config.unreadOnly] Whether this handler should request unread
12+
* notifications by default.
13+
*/
14+
mw.echo.api.ForeignAPIHandler = function MwEchoApiForeignAPIHandler( apiUrl, config ) {
15+
config = config || {};
1716

18-
// Parent constructor
19-
mw.echo.api.ForeignAPIHandler.super.call( this, config );
17+
// Parent constructor
18+
mw.echo.api.ForeignAPIHandler.super.call( this, config );
2019

21-
this.api = new mw.ForeignApi( apiUrl );
22-
this.unreadOnly = config.unreadOnly !== undefined ? !!config.unreadOnly : false;
23-
};
20+
this.api = new mw.ForeignApi( apiUrl );
21+
this.unreadOnly = config.unreadOnly !== undefined ? !!config.unreadOnly : false;
22+
};
2423

25-
/* Setup */
24+
/* Setup */
2625

27-
OO.inheritClass( mw.echo.api.ForeignAPIHandler, mw.echo.api.LocalAPIHandler );
26+
OO.inheritClass( mw.echo.api.ForeignAPIHandler, mw.echo.api.LocalAPIHandler );
2827

29-
/**
30-
* @inheritdoc
31-
*/
32-
mw.echo.api.ForeignAPIHandler.prototype.getTypeParams = function ( type ) {
33-
let params = {
34-
// Backwards compatibility
35-
notforn: 1
36-
};
28+
/**
29+
* @inheritdoc
30+
*/
31+
mw.echo.api.ForeignAPIHandler.prototype.getTypeParams = function ( type ) {
32+
let params = {
33+
// Backwards compatibility
34+
notforn: 1
35+
};
3736

38-
if ( this.unreadOnly ) {
39-
params = Object.assign( {}, params, { notfilter: '!read' } );
40-
}
37+
if ( this.unreadOnly ) {
38+
params = Object.assign( {}, params, { notfilter: '!read' } );
39+
}
4140

42-
return Object.assign( {}, this.typeParams[ type ], params );
43-
};
44-
}() );
41+
return Object.assign( {}, this.typeParams[ type ], params );
42+
};
Lines changed: 132 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,138 @@
1-
( function () {
2-
/**
3-
* Notification API handler
4-
*
5-
* @class
6-
* @extends mw.echo.api.APIHandler
7-
*
8-
* @constructor
9-
* @param {Object} [config] Configuration object
10-
*/
11-
mw.echo.api.LocalAPIHandler = function MwEchoApiLocalAPIHandler( config ) {
12-
// Parent constructor
13-
mw.echo.api.LocalAPIHandler.super.call( this,
14-
new mw.Api( { ajax: { cache: false } } ),
15-
config
16-
);
1+
/**
2+
* Notification API handler
3+
*
4+
* @class
5+
* @extends mw.echo.api.APIHandler
6+
*
7+
* @constructor
8+
* @param {Object} [config] Configuration object
9+
*/
10+
mw.echo.api.LocalAPIHandler = function MwEchoApiLocalAPIHandler( config ) {
11+
// Parent constructor
12+
mw.echo.api.LocalAPIHandler.super.call( this,
13+
new mw.Api( { ajax: { cache: false } } ),
14+
config
15+
);
16+
};
17+
18+
/* Setup */
19+
20+
OO.inheritClass( mw.echo.api.LocalAPIHandler, mw.echo.api.APIHandler );
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
mw.echo.api.LocalAPIHandler.prototype.fetchNotifications = function ( type, source, isForced, overrideParams ) {
26+
if ( overrideParams ) {
27+
return this.createNewFetchNotificationPromise( type, source, overrideParams );
28+
} else if ( isForced || this.isFetchingErrorState( type, source ) ) {
29+
// Force new promise
30+
return this.createNewFetchNotificationPromise( type, source, overrideParams );
31+
}
32+
33+
return this.getFetchNotificationPromise( type, source, overrideParams );
34+
};
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
mw.echo.api.LocalAPIHandler.prototype.updateSeenTime = function ( type ) {
40+
type = Array.isArray( type ) ? type : [ type ];
41+
42+
// This is a GET request, not a POST request, for multi-DC support (see T222851)
43+
return this.api.get( {
44+
action: 'echomarkseen',
45+
type: type.length === 1 ? type[ 0 ] : 'all',
46+
timestampFormat: 'ISO_8601'
47+
} )
48+
.then( ( data ) => data.query.echomarkseen.timestamp );
49+
};
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
mw.echo.api.LocalAPIHandler.prototype.markAllRead = function ( source, type ) {
55+
const data = {
56+
action: 'echomarkread'
1757
};
18-
19-
/* Setup */
20-
21-
OO.inheritClass( mw.echo.api.LocalAPIHandler, mw.echo.api.APIHandler );
22-
23-
/**
24-
* @inheritdoc
25-
*/
26-
mw.echo.api.LocalAPIHandler.prototype.fetchNotifications = function ( type, source, isForced, overrideParams ) {
27-
if ( overrideParams ) {
28-
return this.createNewFetchNotificationPromise( type, source, overrideParams );
29-
} else if ( isForced || this.isFetchingErrorState( type, source ) ) {
30-
// Force new promise
31-
return this.createNewFetchNotificationPromise( type, source, overrideParams );
32-
}
33-
34-
return this.getFetchNotificationPromise( type, source, overrideParams );
35-
};
36-
37-
/**
38-
* @inheritdoc
39-
*/
40-
mw.echo.api.LocalAPIHandler.prototype.updateSeenTime = function ( type ) {
41-
type = Array.isArray( type ) ? type : [ type ];
42-
43-
// This is a GET request, not a POST request, for multi-DC support (see T222851)
44-
return this.api.get( {
45-
action: 'echomarkseen',
46-
type: type.length === 1 ? type[ 0 ] : 'all',
47-
timestampFormat: 'ISO_8601'
48-
} )
49-
.then( ( data ) => data.query.echomarkseen.timestamp );
50-
};
51-
52-
/**
53-
* @inheritdoc
54-
*/
55-
mw.echo.api.LocalAPIHandler.prototype.markAllRead = function ( source, type ) {
56-
const data = {
57-
action: 'echomarkread'
58-
};
59-
type = Array.isArray( type ) ? type : [ type ];
60-
if ( type.indexOf( 'all' ) !== -1 ) {
61-
// As specified in the documentation of the parent function, the type parameter can be
62-
// 'all'. We especially handle that case here to match the PHP API. Note: Other values
63-
// of the array will be ignored.
64-
data.all = true;
65-
} else {
66-
data.sections = type;
67-
}
68-
if ( !this.isSourceLocal( source ) ) {
69-
data.wikis = source;
70-
}
71-
72-
return this.api.postWithToken( 'csrf', data )
73-
.then( ( result ) => OO.getProp( result.query, 'echomarkread', type, 'rawcount' ) || 0 );
58+
type = Array.isArray( type ) ? type : [ type ];
59+
if ( type.indexOf( 'all' ) !== -1 ) {
60+
// As specified in the documentation of the parent function, the type parameter can be
61+
// 'all'. We especially handle that case here to match the PHP API. Note: Other values
62+
// of the array will be ignored.
63+
data.all = true;
64+
} else {
65+
data.sections = type;
66+
}
67+
if ( !this.isSourceLocal( source ) ) {
68+
data.wikis = source;
69+
}
70+
71+
return this.api.postWithToken( 'csrf', data )
72+
.then( ( result ) => OO.getProp( result.query, 'echomarkread', type, 'rawcount' ) || 0 );
73+
};
74+
75+
/**
76+
* @inheritdoc
77+
*/
78+
mw.echo.api.LocalAPIHandler.prototype.markItemsRead = function ( source, itemIdArray, isRead ) {
79+
const data = {
80+
action: 'echomarkread'
7481
};
7582

76-
/**
77-
* @inheritdoc
78-
*/
79-
mw.echo.api.LocalAPIHandler.prototype.markItemsRead = function ( source, itemIdArray, isRead ) {
80-
const data = {
81-
action: 'echomarkread'
83+
if ( !this.isSourceLocal( source ) ) {
84+
data.wikis = source;
85+
}
86+
87+
if ( isRead ) {
88+
data.list = itemIdArray;
89+
} else {
90+
data.unreadlist = itemIdArray;
91+
}
92+
93+
return this.api.postWithToken( 'csrf', data );
94+
};
95+
96+
/**
97+
* Fetch the number of unread notifications.
98+
*
99+
* @param {string} type Notification type, 'alert', 'message' or 'all'
100+
* @param {boolean} [ignoreCrossWiki] Ignore cross-wiki notifications when fetching the count.
101+
* If set to false (by default) it counts notifications across all wikis.
102+
* @return {jQuery.Promise} Promise which resolves with the unread count
103+
*/
104+
mw.echo.api.LocalAPIHandler.prototype.fetchUnreadCount = function ( type, ignoreCrossWiki ) {
105+
const normalizedType = this.normalizedType[ type ],
106+
apiData = {
107+
action: 'query',
108+
meta: 'notifications',
109+
notsections: normalizedType,
110+
notgroupbysection: 1,
111+
notmessageunreadfirst: 1,
112+
notlimit: this.limit,
113+
notprop: 'count',
114+
uselang: this.userLang
82115
};
83116

84-
if ( !this.isSourceLocal( source ) ) {
85-
data.wikis = source;
86-
}
87-
88-
if ( isRead ) {
89-
data.list = itemIdArray;
90-
} else {
91-
data.unreadlist = itemIdArray;
92-
}
93-
94-
return this.api.postWithToken( 'csrf', data );
95-
};
96-
97-
/**
98-
* Fetch the number of unread notifications.
99-
*
100-
* @param {string} type Notification type, 'alert', 'message' or 'all'
101-
* @param {boolean} [ignoreCrossWiki] Ignore cross-wiki notifications when fetching the count.
102-
* If set to false (by default) it counts notifications across all wikis.
103-
* @return {jQuery.Promise} Promise which resolves with the unread count
104-
*/
105-
mw.echo.api.LocalAPIHandler.prototype.fetchUnreadCount = function ( type, ignoreCrossWiki ) {
106-
const normalizedType = this.normalizedType[ type ],
107-
apiData = {
108-
action: 'query',
109-
meta: 'notifications',
110-
notsections: normalizedType,
111-
notgroupbysection: 1,
112-
notmessageunreadfirst: 1,
113-
notlimit: this.limit,
114-
notprop: 'count',
115-
uselang: this.userLang
116-
};
117-
118-
if ( !ignoreCrossWiki ) {
119-
apiData.notcrosswikisummary = 1;
120-
}
121-
122-
return this.api.get( apiData )
123-
.then( ( result ) => {
124-
if ( type === 'message' || type === 'alert' ) {
125-
return OO.getProp( result.query, 'notifications', normalizedType, 'rawcount' ) || 0;
126-
} else {
127-
return OO.getProp( result.query, 'notifications', 'rawcount' ) || 0;
128-
}
129-
} );
130-
};
131-
132-
/**
133-
* @inheritdoc
134-
*/
135-
mw.echo.api.LocalAPIHandler.prototype.getTypeParams = function ( type ) {
136-
return Object.assign( {}, this.typeParams[ type ], {
137-
notcrosswikisummary: 1
117+
if ( !ignoreCrossWiki ) {
118+
apiData.notcrosswikisummary = 1;
119+
}
120+
121+
return this.api.get( apiData )
122+
.then( ( result ) => {
123+
if ( type === 'message' || type === 'alert' ) {
124+
return OO.getProp( result.query, 'notifications', normalizedType, 'rawcount' ) || 0;
125+
} else {
126+
return OO.getProp( result.query, 'notifications', 'rawcount' ) || 0;
127+
}
138128
} );
139-
};
140-
}() );
129+
};
130+
131+
/**
132+
* @inheritdoc
133+
*/
134+
mw.echo.api.LocalAPIHandler.prototype.getTypeParams = function ( type ) {
135+
return Object.assign( {}, this.typeParams[ type ], {
136+
notcrosswikisummary: 1
137+
} );
138+
};

0 commit comments

Comments
 (0)