Debian Codegraph @

extensions/Echo/modules/model/mw.echo.dm.BundleNotificationItem.js

raw symbols SCIP
1 ( function () {
2 /**
3 * Bundle notification item model. Contains a list of bundled notifications.
4 * Is expandable.
5 *
6 * @class
7 * @extends mw.echo.dm.NotificationItem
8 *
9 * @constructor
10 * @param {number} id Notification id
11 * @param {mw.echo.dm.NotificationItem[]} bundledNotificationModels
12 * @param {Object} [config] Configuration object
13 */
14 mw.echo.dm.BundleNotificationItem = function MwEchoDmBundleNotificationItem( id, bundledNotificationModels, config ) {
15 // Parent constructor
16 mw.echo.dm.BundleNotificationItem.super.call( this, id, config );
17
18 this.getSecondaryUrls().forEach( ( link ) => {
19 // hack: put all secondary actions in the menu for now
20 // this is a temporary fix for
21 // - alignment of the labels
22 // - make sure there isn't to many secondary links (causes a horizontal scrollbar)
23 delete link.prioritized;
24 } );
25
26 this.setForeign( false );
27 this.count = bundledNotificationModels.length;
28
29 // bundled notifications use the compact header and do not have icons
30 bundledNotificationModels.forEach( ( bundled ) => {
31 bundled.content.header = bundled.content.compactHeader;
32 delete bundled.iconUrl;
33 } );
34
35 this.list = new mw.echo.dm.NotificationsList();
36 this.list.setItems( bundledNotificationModels );
37
38 this.list.connect( this, { itemUpdate: 'onItemUpdate' } );
39
40 // For bundles, 'read' is a computed state based on
41 // inner notifications.
42 // Calling toggleRead here to initialize based
43 // on current computed state.
44 this.toggleRead( this.isRead() );
45 };
46
47 OO.inheritClass( mw.echo.dm.BundleNotificationItem, mw.echo.dm.NotificationItem );
48
49 /* Methods */
50
51 /**
52 * Whenever a bundled notification changes, update the read status of the parent.
53 */
54 mw.echo.dm.BundleNotificationItem.prototype.onItemUpdate = function () {
55 this.toggleRead( this.isRead() );
56 };
57
58 /**
59 * @return {boolean} Whether this bundle is completely read
60 */
61 mw.echo.dm.BundleNotificationItem.prototype.isRead = function () {
62 return this.list.getItems().every( ( item ) => item.isRead() );
63 };
64
65 /**
66 * Get the list of bundled notifications
67 *
68 * @return {mw.echo.dm.NotificationsList} List of bundled notifications
69 */
70 mw.echo.dm.BundleNotificationItem.prototype.getList = function () {
71 return this.list;
72 };
73
74 /**
75 * Get expected item count from all sources
76 *
77 * @return {number} Item count
78 */
79 mw.echo.dm.BundleNotificationItem.prototype.getCount = function () {
80 return this.list.getItemCount();
81 };
82
83 /**
84 * Check if there are unseen items in any of the cross wiki source lists.
85 * This method is required for all models that are managed by the
86 * mw.echo.dm.ModelManager.
87 *
88 * @return {boolean} There are unseen items
89 */
90 mw.echo.dm.BundleNotificationItem.prototype.hasUnseen = function () {
91 return this.list.getItems().some( ( item ) => !item.isSeen() );
92 };
93
94 /**
95 * Set all notifications to seen
96 *
97 * @param {number} timestamp New seen timestamp
98 */
99 mw.echo.dm.BundleNotificationItem.prototype.updateSeenState = function ( timestamp ) {
100 this.list.getItems().forEach( ( notification ) => {
101 notification.toggleSeen(
102 notification.isRead() || notification.getTimestamp() < timestamp
103 );
104 } );
105 };
106
107 /**
108 * This item is a group.
109 * This method is required for all models that are managed by the
110 * mw.echo.dm.ModelManager.
111 *
112 * @return {boolean} This item is a group
113 */
114 mw.echo.dm.BundleNotificationItem.prototype.isGroup = function () {
115 return true;
116 };
117
118 /**
119 * Get the all ids contained in this notification
120 *
121 * @return {number[]}
122 */
123 mw.echo.dm.BundleNotificationItem.prototype.getAllIds = function () {
124 return this.list.getItems().map( ( item ) => item.getId() );
125 };
126
127 /**
128 * Find all items that match the given IDs.
129 *
130 * @param {number[]} ids An array of item IDs
131 * @return {mw.echo.dm.NotificationItem[]} An array of matching items
132 */
133 mw.echo.dm.BundleNotificationItem.prototype.findByIds = function ( ids ) {
134 return this.list.findByIds( ids );
135 };
136
137 /**
138 * Get bundled notifications
139 *
140 * @return {mw.echo.dm.NotificationItem[]} bundled notifications
141 */
142 mw.echo.dm.BundleNotificationItem.prototype.getItems = function () {
143 return this.list.getItems();
144 };
145
146 /**
147 * Get model name
148 *
149 * @return {string} model name
150 */
151 mw.echo.dm.BundleNotificationItem.prototype.getName = function () {
152 return this.getModelName();
153 };
154
155 }() );