Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/293451
Change subject: Separate model's symbolic name and model's source ...................................................................... Separate model's symbolic name and model's source This should have been done from the beginning; the model manager pulls models by their symbolic names. So far, we've used the source for that, but that assumes that two modules always have different sources, and that is absolutely not necessarily the case. For example, internal local bundles will each be a model, but have the same ('local') source. They should still be differentiated in the manager by their names, but the source should state clearly that it is local. For this, the models now have "getName" method and the name is created separately from their source. Items also preserve a reference to their parent's symbolic name so they can provide that for items that require the controller to manipulate a specific model. Change-Id: I8c39d5d28383d11fb330addce21e07d5c424da6f --- M modules/controller/mw.echo.Controller.js M modules/model/mw.echo.dm.ModelManager.js M modules/model/mw.echo.dm.NotificationItem.js M modules/model/mw.echo.dm.NotificationsList.js M modules/ui/mw.echo.ui.SingleNotificationItemWidget.js M modules/ui/mw.echo.ui.SubGroupListWidget.js 6 files changed, 48 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/51/293451/1 diff --git a/modules/controller/mw.echo.Controller.js b/modules/controller/mw.echo.Controller.js index eac7c92..ebd42a2 100644 --- a/modules/controller/mw.echo.Controller.js +++ b/modules/controller/mw.echo.Controller.js @@ -74,6 +74,8 @@ var controller = this, pagination = this.manager.getPaginationModel(), filters = this.manager.getFiltersModel(), + // When we have multiple possible sources, this will change + currentSource = 'local', continueValue = pagination.getPageContinue( page || pagination.getCurrPageIndex() ); pagination.setItemsPerPage( this.api.getLimit() ); @@ -100,7 +102,8 @@ newNotifData = controller.createNotificationData( notifData ); if ( notifData.type !== 'foreign' ) { date = newNotifData.timestamp.substring( 0, 8 ); - newNotifData.source = 'local_' + date; + newNotifData.modelName = 'local_' + date; + newNotifData.source = currentSource; // Single notifications itemModel = new mw.echo.dm.NotificationItem( @@ -123,7 +126,8 @@ // Set up model models[ symbolicName ] = new mw.echo.dm.NotificationsList( { type: controller.manager.getTypes(), - source: symbolicName, + name: symbolicName, + source: currentSource, title: date, timestamp: date } ); @@ -194,6 +198,7 @@ if ( notifData.type === 'foreign' ) { // x-wiki notification multi-group // We need to request a new list model + newNotifData.name = 'xwiki'; allModels.xwiki = foreignListModel = new mw.echo.dm.CrossWikiNotificationItem( notifData.id, newNotifData ); foreignListModel.setForeign( true ); @@ -301,7 +306,7 @@ } } - return this.markItemsRead( itemIds, model.getSource(), true ); + return this.markItemsRead( itemIds, model.getName(), model.getSource(), true ); }; /** @@ -362,6 +367,7 @@ * that is part of an xwiki foreign list. * * @param {number} itemId Item ID + * @param {string} modelName The name of the model that these items belong to * @param {string} modelSource The source that these items belong to * @param {boolean} [isForeign=false] The model is foreign, inside a cross-wiki * bundle. @@ -371,33 +377,34 @@ * is complete, with the number of unread notifications still remaining * for the set type of this controller, in the given source. */ - mw.echo.Controller.prototype.markSingleItemRead = function ( itemId, modelSource, isForeign, isRead ) { + mw.echo.Controller.prototype.markSingleItemRead = function ( itemId, modelName, modelSource, isForeign, isRead ) { if ( isForeign ) { return this.markCrossWikiItemsRead( [ itemId ], modelSource, isRead ); } - return this.markItemsRead( [ itemId ], modelSource, isRead ); + return this.markItemsRead( [ itemId ], modelName, modelSource, isRead ); }; /** * Mark local items as read in the API. * * @param {string[]|string} itemIds An array of item IDs, or a single item ID, to mark as read - * @param {string} modelSource The source that these items belong to + * @param {string} modelName The name of the model that these items belong to + * @param {string} modelSource The source that these items come from * @param {boolean} [isRead=true] The read state of the item; true for marking the * item as read, false for marking the item as unread * @return {jQuery.Promise} A promise that is resolved when the operation * is complete, with the number of unread notifications still remaining * for the set type of this controller, in the given source. */ - mw.echo.Controller.prototype.markItemsRead = function ( itemIds, modelSource, isRead ) { + mw.echo.Controller.prototype.markItemsRead = function ( itemIds, modelName, modelSource, isRead ) { var allIds = []; itemIds = Array.isArray( itemIds ) ? itemIds : [ itemIds ]; // Default to true isRead = isRead === undefined ? true : isRead; - this.manager.getNotificationModel( modelSource ).findByIds( itemIds ).forEach( function ( notification ) { + this.manager.getNotificationModel( modelName ).findByIds( itemIds ).forEach( function ( notification ) { allIds = allIds.concat( notification.getAllIds() ); notification.toggleRead( isRead ); } ); diff --git a/modules/model/mw.echo.dm.ModelManager.js b/modules/model/mw.echo.dm.ModelManager.js index 9fcae1c..c538e48 100644 --- a/modules/model/mw.echo.dm.ModelManager.js +++ b/modules/model/mw.echo.dm.ModelManager.js @@ -10,6 +10,7 @@ * * All notification models that are managed by the manager must implement the * following methods: + * * getName - This should retrieve the model's name for the manager to fetch * * isGroup - This should be true for xwiki model and local bundles * * hasUnseen - This should iterate in the model's items and check whether * there are any unseen notifications within them. diff --git a/modules/model/mw.echo.dm.NotificationItem.js b/modules/model/mw.echo.dm.NotificationItem.js index a1b3621..145d61a 100644 --- a/modules/model/mw.echo.dm.NotificationItem.js +++ b/modules/model/mw.echo.dm.NotificationItem.js @@ -25,6 +25,7 @@ * @cfg {boolean} [foreign=false] This notification is from a foreign source * @cfg {boolean} [bundled=false] This notification is part of a bundle * @cfg {number[]} [bundledIds] IDs of notifications bundled with this one + * @cfg {string} [modelName='local'] The name of the model this item belongs to * @cfg {string} [source] The source this notification is coming from, if it is foreign * @cfg {Object[]} [secondaryUrls] An array of objects defining the secondary URLs * for this notification. The secondary URLs are expected to have this structure: @@ -56,6 +57,7 @@ // Properties this.id = id; + this.modelName = config.modelName || 'local'; this.content = $.extend( { header: '', body: '' }, config.content ); this.category = config.category || ''; this.type = config.type || 'message'; @@ -284,6 +286,15 @@ }; /** + * Get the notification's model name + * + * @return {string} Notification model name + */ + mw.echo.dm.NotificationItem.prototype.getModelName = function () { + return this.modelName; + }; + + /** * Get the all ids contained in this notification * * @return {number[]} diff --git a/modules/model/mw.echo.dm.NotificationsList.js b/modules/model/mw.echo.dm.NotificationsList.js index b2b46fe..c0da050 100644 --- a/modules/model/mw.echo.dm.NotificationsList.js +++ b/modules/model/mw.echo.dm.NotificationsList.js @@ -11,9 +11,10 @@ * @constructor * @param {Object} config Configuration options * @cfg {string} [title] An optional title for this notifications list + * @cfg {string} [name='local'] Symbolic name for this list * @cfg {string} [source='local'] Symbolic name for the source of this list. - * This is used mainly for recognizing where API actions should be - * by the controller. + * This is used mainly for recognizing where API actions should be by the + * controller. * @cfg {string} [sourceURL] The URL for the article base of the remote * group or wiki * @cfg {string} [timestamp=0] A timestamp representing the latest item in @@ -25,6 +26,7 @@ // Parent constructor mw.echo.dm.NotificationsList.parent.call( this ); + this.name = config.name || 'local'; this.source = config.source || 'local'; this.sourceURL = config.sourceURL; this.title = config.title || ''; @@ -144,6 +146,15 @@ }; /** + * Get the name associated with this list. + * + * @return {string} List name + */ + mw.echo.dm.NotificationsList.prototype.getName = function () { + return this.name; + }; + + /** * Get the source associated with this list. * * @return {string} List source diff --git a/modules/ui/mw.echo.ui.SingleNotificationItemWidget.js b/modules/ui/mw.echo.ui.SingleNotificationItemWidget.js index a30bf4c..40e7607 100644 --- a/modules/ui/mw.echo.ui.SingleNotificationItemWidget.js +++ b/modules/ui/mw.echo.ui.SingleNotificationItemWidget.js @@ -70,7 +70,13 @@ mw.echo.ui.SingleNotificationItemWidget.prototype.markRead = function ( isRead ) { isRead = isRead !== undefined ? isRead : true; - this.controller.markSingleItemRead( this.model.getId(), this.model.getSource(), this.model.isForeign(), !!isRead ); + this.controller.markSingleItemRead( + this.model.getId(), + this.model.getModelName(), + this.model.getSource(), + this.model.isForeign(), + !!isRead + ); }; /** diff --git a/modules/ui/mw.echo.ui.SubGroupListWidget.js b/modules/ui/mw.echo.ui.SubGroupListWidget.js index e0f772b..1ccd13f 100644 --- a/modules/ui/mw.echo.ui.SubGroupListWidget.js +++ b/modules/ui/mw.echo.ui.SubGroupListWidget.js @@ -126,7 +126,7 @@ * Respond to 'mark all as read' button click */ mw.echo.ui.SubGroupListWidget.prototype.onMarkAllReadButtonClick = function () { - this.controller.markEntireListModelRead( this.model.getSource() ); + this.controller.markEntireListModelRead( this.model.getName() ); }; /** -- To view, visit https://gerrit.wikimedia.org/r/293451 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8c39d5d28383d11fb330addce21e07d5c424da6f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits