| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
mw.echo.api.LocalAPIHandler = function MwEchoApiLocalAPIHandler( config ) { |
| 12 |
|
| 13 |
mw.echo.api.LocalAPIHandler.super.call( this, |
| 14 |
new mw.Api( { ajax: { cache: false } } ), |
| 15 |
config |
| 16 |
); |
| 17 |
}; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
OO.inheritClass( mw.echo.api.LocalAPIHandler, mw.echo.api.APIHandler ); |
| 22 |
|
| 23 |
|
| 24 |
|
| 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 |
|
| 31 |
return this.createNewFetchNotificationPromise( type, source, overrideParams ); |
| 32 |
} |
| 33 |
|
| 34 |
return this.getFetchNotificationPromise( type, source, overrideParams ); |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
mw.echo.api.LocalAPIHandler.prototype.updateSeenTime = function ( type ) { |
| 41 |
type = Array.isArray( type ) ? type : [ type ]; |
| 42 |
|
| 43 |
|
| 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 |
|
| 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 |
|
| 62 |
|
| 63 |
|
| 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 ); |
| 74 |
}; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
mw.echo.api.LocalAPIHandler.prototype.markItemsRead = function ( source, itemIdArray, isRead ) { |
| 80 |
const data = { |
| 81 |
action: 'echomarkread' |
| 82 |
}; |
| 83 |
|
| 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 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 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 |
|
| 134 |
|
| 135 |
mw.echo.api.LocalAPIHandler.prototype.getTypeParams = function ( type ) { |
| 136 |
return Object.assign( {}, this.typeParams[ type ], { |
| 137 |
notcrosswikisummary: 1 |
| 138 |
} ); |
| 139 |
}; |
| 140 |
}() ); |