| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
mw.echo.Controller = function MwEchoController( echoApi, manager ) { |
| 10 |
this.api = echoApi; |
| 11 |
this.manager = manager; |
| 12 |
}; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
OO.initClass( mw.echo.Controller ); |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
mw.echo.Controller.prototype.setFilter = function ( filter ) { |
| 26 |
const filtersModel = this.manager.getFiltersModel(), |
| 27 |
values = Array.prototype.slice.call( arguments ); |
| 28 |
|
| 29 |
values.shift(); |
| 30 |
|
| 31 |
if ( filter === 'readState' ) { |
| 32 |
filtersModel.setReadState( values[ 0 ] ); |
| 33 |
} else if ( filter === 'sourcePage' ) { |
| 34 |
filtersModel.setCurrentSourcePage( values[ 0 ], values[ 1 ] ); |
| 35 |
this.manager.getLocalCounter().setSource( filtersModel.getSourcePagesModel().getCurrentSource() ); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
this.manager.getPaginationModel().reset(); |
| 40 |
}; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
mw.echo.Controller.prototype.fetchNextPageByDate = function () { |
| 49 |
this.manager.getPaginationModel().forwards(); |
| 50 |
return this.fetchLocalNotificationsByDate(); |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
mw.echo.Controller.prototype.fetchPrevPageByDate = function () { |
| 60 |
this.manager.getPaginationModel().backwards(); |
| 61 |
return this.fetchLocalNotificationsByDate(); |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
mw.echo.Controller.prototype.fetchFirstPageByDate = function () { |
| 71 |
this.manager.getPaginationModel().setCurrPageIndex( 0 ); |
| 72 |
return this.fetchLocalNotificationsByDate(); |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
mw.echo.Controller.prototype.fetchUnreadPagesByWiki = function () { |
| 83 |
const filterModel = this.manager.getFiltersModel(), |
| 84 |
sourcePageModel = filterModel.getSourcePagesModel(); |
| 85 |
|
| 86 |
return this.api.fetchUnreadNotificationPages() |
| 87 |
.then( ( data ) => { |
| 88 |
const result = {}, |
| 89 |
foreignSources = {}; |
| 90 |
|
| 91 |
for ( const source in data ) { |
| 92 |
if ( source !== mw.config.get( 'wgWikiID' ) ) { |
| 93 |
|
| 94 |
foreignSources[ source ] = data[ source ].source; |
| 95 |
} |
| 96 |
result[ source === mw.config.get( 'wgWikiID' ) ? 'local' : source ] = data[ source ]; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
this.api.registerForeignSources( foreignSources, false ); |
| 101 |
|
| 102 |
|
| 103 |
sourcePageModel.setAllSources( result ); |
| 104 |
} ); |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
mw.echo.Controller.prototype.fetchLocalNotificationsByDate = function ( page ) { |
| 117 |
const pagination = this.manager.getPaginationModel(), |
| 118 |
filters = this.manager.getFiltersModel(), |
| 119 |
currentSource = filters.getSourcePagesModel().getCurrentSource(), |
| 120 |
continueValue = pagination.getPageContinue( page || pagination.getCurrPageIndex() ); |
| 121 |
|
| 122 |
pagination.setItemsPerPage( this.api.getLimit() ); |
| 123 |
|
| 124 |
return this.api.fetchFilteredNotifications( |
| 125 |
this.manager.getTypeString(), |
| 126 |
currentSource, |
| 127 |
{ |
| 128 |
continue: continueValue, |
| 129 |
readState: filters.getReadState(), |
| 130 |
titles: filters.getSourcePagesModel().getGroupedPagesForCurrentTitle() |
| 131 |
} |
| 132 |
) |
| 133 |
.then( ( data ) => { |
| 134 |
const dateItemIds = {}, |
| 135 |
dateItems = {}, |
| 136 |
models = {}; |
| 137 |
|
| 138 |
data = data || { list: [] }; |
| 139 |
|
| 140 |
|
| 141 |
for ( let i = 0; i < data.list.length; i++ ) { |
| 142 |
const notifData = data.list[ i ]; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
const maxSeenTime = data.seenTime.alert < data.seenTime.notice ? |
| 153 |
data.seenTime.notice : data.seenTime.alert; |
| 154 |
this.manager.getSeenTimeModel().setSeenTime( |
| 155 |
maxSeenTime |
| 156 |
); |
| 157 |
|
| 158 |
|
| 159 |
const newNotifData = this.createNotificationData( notifData ); |
| 160 |
if ( notifData.type !== 'foreign' ) { |
| 161 |
const localizedDate = moment.utc( newNotifData.timestamp ).local().format( 'YYYYMMDD' ); |
| 162 |
|
| 163 |
newNotifData.modelName = 'local_' + localizedDate; |
| 164 |
newNotifData.source = currentSource; |
| 165 |
|
| 166 |
|
| 167 |
const itemModel = new mw.echo.dm.NotificationItem( |
| 168 |
notifData.id, |
| 169 |
newNotifData |
| 170 |
); |
| 171 |
|
| 172 |
dateItems[ localizedDate ] = dateItems[ localizedDate ] || []; |
| 173 |
dateItems[ localizedDate ].push( itemModel ); |
| 174 |
|
| 175 |
dateItemIds[ localizedDate ] = dateItemIds[ localizedDate ] || []; |
| 176 |
dateItemIds[ localizedDate ].push( notifData.id ); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
for ( const date in dateItems ) { |
| 182 |
const symbolicName = 'local_' + date; |
| 183 |
|
| 184 |
|
| 185 |
models[ symbolicName ] = new mw.echo.dm.NotificationsList( { |
| 186 |
type: this.manager.getTypes(), |
| 187 |
name: symbolicName, |
| 188 |
source: currentSource, |
| 189 |
title: date, |
| 190 |
timestamp: date, |
| 191 |
sortingCallback: function ( a, b ) { |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
if ( b.getTimestamp() < a.getTimestamp() ) { |
| 196 |
return -1; |
| 197 |
} else if ( b.getTimestamp() > a.getTimestamp() ) { |
| 198 |
return 1; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
return b.getId() - a.getId(); |
| 203 |
} |
| 204 |
} ); |
| 205 |
models[ symbolicName ].setItems( dateItems[ date ] ); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
this.api.registerLocalSources( Object.keys( models ) ); |
| 210 |
|
| 211 |
|
| 212 |
this.manager.setNotificationModels( models ); |
| 213 |
|
| 214 |
|
| 215 |
pagination.setNextPageContinue( data.continue ); |
| 216 |
|
| 217 |
|
| 218 |
this.manager.getLocalCounter().update(); |
| 219 |
|
| 220 |
return dateItemIds; |
| 221 |
} ) |
| 222 |
.then( |
| 223 |
null, |
| 224 |
( errCode, errObj ) => ( { |
| 225 |
errCode: errCode, |
| 226 |
errInfo: OO.getProp( errObj, 'error', 'info' ) |
| 227 |
} ) |
| 228 |
); |
| 229 |
}; |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
mw.echo.Controller.prototype.fetchLocalNotifications = function ( isForced ) { |
| 240 |
|
| 241 |
const localListModel = new mw.echo.dm.NotificationsList( { |
| 242 |
type: this.manager.getTypes() |
| 243 |
} ), |
| 244 |
localItems = [], |
| 245 |
idArray = []; |
| 246 |
|
| 247 |
this.manager.counter.update(); |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
return this.api.fetchNotifications( this.manager.getTypeString(), 'local', !!isForced, { unreadFirst: true, bundle: true } ) |
| 255 |
.then( |
| 256 |
|
| 257 |
( data ) => { |
| 258 |
const allModels = { local: localListModel }, |
| 259 |
createBundledNotification = ( modelName, rawBundledNotifData ) => { |
| 260 |
const bundleNotifData = this.createNotificationData( rawBundledNotifData ); |
| 261 |
bundleNotifData.bundled = true; |
| 262 |
bundleNotifData.modelName = modelName; |
| 263 |
return new mw.echo.dm.NotificationItem( |
| 264 |
rawBundledNotifData.id, |
| 265 |
bundleNotifData |
| 266 |
); |
| 267 |
}; |
| 268 |
|
| 269 |
data = data || { list: [] }; |
| 270 |
|
| 271 |
|
| 272 |
for ( let i = 0; i < data.list.length; i++ ) { |
| 273 |
const notifData = data.list[ i ]; |
| 274 |
|
| 275 |
|
| 276 |
this.manager.getSeenTimeModel().setSeenTime( |
| 277 |
this.getTypes().length > 1 ? |
| 278 |
( |
| 279 |
data.seenTime.alert < data.seenTime.notice ? |
| 280 |
data.seenTime.notice : data.seenTime.alert |
| 281 |
) : |
| 282 |
data.seenTime[ this.getTypeString() ] |
| 283 |
); |
| 284 |
|
| 285 |
|
| 286 |
const newNotifData = this.createNotificationData( notifData ); |
| 287 |
if ( notifData.type === 'foreign' ) { |
| 288 |
|
| 289 |
|
| 290 |
newNotifData.name = 'xwiki'; |
| 291 |
const foreignListModel = allModels.xwiki = new mw.echo.dm.CrossWikiNotificationItem( notifData.id, newNotifData ); |
| 292 |
foreignListModel.setForeign( true ); |
| 293 |
|
| 294 |
|
| 295 |
this.api.registerForeignSources( notifData.sources, true ); |
| 296 |
|
| 297 |
for ( const source in notifData.sources ) { |
| 298 |
foreignListModel.getList().addGroup( |
| 299 |
source, |
| 300 |
notifData.sources[ source ] |
| 301 |
); |
| 302 |
} |
| 303 |
|
| 304 |
} else if ( Array.isArray( newNotifData.bundledNotifications ) ) { |
| 305 |
|
| 306 |
newNotifData.modelName = 'bundle_' + notifData.id; |
| 307 |
const itemModel = new mw.echo.dm.BundleNotificationItem( |
| 308 |
notifData.id, |
| 309 |
newNotifData.bundledNotifications.map( createBundledNotification.bind( null, newNotifData.modelName ) ), |
| 310 |
newNotifData |
| 311 |
); |
| 312 |
allModels[ newNotifData.modelName ] = itemModel; |
| 313 |
} else { |
| 314 |
|
| 315 |
const itemModel = new mw.echo.dm.NotificationItem( |
| 316 |
notifData.id, |
| 317 |
newNotifData |
| 318 |
); |
| 319 |
|
| 320 |
idArray.push( notifData.id ); |
| 321 |
localItems.push( itemModel ); |
| 322 |
|
| 323 |
if ( newNotifData.bundledNotifications ) { |
| 324 |
|
| 325 |
|
| 326 |
mw.log.warn( |
| 327 |
'newNotifData.bundledNotifications is expected to be an array,' + |
| 328 |
'but instead received "' + typeof newNotifData.bundledNotifications + '"' |
| 329 |
); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
localListModel.addItems( localItems ); |
| 337 |
|
| 338 |
|
| 339 |
this.manager.setNotificationModels( allModels ); |
| 340 |
|
| 341 |
return idArray; |
| 342 |
}, |
| 343 |
|
| 344 |
( errCode, errObj ) => { |
| 345 |
if ( !this.manager.getNotificationModel( 'local' ) ) { |
| 346 |
|
| 347 |
this.manager.setNotificationModels( { local: localListModel } ); |
| 348 |
} |
| 349 |
return { |
| 350 |
errCode: errCode, |
| 351 |
errInfo: OO.getProp( errObj, 'error', 'info' ) |
| 352 |
}; |
| 353 |
} |
| 354 |
); |
| 355 |
}; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
mw.echo.Controller.prototype.createNotificationData = function ( apiData ) { |
| 365 |
const content = apiData[ '*' ] || {}; |
| 366 |
|
| 367 |
let utcTimestamp; |
| 368 |
if ( apiData.timestamp.utciso8601 ) { |
| 369 |
utcTimestamp = apiData.timestamp.utciso8601; |
| 370 |
} else { |
| 371 |
|
| 372 |
|
| 373 |
const utcIsoMoment = moment.utc( apiData.timestamp.utcunix * 1000 ); |
| 374 |
utcTimestamp = utcIsoMoment.format( 'YYYY-MM-DD[T]HH:mm:ss[Z]' ); |
| 375 |
} |
| 376 |
|
| 377 |
return { |
| 378 |
type: apiData.section, |
| 379 |
foreign: false, |
| 380 |
source: 'local', |
| 381 |
count: apiData.count, |
| 382 |
read: !!apiData.read, |
| 383 |
seen: ( |
| 384 |
!!apiData.read || |
| 385 |
utcTimestamp <= this.manager.getSeenTime() |
| 386 |
), |
| 387 |
timestamp: utcTimestamp, |
| 388 |
category: apiData.category, |
| 389 |
content: { |
| 390 |
header: content.header, |
| 391 |
compactHeader: content.compactHeader, |
| 392 |
body: content.body |
| 393 |
}, |
| 394 |
iconUrl: content.iconUrl, |
| 395 |
iconType: content.icon, |
| 396 |
primaryUrl: OO.getProp( content.links, 'primary', 'url' ), |
| 397 |
secondaryUrls: OO.getProp( content.links, 'secondary' ) || [], |
| 398 |
bundledIds: apiData.bundledIds, |
| 399 |
bundledNotifications: apiData.bundledNotifications |
| 400 |
}; |
| 401 |
}; |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
mw.echo.Controller.prototype.markEntireListModelRead = function ( modelName, isRead ) { |
| 416 |
const itemIds = [], |
| 417 |
model = this.manager.getNotificationModel( modelName || 'local' ); |
| 418 |
|
| 419 |
if ( !model ) { |
| 420 |
|
| 421 |
return $.Deferred().reject(); |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
isRead = isRead === undefined ? true : isRead; |
| 426 |
|
| 427 |
const items = model.getItems(); |
| 428 |
for ( let i = 0; i < items.length; i++ ) { |
| 429 |
const item = items[ i ]; |
| 430 |
if ( item.isRead() !== isRead ) { |
| 431 |
itemIds.push( item.getId() ); |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
return this.markItemsRead( itemIds, model.getName(), isRead ); |
| 436 |
}; |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
mw.echo.Controller.prototype.markAllRead = function ( source ) { |
| 448 |
const itemIds = [], |
| 449 |
readState = this.manager.getFiltersModel().getReadState(), |
| 450 |
localCounter = this.manager.getLocalCounter(); |
| 451 |
|
| 452 |
source = source || this.manager.getFiltersModel().getSourcePagesModel().getCurrentSource(); |
| 453 |
|
| 454 |
this.manager.getNotificationsBySource( source ).forEach( ( notification ) => { |
| 455 |
if ( !notification.isRead() ) { |
| 456 |
itemIds.push( ...notification.getAllIds() ); |
| 457 |
notification.toggleRead( true ); |
| 458 |
|
| 459 |
if ( readState === 'unread' ) { |
| 460 |
|
| 461 |
const model = this.manager.getNotificationModel( notification.getModelName() ); |
| 462 |
model.discardItems( notification ); |
| 463 |
} |
| 464 |
} |
| 465 |
} ); |
| 466 |
|
| 467 |
|
| 468 |
this.manager.updateCurrentPageItemCount(); |
| 469 |
|
| 470 |
localCounter.estimateChange( -itemIds.length ); |
| 471 |
return this.api.markAllRead( |
| 472 |
source, |
| 473 |
this.getTypes() |
| 474 |
).then( |
| 475 |
this.refreshUnreadCount.bind( this ) |
| 476 |
).then( |
| 477 |
localCounter.update.bind( localCounter, true ) |
| 478 |
); |
| 479 |
}; |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
mw.echo.Controller.prototype.markLocalNotificationsRead = function () { |
| 488 |
const readState = this.manager.getFiltersModel().getReadState(), |
| 489 |
modelItems = {}; |
| 490 |
|
| 491 |
this.manager.getLocalNotifications().forEach( ( notification ) => { |
| 492 |
if ( !notification.isRead() ) { |
| 493 |
notification.toggleRead( true ); |
| 494 |
|
| 495 |
const modelName = notification.getModelName(); |
| 496 |
modelItems[ modelName ] = modelItems[ modelName ] || []; |
| 497 |
modelItems[ modelName ].push( notification ); |
| 498 |
} |
| 499 |
} ); |
| 500 |
|
| 501 |
|
| 502 |
if ( readState === 'unread' ) { |
| 503 |
for ( const name in modelItems ) { |
| 504 |
const model = this.manager.getNotificationModel( name ); |
| 505 |
model.discardItems( modelItems[ name ] ); |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
this.manager.updateCurrentPageItemCount(); |
| 511 |
|
| 512 |
this.manager.getLocalCounter().setCount( 0, false ); |
| 513 |
return this.api.markAllRead( 'local', this.getTypeString() ).then( this.refreshUnreadCount.bind( this ) ); |
| 514 |
}; |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
mw.echo.Controller.prototype.fetchCrossWikiNotifications = function () { |
| 524 |
const xwikiModel = this.manager.getNotificationModel( 'xwiki' ); |
| 525 |
|
| 526 |
if ( !xwikiModel ) { |
| 527 |
|
| 528 |
|
| 529 |
return $.Deferred().reject().promise(); |
| 530 |
} |
| 531 |
|
| 532 |
return this.api.fetchNotificationGroups( xwikiModel.getSourceNames(), this.manager.getTypeString(), true ) |
| 533 |
.then( |
| 534 |
( groupList ) => { |
| 535 |
for ( const group in groupList ) { |
| 536 |
const listModel = xwikiModel.getItemBySource( group ); |
| 537 |
const groupItems = groupList[ group ]; |
| 538 |
|
| 539 |
const items = []; |
| 540 |
for ( let i = 0; i < groupItems.length; i++ ) { |
| 541 |
const notifData = this.createNotificationData( groupItems[ i ] ); |
| 542 |
items.push( |
| 543 |
new mw.echo.dm.NotificationItem( groupItems[ i ].id, Object.assign( notifData, { |
| 544 |
modelName: 'xwiki', |
| 545 |
source: group, |
| 546 |
bundled: true, |
| 547 |
foreign: true |
| 548 |
} ) ) |
| 549 |
); |
| 550 |
} |
| 551 |
|
| 552 |
listModel.setItems( items ); |
| 553 |
} |
| 554 |
}, |
| 555 |
( errCode, errObj ) => ( { |
| 556 |
errCode: errCode, |
| 557 |
errInfo: errCode === 'http' ? |
| 558 |
mw.msg( 'echo-api-failure-cross-wiki' ) : |
| 559 |
OO.getProp( errObj, 'error', 'info' ) |
| 560 |
} ) |
| 561 |
); |
| 562 |
}; |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
mw.echo.Controller.prototype.markItemsRead = function ( itemIds, modelName, isRead ) { |
| 576 |
const model = this.manager.getNotificationModel( modelName ), |
| 577 |
readState = this.manager.getFiltersModel().getReadState(), |
| 578 |
allIds = []; |
| 579 |
|
| 580 |
itemIds = Array.isArray( itemIds ) ? itemIds : [ itemIds ]; |
| 581 |
|
| 582 |
|
| 583 |
isRead = isRead === undefined ? true : isRead; |
| 584 |
|
| 585 |
const items = model.findByIds( itemIds ); |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
if ( readState === 'read' && !isRead ) { |
| 592 |
model.discardItems( items ); |
| 593 |
} else if ( readState === 'unread' && isRead ) { |
| 594 |
model.discardItems( items ); |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
} |
| 601 |
|
| 602 |
items.forEach( ( notification ) => { |
| 603 |
allIds.push( ...notification.getAllIds() ); |
| 604 |
if ( readState === 'all' ) { |
| 605 |
notification.toggleRead( isRead ); |
| 606 |
} |
| 607 |
} ); |
| 608 |
|
| 609 |
|
| 610 |
this.manager.updateCurrentPageItemCount(); |
| 611 |
|
| 612 |
this.manager.getUnreadCounter().estimateChange( isRead ? -allIds.length : allIds.length ); |
| 613 |
if ( modelName !== 'xwiki' ) { |
| 614 |
|
| 615 |
|
| 616 |
this.manager.getLocalCounter().estimateChange( isRead ? -allIds.length : allIds.length ); |
| 617 |
} |
| 618 |
|
| 619 |
return this.api.markItemsRead( allIds, model.getSource(), isRead ).then( this.refreshUnreadCount.bind( this ) ); |
| 620 |
}; |
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
mw.echo.Controller.prototype.markCrossWikiItemsRead = function ( itemIds, source ) { |
| 632 |
const allIds = [], |
| 633 |
xwikiModel = this.manager.getNotificationModel( 'xwiki' ); |
| 634 |
|
| 635 |
if ( !xwikiModel ) { |
| 636 |
return $.Deferred().reject().promise(); |
| 637 |
} |
| 638 |
itemIds = Array.isArray( itemIds ) ? itemIds : [ itemIds ]; |
| 639 |
|
| 640 |
const sourceModel = xwikiModel.getList().getGroupByName( source ); |
| 641 |
const notifs = sourceModel.findByIds( itemIds ); |
| 642 |
sourceModel.discardItems( notifs ); |
| 643 |
|
| 644 |
this.manager.updateCurrentPageItemCount(); |
| 645 |
|
| 646 |
notifs.forEach( ( notif ) => { |
| 647 |
allIds.push( ...notif.getAllIds() ); |
| 648 |
} ); |
| 649 |
this.manager.getUnreadCounter().estimateChange( -allIds.length ); |
| 650 |
return this.api.markItemsRead( allIds, source, true ) |
| 651 |
.then( this.refreshUnreadCount.bind( this ) ); |
| 652 |
}; |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
mw.echo.Controller.prototype.markEntireCrossWikiItemAsRead = function () { |
| 661 |
const xwikiModel = this.manager.getNotificationModel( 'xwiki' ); |
| 662 |
|
| 663 |
if ( !xwikiModel ) { |
| 664 |
return $.Deferred().reject().promise(); |
| 665 |
} |
| 666 |
|
| 667 |
this.manager.getUnreadCounter().estimateChange( -xwikiModel.getCount() ); |
| 668 |
|
| 669 |
return this.api.fetchNotificationGroups( xwikiModel.getSourceNames(), this.manager.getTypeString() ) |
| 670 |
.then( ( groupList ) => { |
| 671 |
const promises = []; |
| 672 |
|
| 673 |
for ( const group in groupList ) { |
| 674 |
const listModel = xwikiModel.getItemBySource( group ); |
| 675 |
const groupItems = groupList[ group ]; |
| 676 |
|
| 677 |
const idArray = []; |
| 678 |
for ( let i = 0; i < groupItems.length; i++ ) { |
| 679 |
idArray.push( groupItems[ i ].id, ...( groupItems[ i ].bundledIds || [] ) ); |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
promises.push( |
| 684 |
this.api.markItemsRead( idArray, listModel.getName(), true ) |
| 685 |
); |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
this.removeCrossWikiItem(); |
| 690 |
|
| 691 |
return mw.echo.api.NetworkHandler.static.waitForAllPromises( promises ).then( |
| 692 |
this.refreshUnreadCount.bind( this ) |
| 693 |
); |
| 694 |
} ); |
| 695 |
}; |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
mw.echo.Controller.prototype.removeCrossWikiItem = function () { |
| 701 |
this.manager.removeNotificationModel( 'xwiki' ); |
| 702 |
}; |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
mw.echo.Controller.prototype.refreshUnreadCount = function () { |
| 711 |
return this.manager.getUnreadCounter().update(); |
| 712 |
}; |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
mw.echo.Controller.prototype.updateSeenTime = function () { |
| 721 |
return this.api.updateSeenTime( |
| 722 |
this.getTypes(), |
| 723 |
|
| 724 |
|
| 725 |
this.manager.getFiltersModel().getSourcePagesModel().getCurrentSource() |
| 726 |
) |
| 727 |
.then( ( time ) => { |
| 728 |
this.manager.getSeenTimeModel().setSeenTime( time ); |
| 729 |
} ); |
| 730 |
}; |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
mw.echo.Controller.prototype.performDynamicAction = function ( data, source ) { |
| 741 |
source = source || this.manager.getFiltersModel().getSourcePagesModel().getCurrentSource(); |
| 742 |
return this.api.queryAPI( data, source ); |
| 743 |
}; |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
mw.echo.Controller.prototype.getTypes = function () { |
| 751 |
return this.manager.getTypes(); |
| 752 |
}; |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
mw.echo.Controller.prototype.getTypeString = function () { |
| 761 |
return this.manager.getTypeString(); |
| 762 |
}; |
| 763 |
}() ); |