Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/239514

Change subject: Update the API when a single notification is marked as read
......................................................................

Update the API when a single notification is marked as read

The status changed internally but was never passed to the API.
This commit fixes that mishap.

Bug: T112826
Change-Id: I1a6d2a871eae837860eb1f21df28134d5e747cd7
---
M modules/viewmodel/mw.echo.dm.NotificationsModel.js
1 file changed, 26 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/14/239514/1

diff --git a/modules/viewmodel/mw.echo.dm.NotificationsModel.js 
b/modules/viewmodel/mw.echo.dm.NotificationsModel.js
index 2b6b5a4..3fd1ee4 100644
--- a/modules/viewmodel/mw.echo.dm.NotificationsModel.js
+++ b/modules/viewmodel/mw.echo.dm.NotificationsModel.js
@@ -110,6 +110,7 @@
 
                if ( unreadItem ) {
                        if ( isRead ) {
+                               this.markItemReadInApi( id );
                                this.unreadNotifications.removeItems( [ 
unreadItem ] );
                        } else {
                                this.unreadNotifications.addItems( [ unreadItem 
] );
@@ -256,6 +257,31 @@
        };
 
        /**
+        * Update the read status of a notification item in the API
+        *
+        * @param {string} itemId Item id
+        * @return {jQuery.Promise} A promise that resolves when the 
notifications
+        * were marked as read.
+        */
+       mw.echo.dm.NotificationsModel.prototype.markItemReadInApi = function ( 
itemId ) {
+               var model = this,
+                       data = {
+                               action: 'echomarkread',
+                               uselang: this.userLang,
+                               list: itemId
+                       };
+
+               if ( !this.unreadNotifications.getItemCount() ) {
+                       return $.Deferred().resolve( 0 ).promise();
+               }
+
+               return this.api.postWithToken( 'edit', data )
+                       .then( function ( result ) {
+                               return 
result.query.echomarkread[model.type].rawcount || 0;
+                       } );
+       };
+
+       /**
         * Fetch notifications from the API and update the notifications list.
         *
         * @param {jQuery.Promise} An existing promise querying the API for 
notifications.

-- 
To view, visit https://gerrit.wikimedia.org/r/239514
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a6d2a871eae837860eb1f21df28134d5e747cd7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to