| 1 |
const mobile = require( 'mobile.startup' ), |
| 2 |
View = mobile.View, |
| 3 |
promisedView = mobile.promisedView; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
function notificationsList( echo, markAllReadButton, onCountChange ) { |
| 25 |
const maxNotificationCount = require( './config.json' ).EchoMaxNotificationCount, |
| 26 |
echoApi = new echo.api.EchoApi(), |
| 27 |
unreadCounter = new echo.dm.UnreadNotificationCounter( echoApi, 'all', maxNotificationCount ), |
| 28 |
modelManager = new echo.dm.ModelManager( unreadCounter, { type: [ 'message', 'alert' ] } ), |
| 29 |
controller = new echo.Controller( |
| 30 |
echoApi, |
| 31 |
modelManager, |
| 32 |
{ |
| 33 |
type: [ 'message', 'alert' ] |
| 34 |
} |
| 35 |
), |
| 36 |
markAsReadHandler = function () { |
| 37 |
markAllReadButton.toggle( |
| 38 |
controller.manager.hasLocalUnread() |
| 39 |
); |
| 40 |
markAllReadButton.setTitle( |
| 41 |
mw.msg( 'echo-mark-all-as-read', unreadCounter.getCount() ) |
| 42 |
); |
| 43 |
}, |
| 44 |
|
| 45 |
|
| 46 |
$moreOptions = $( '<div>' ) |
| 47 |
.addClass( 'notifications-overlay-overlay position-fixed skin-invert' ); |
| 48 |
|
| 49 |
echo.config.maxPrioritizedActions = 1; |
| 50 |
|
| 51 |
const wrapperWidget = new echo.ui.NotificationsWrapper( controller, modelManager, { |
| 52 |
$overlay: $moreOptions |
| 53 |
} ); |
| 54 |
|
| 55 |
|
| 56 |
unreadCounter.on( 'countChange', ( count ) => { |
| 57 |
onCountChange( |
| 58 |
controller.manager.getUnreadCounter().getCappedNotificationCount( count ) |
| 59 |
); |
| 60 |
markAsReadHandler(); |
| 61 |
} ); |
| 62 |
markAllReadButton.on( 'click', () => { |
| 63 |
const numNotifications = controller.manager.getLocalUnread().length; |
| 64 |
|
| 65 |
controller.markLocalNotificationsRead() |
| 66 |
.then( () => { |
| 67 |
mw.notify( mw.msg( 'echo-mark-all-as-read-confirmation', numNotifications ) ); |
| 68 |
markAllReadButton.toggle( false ); |
| 69 |
}, () => { |
| 70 |
markAllReadButton.toggle( false ); |
| 71 |
} ); |
| 72 |
} ); |
| 73 |
|
| 74 |
return promisedView( |
| 75 |
|
| 76 |
wrapperWidget.populate().then( () => { |
| 77 |
controller.updateSeenTime(); |
| 78 |
markAsReadHandler(); |
| 79 |
|
| 80 |
modelManager.on( 'update', markAsReadHandler ); |
| 81 |
return View.make( {}, [ wrapperWidget.$element, $moreOptions ] ); |
| 82 |
} ) |
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
module.exports = notificationsList; |