From d1233640353d17198fc9806702710c38816f5517 Mon Sep 17 00:00:00 2001 From: Moriel Schottlender Date: Wed, 23 Dec 2015 10:33:59 -0800 Subject: [PATCH] Log cross-wiki & bundle items impressions and add their source wiki Bug: T120158 Change-Id: Ibcd1923aaff4e1fd6fb1f54eefbc010122caa398 --- .../mw.echo.ui.NotificationGroupItemWidget.js | 18 +++++++++++++ .../ooui/mw.echo.ui.NotificationItemWidget.js | 5 +++- .../mw.echo.dm.NotificationGroupItem.js | 25 +++++++++++++++++-- .../viewmodel/mw.echo.dm.NotificationItem.js | 11 ++++++++ .../mw.echo.dm.NotificationsModel.js | 1 + 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/modules/ooui/mw.echo.ui.NotificationGroupItemWidget.js b/modules/ooui/mw.echo.ui.NotificationGroupItemWidget.js index 63ace574a..12d120b61 100644 --- a/modules/ooui/mw.echo.ui.NotificationGroupItemWidget.js +++ b/modules/ooui/mw.echo.ui.NotificationGroupItemWidget.js @@ -126,7 +126,25 @@ // Query all sources this.model.fetchAllNotificationsInGroups() .then( function ( /* Groups */ ) { + var source, items, i, + models = widget.model.getSubModels(); + widget.popPending(); + + // Log impressions of all items from each group + for ( source in models ) { + items = models[source].getItems(); + for ( i = 0; i < items.length; i++ ) { + mw.echo.logger.logInteraction( + mw.echo.Logger.static.actions.notificationImpression, + mw.echo.Logger.static.context.popup, + items[ i ].getId(), + items[ i ].getCategory(), + false, + source + ); + } + } } ); } }; diff --git a/modules/ooui/mw.echo.ui.NotificationItemWidget.js b/modules/ooui/mw.echo.ui.NotificationItemWidget.js index 7ec907efb..25caba0a3 100644 --- a/modules/ooui/mw.echo.ui.NotificationItemWidget.js +++ b/modules/ooui/mw.echo.ui.NotificationItemWidget.js @@ -166,7 +166,10 @@ mw.echo.Logger.static.actions.notificationClick, mw.echo.Logger.static.context.popup, widget.getModel().getId(), - widget.getModel().getCategory() + widget.getModel().getCategory(), + false, + // Source of this notification if it is cross-wiki + widget.bundle ? widget.getModel().getSource() : '' ); } ) ); diff --git a/modules/viewmodel/mw.echo.dm.NotificationGroupItem.js b/modules/viewmodel/mw.echo.dm.NotificationGroupItem.js index a4c30f028..d6f737397 100644 --- a/modules/viewmodel/mw.echo.dm.NotificationGroupItem.js +++ b/modules/viewmodel/mw.echo.dm.NotificationGroupItem.js @@ -114,6 +114,7 @@ mw.echo.dm.NotificationGroupItem.prototype.fetchAllNotificationsInGroups = function () { var notifModel, model = this, + fetchPromises = [], sourceKeys = Object.keys( this.sources ); return this.networkHandler.fetchNotificationGroups( sourceKeys ) @@ -123,11 +124,12 @@ for ( i = 0; i < sourceKeys.length; i++ ) { notifModel = model.getItemById( sourceKeys[ i ] ); if ( notifModel ) { - notifModel.fetchNotifications( promises[ i ] ); + fetchPromises.push( notifModel.fetchNotifications( promises[ i ] ) ); } } - return promises; + // Wait for all fetch processes to finish before we resolve this promise + return mw.echo.dm.NetworkHandler.static.waitForAllPromises( fetchPromises ); } ); }; @@ -180,4 +182,23 @@ return this.count; }; + /** + * Get the array of sources for this group + * + * @return {string[]} Sources + */ + mw.echo.dm.NotificationGroupItem.prototype.getSources = function () { + return this.sources; + }; + + /** + * Get all the sub-notification models for this group + * + * @return {Object} A keyed object containing mw.echo.dm.NotificationModel + * objects keyed by their source name. + */ + mw.echo.dm.NotificationGroupItem.prototype.getSubModels = function () { + return this.notifModels; + }; + } )( mediaWiki ); diff --git a/modules/viewmodel/mw.echo.dm.NotificationItem.js b/modules/viewmodel/mw.echo.dm.NotificationItem.js index 60ea57353..2ea4a64ce 100644 --- a/modules/viewmodel/mw.echo.dm.NotificationItem.js +++ b/modules/viewmodel/mw.echo.dm.NotificationItem.js @@ -22,6 +22,7 @@ * @cfg {string} [timestamp] Notification timestamp in Mediawiki timestamp format * @cfg {string} [primaryUrl] Notification primary link in raw url format * @cfg {boolean} [external=false] This notification is from an external source + * @cfg {string} [source] The source this notification is coming from, if it is external * @cfg {Object[]} [secondaryUrls] An array of objects defining the secondary URLs * for this notification. The secondary URLs are expected to have this structure: * { @@ -55,6 +56,7 @@ this.category = config.category || ''; this.type = config.type || 'alert'; this.external = !!config.external; + this.source = config.source || ''; this.iconType = config.iconType; this.iconURL = config.iconURL; @@ -253,4 +255,13 @@ mw.echo.dm.NotificationItem.prototype.getSecondaryUrls = function () { return this.secondaryUrls; }; + + /** + * Get the notification's source + * + * @return {string} Notification source + */ + mw.echo.dm.NotificationItem.prototype.getSource = function () { + return this.source; + }; }( mediaWiki, jQuery ) ); diff --git a/modules/viewmodel/mw.echo.dm.NotificationsModel.js b/modules/viewmodel/mw.echo.dm.NotificationsModel.js index 870c522ac..c241a4da6 100644 --- a/modules/viewmodel/mw.echo.dm.NotificationsModel.js +++ b/modules/viewmodel/mw.echo.dm.NotificationsModel.js @@ -442,6 +442,7 @@ iconType: content.icon, type: model.getType(), external: model.isExternal(), + source: model.getSource(), primaryUrl: OO.getProp( content.links, 'primary', 'url' ), secondaryUrls: OO.getProp( content.links, 'secondary' ) || [] };