Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/288733
Change subject: [wip] Fetch notifications by read state in Special:Notifications ...................................................................... [wip] Fetch notifications by read state in Special:Notifications This isn't really done yet, but it shows the system is working and can fetch notifications based on state into the model(s) and display them by date. Change-Id: I7b47e76ae48eaf4732d99616baa3b4b1ee4ddff5 --- M modules/api/mw.echo.api.APIHandler.js M modules/api/mw.echo.api.EchoApi.js M modules/api/mw.echo.api.LocalAPIHandler.js M modules/controller/mw.echo.Controller.js M modules/nojs/mw.echo.special.less M modules/special/ext.echo.special.js 6 files changed, 99 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/33/288733/1 diff --git a/modules/api/mw.echo.api.APIHandler.js b/modules/api/mw.echo.api.APIHandler.js index 90645e0..035ea2d 100644 --- a/modules/api/mw.echo.api.APIHandler.js +++ b/modules/api/mw.echo.api.APIHandler.js @@ -61,7 +61,7 @@ * @param {string} type Notification type * @param {string[]} [sources] An array of sources to query */ - mw.echo.api.APIHandler.prototype.createNewFetchNotificationPromise = function ( type, sources ) { + mw.echo.api.APIHandler.prototype.createNewFetchNotificationPromise = function ( type, sources, apiParams ) { var fetchingSource = 'local', me = this, params = $.extend( { @@ -84,7 +84,7 @@ this.apiErrorState[ type ] = this.apiErrorState[ type ] || {}; this.apiErrorState[ type ][ fetchingSource ] = false; this.fetchNotificationsPromise[ type ] = this.fetchNotificationsPromise[ type ] || {}; - this.fetchNotificationsPromise[ type ][ fetchingSource ] = this.api.get( params ) + this.fetchNotificationsPromise[ type ][ fetchingSource ] = this.api.get( $.extend( params, apiParams ) ) .fail( function () { // Mark API error state me.apiErrorState[ type ][ fetchingSource ] = true; @@ -164,14 +164,14 @@ * @return {jQuery.Promise} Promise that is resolved when notifications are * fetched from the API. */ - mw.echo.api.APIHandler.prototype.getFetchNotificationPromise = function ( type, sources ) { + mw.echo.api.APIHandler.prototype.getFetchNotificationPromise = function ( type, sources, params ) { var fetchingSource = 'local'; if ( Array.isArray( sources ) && sources.indexOf( 'local' ) === -1 ) { fetchingSource = 'foreign'; } if ( !this.fetchNotificationsPromise[ type ] || !this.fetchNotificationsPromise[ type ][ fetchingSource ] ) { - this.createNewFetchNotificationPromise( type, sources ); + this.createNewFetchNotificationPromise( type, sources, params ); } return this.fetchNotificationsPromise[ type ][ fetchingSource ]; }; diff --git a/modules/api/mw.echo.api.EchoApi.js b/modules/api/mw.echo.api.EchoApi.js index b397288..57f31de 100644 --- a/modules/api/mw.echo.api.EchoApi.js +++ b/modules/api/mw.echo.api.EchoApi.js @@ -50,17 +50,33 @@ * @param {string|string[]} [sources] The source from which to fetch the notifications. * If not given, the local notifications will be fetched. * @param {boolean} [isForced] Force a refresh on the fetch notifications promise + * @param {string} [readStatus] Notification read status to fetch. Can be 'read', + * 'unread' or 'all' * @return {jQuery.Promise} Promise that is resolved with all notifications for the * requested types. */ - mw.echo.api.EchoApi.prototype.fetchNotifications = function ( type, sources, isForced ) { + mw.echo.api.EchoApi.prototype.fetchNotifications = function ( type, sources, isForced, readStatus ) { + var acceptableStatus = [ 'read', 'unread', 'all' ], + overrideParams = {}; + sources = Array.isArray( sources ) ? sources : sources ? [ sources ] : null; - return this.network.getApiHandler( 'local' ).fetchNotifications( type, sources, isForced ) + // Fetch a specific read status + readStatus = acceptableStatus.indexOf( readStatus ) === -1 ? + 'all' : + readStatus; + + if ( readStatus === 'read' ) { + overrideParams.notfilter = 'read'; + } else if ( readStatus === 'unread' ) { + overrideParams.notfilter = '!read'; + } + + return this.network.getApiHandler( 'local' ).fetchNotifications( type, sources, isForced, overrideParams ) .then( function ( result ) { return OO.getProp( result.query, 'notifications' ); } ); diff --git a/modules/api/mw.echo.api.LocalAPIHandler.js b/modules/api/mw.echo.api.LocalAPIHandler.js index d657449..ddf69e6 100644 --- a/modules/api/mw.echo.api.LocalAPIHandler.js +++ b/modules/api/mw.echo.api.LocalAPIHandler.js @@ -25,13 +25,13 @@ /** * @inheritdoc */ - mw.echo.api.LocalAPIHandler.prototype.fetchNotifications = function ( type, source, isForced ) { + mw.echo.api.LocalAPIHandler.prototype.fetchNotifications = function ( type, source, isForced, params ) { if ( isForced || this.isFetchingErrorState( type, source ) ) { // Force new promise - this.createNewFetchNotificationPromise( type, source ); + this.createNewFetchNotificationPromise( type, source, params ); } - return this.getFetchNotificationPromise( type, source ); + return this.getFetchNotificationPromise( type, source, params ); }; /** diff --git a/modules/controller/mw.echo.Controller.js b/modules/controller/mw.echo.Controller.js index 35d0a95..ceed5eb 100644 --- a/modules/controller/mw.echo.Controller.js +++ b/modules/controller/mw.echo.Controller.js @@ -24,6 +24,8 @@ * Fetch notifications from the local API and sort them by date. * This method ignores cross-wiki notifications and bundles. * + * @param {string} [readStatus] Notification read status to fetch. Can be 'read', + * 'unread' or 'all' * @param {boolean} [isForced] Force a renewed fetching promise. If set to false, the * model will request the stored/cached fetching promise from the API. A 'true' value * will force the API to re-request that information from the server and update the @@ -31,10 +33,10 @@ * @return {jQuery.Promise} A promise that resolves with an object where the keys are * days and the items are item IDs. */ - mw.echo.Controller.prototype.fetchLocalNotificationsByDate = function ( isForced ) { + mw.echo.Controller.prototype.fetchLocalNotificationsByDate = function ( readStatus, isForced ) { var controller = this; - return this.api.fetchNotifications( this.manager.getTypeString(), 'local', !!isForced ) + return this.api.fetchNotifications( this.manager.getTypeString(), 'local', !!isForced, readStatus ) .then( function ( data ) { var i, notifData, newNotifData, date, itemModel, echoMoment, symbolicName, dateItemIds = {}, diff --git a/modules/nojs/mw.echo.special.less b/modules/nojs/mw.echo.special.less index 7cd3227..b09255b 100644 --- a/modules/nojs/mw.echo.special.less +++ b/modules/nojs/mw.echo.special.less @@ -21,6 +21,10 @@ float: right; } +.mw-echo-special-sidebar { + float: left; +} + /* Special styles to use if we're converting subtitle links into header icons */ #firstHeading { .mw-echo-special-header-link { diff --git a/modules/special/ext.echo.special.js b/modules/special/ext.echo.special.js index 2762605..dabe8d8 100644 --- a/modules/special/ext.echo.special.js +++ b/modules/special/ext.echo.special.js @@ -13,7 +13,7 @@ }; $( document ).ready( function () { - var model, wrapperWidget, markAsReadButton, widget, + var model, wrapperWidget, markAsReadButton, readStatusButtons, maxNotificationCount = mw.config.get( 'wgEchoMaxNotificationCount' ), skin = mw.config.get( 'skin' ), $content = $( '#mw-content-text' ), @@ -26,24 +26,77 @@ { type: [ 'message' ] } - ); - widget = new mw.echo.ui.DatedNotificationsWidget( - controller, - modelManager, - { - $overlay: mw.echo.ui.$overlay - } - ); + ), + $sidebar = $( '<div>' ) + .addClass( 'mw-echo-special-sidebar' ), + widget = new mw.echo.ui.DatedNotificationsWidget( + controller, + modelManager, + { + $overlay: mw.echo.ui.$overlay + } + ), + fetchNotifications = function ( state ) { + state = state || 'all'; + + widget.pushPending(); + readStatusButtons.setDisabled( true ); + controller.fetchLocalNotificationsByDate( state, true ) + .always( function () { + readStatusButtons.setDisabled( false ); + widget.popPending(); + } ); + }; // Overlay $( 'body' ).append( mw.echo.ui.$overlay ); - $content.empty().append( widget.$element ); + readStatusButtons = new OO.ui.ButtonSelectWidget( { + items: [ + new OO.ui.ButtonOptionWidget( { + data: 'all', + label: 'All', + title: 'All' + } ), + new OO.ui.ButtonOptionWidget( { + data: 'read', + label: 'Read', + title: 'Read' + } ), + new OO.ui.ButtonOptionWidget( { + data: 'unread', + label: 'Unread', + title: 'Unread' + } ) + ] + } ); + readStatusButtons.on( 'choose', function ( item ) { + fetchNotifications( item.getData(), true ); + } ); - widget.pushPending(); - controller.fetchLocalNotificationsByDate() - .always( widget.popPending.bind( widget ) ); + $content.empty().append( + $( '<div>' ) + .css( 'display', 'table' ) + .append( + $( '<div>' ) + .css( 'display', 'table-row' ) + .append( + $sidebar + .css( { + display: 'table-cell', + paddingRight: '0.5em' + } ) + .append( + readStatusButtons.$element + ), + widget.$element + .css( 'display', 'table-cell' ) + ) + ) + ); + readStatusButtons.selectItemByData( 'all' ); + fetchNotifications( 'all', true ); -- To view, visit https://gerrit.wikimedia.org/r/288733 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7b47e76ae48eaf4732d99616baa3b4b1ee4ddff5 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