| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
mw.echo.dm.CrossWikiNotificationItem = function MwEchoDmCrossWikiNotificationItem( id, config ) { |
| 16 |
config = config || {}; |
| 17 |
|
| 18 |
mw.echo.dm.CrossWikiNotificationItem.super.call( this, id, config ); |
| 19 |
|
| 20 |
this.foreign = true; |
| 21 |
this.source = null; |
| 22 |
this.count = config.count || 0; |
| 23 |
this.modelName = config.modelName || 'xwiki'; |
| 24 |
|
| 25 |
this.list = new mw.echo.dm.NotificationGroupsList(); |
| 26 |
|
| 27 |
this.list.connect( this, { discard: 'onListDiscard' } ); |
| 28 |
}; |
| 29 |
|
| 30 |
OO.inheritClass( mw.echo.dm.CrossWikiNotificationItem, mw.echo.dm.NotificationItem ); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
mw.echo.dm.CrossWikiNotificationItem.prototype.onListDiscard = function ( sourceModel ) { |
| 50 |
this.emit( 'discard', sourceModel.getName() ); |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
mw.echo.dm.CrossWikiNotificationItem.prototype.getList = function () { |
| 59 |
return this.list; |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
mw.echo.dm.CrossWikiNotificationItem.prototype.getSourceNames = function () { |
| 68 |
const sourceNames = [], |
| 69 |
sourceLists = this.list.getItems(); |
| 70 |
|
| 71 |
for ( let i = 0; i < sourceLists.length; i++ ) { |
| 72 |
sourceNames.push( sourceLists[ i ].getName() ); |
| 73 |
} |
| 74 |
|
| 75 |
return sourceNames; |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
mw.echo.dm.CrossWikiNotificationItem.prototype.getItemBySource = function ( sourceName ) { |
| 85 |
return this.list.getGroupByName( sourceName ); |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
mw.echo.dm.CrossWikiNotificationItem.prototype.getCount = function () { |
| 94 |
return this.count; |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
mw.echo.dm.CrossWikiNotificationItem.prototype.hasUnseen = function () { |
| 105 |
const sourceLists = this.getList().getItems(); |
| 106 |
|
| 107 |
for ( let i = 0; i < sourceLists.length; i++ ) { |
| 108 |
const items = sourceLists[ i ].getItems(); |
| 109 |
for ( let j = 0; j < items.length; j++ ) { |
| 110 |
if ( !items[ j ].isSeen() ) { |
| 111 |
return true; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
return false; |
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
mw.echo.dm.CrossWikiNotificationItem.prototype.updateSeenState = function ( timestamp ) { |
| 125 |
this.getList().getItems().forEach( ( source ) => { |
| 126 |
source.getItems().forEach( ( notification ) => { |
| 127 |
notification.toggleSeen( |
| 128 |
notification.isRead() || notification.getTimestamp() < timestamp |
| 129 |
); |
| 130 |
} ); |
| 131 |
} ); |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
mw.echo.dm.CrossWikiNotificationItem.prototype.getItems = function () { |
| 140 |
let notifications = []; |
| 141 |
this.list.getItems().forEach( ( sourceList ) => { |
| 142 |
notifications = notifications.concat( sourceList.getItems() ); |
| 143 |
} ); |
| 144 |
|
| 145 |
return notifications; |
| 146 |
}; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
mw.echo.dm.CrossWikiNotificationItem.prototype.isGroup = function () { |
| 156 |
return true; |
| 157 |
}; |
| 158 |
|
| 159 |
mw.echo.dm.CrossWikiNotificationItem.prototype.isEmpty = function () { |
| 160 |
return this.getList().isEmpty(); |
| 161 |
}; |
| 162 |
|
| 163 |
}() ); |