| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
mw.echo.dm.NotificationsList = function MwEchoDmNotificationsList( config ) { |
| 26 |
config = config || {}; |
| 27 |
|
| 28 |
|
| 29 |
mw.echo.dm.NotificationsList.super.call( this ); |
| 30 |
|
| 31 |
this.name = config.name || 'local'; |
| 32 |
this.source = config.source || 'local'; |
| 33 |
this.sourceURL = config.sourceURL || ''; |
| 34 |
this.title = config.title || ''; |
| 35 |
this.fallbackTimestamp = config.timestamp || 0; |
| 36 |
|
| 37 |
|
| 38 |
this.setSortingCallback( config.sortingCallback || ( ( a, b ) => { |
| 39 |
if ( !a.isRead() && b.isRead() ) { |
| 40 |
return -1; |
| 41 |
} else if ( a.isRead() && !b.isRead() ) { |
| 42 |
return 1; |
| 43 |
} else if ( !a.isForeign() && b.isForeign() ) { |
| 44 |
return -1; |
| 45 |
} else if ( a.isForeign() && !b.isForeign() ) { |
| 46 |
return 1; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
if ( b.getTimestamp() < a.getTimestamp() ) { |
| 51 |
return -1; |
| 52 |
} else if ( b.getTimestamp() > a.getTimestamp() ) { |
| 53 |
return 1; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
return b.getId() - a.getId(); |
| 58 |
} ) ); |
| 59 |
|
| 60 |
|
| 61 |
this.aggregate( { update: 'itemUpdate' } ); |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
OO.inheritClass( mw.echo.dm.NotificationsList, mw.echo.dm.SortedList ); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
mw.echo.dm.NotificationsList.prototype.setItems = function ( items ) { |
| 99 |
this.clearItems(); |
| 100 |
this.addItems( items ); |
| 101 |
this.emit( 'update', this.getItems() ); |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
mw.echo.dm.NotificationsList.prototype.discardItems = function ( items ) { |
| 117 |
this.removeItems( items ); |
| 118 |
this.emit( 'discard', items ); |
| 119 |
}; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
mw.echo.dm.NotificationsList.prototype.getAllItemIds = function () { |
| 127 |
const idArray = [], |
| 128 |
items = this.getItems(); |
| 129 |
|
| 130 |
for ( let i = 0; i < items.length; i++ ) { |
| 131 |
idArray.push( items[ i ].getId() ); |
| 132 |
} |
| 133 |
|
| 134 |
return idArray; |
| 135 |
}; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
mw.echo.dm.NotificationsList.prototype.getAllItemIdsByType = function ( type ) { |
| 144 |
const idArray = [], |
| 145 |
items = this.getItems(); |
| 146 |
|
| 147 |
for ( let i = 0; i < items.length; i++ ) { |
| 148 |
if ( items[ i ].getType() === type ) { |
| 149 |
idArray.push( items[ i ].getId() ); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
return idArray; |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
mw.echo.dm.NotificationsList.prototype.getTitle = function () { |
| 162 |
return this.title; |
| 163 |
}; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
mw.echo.dm.NotificationsList.prototype.getName = function () { |
| 171 |
return this.name; |
| 172 |
}; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
mw.echo.dm.NotificationsList.prototype.getSource = function () { |
| 180 |
return this.source; |
| 181 |
}; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
mw.echo.dm.NotificationsList.prototype.getSourceURL = function () { |
| 189 |
return this.sourceURL; |
| 190 |
}; |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
mw.echo.dm.NotificationsList.prototype.getTimestamp = function () { |
| 199 |
const items = this.getItems(); |
| 200 |
|
| 201 |
return ( |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
items.length > 0 ? |
| 206 |
items[ 0 ].getTimestamp() : |
| 207 |
this.fallbackTimestamp |
| 208 |
); |
| 209 |
}; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
mw.echo.dm.NotificationsList.prototype.findByIds = function ( ids ) { |
| 218 |
return this.getItems().filter( ( item ) => ids.indexOf( item.getId() ) !== -1 ); |
| 219 |
}; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
mw.echo.dm.NotificationsList.prototype.getCount = function () { |
| 227 |
return this.getItemCount(); |
| 228 |
}; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
mw.echo.dm.NotificationsList.prototype.hasUnseen = function () { |
| 236 |
return this.getItems().some( ( item ) => !item.isSeen() ); |
| 237 |
}; |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
mw.echo.dm.NotificationsList.prototype.updateSeenState = function ( timestamp ) { |
| 245 |
this.getItems().forEach( ( notification ) => { |
| 246 |
notification.toggleSeen( |
| 247 |
notification.isRead() || notification.getTimestamp() < timestamp |
| 248 |
); |
| 249 |
} ); |
| 250 |
}; |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
mw.echo.dm.NotificationsList.prototype.isGroup = function () { |
| 256 |
return false; |
| 257 |
}; |
| 258 |
|
| 259 |
mw.echo.dm.NotificationsList.prototype.isForeign = function () { |
| 260 |
return this.getSource() !== 'local'; |
| 261 |
}; |
| 262 |
|
| 263 |
}() ); |