Legoktm has uploaded a new change for review.

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

Change subject: [WIP] Add markseen support to API action=echomarkread
......................................................................

[WIP] Add markseen support to API action=echomarkread

Bug: T110216
Change-Id: I85969c13df9eb1ca6c0d9a82c94d9d7b850f47e7
---
M includes/api/ApiEchoMarkRead.php
M modules/ooui/mw.echo.ui.NotificationBadgeButtonPopupWidget.js
M modules/ooui/mw.echo.ui.NotificationsWidget.js
3 files changed, 39 insertions(+), 14 deletions(-)


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

diff --git a/includes/api/ApiEchoMarkRead.php b/includes/api/ApiEchoMarkRead.php
index 13e069e..c253e37 100644
--- a/includes/api/ApiEchoMarkRead.php
+++ b/includes/api/ApiEchoMarkRead.php
@@ -32,6 +32,14 @@
                $result = array(
                        'result' => 'success'
                );
+
+               if ( $params['markseen'] ) {
+                       $seen = EchoSeenTime::newFromUser( $user );
+                       $ts = wfTimestamp( TS_MW );
+                       $seen->setTime( $ts );
+                       $result['seentime'] = $ts;
+               }
+
                $rawCount = 0;
                foreach ( EchoAttributeManager::$sections as $section ) {
                        $rawSectionCount = $notifUser->getNotificationCount( /* 
$tryCache = */true, DB_SLAVE, $section );
@@ -60,6 +68,10 @@
                                ApiBase::PARAM_TYPE => 
EchoAttributeManager::$sections,
                                ApiBase::PARAM_ISMULTI => true,
                        ),
+                       'markseen' => array(
+                               ApiBase::PARAM_TYPE => 'boolean',
+                               ApiBase::PARAM_DFLT => false,
+                       ),
                        'token' => array(
                                ApiBase::PARAM_REQUIRED => true,
                        ),
diff --git a/modules/ooui/mw.echo.ui.NotificationBadgeButtonPopupWidget.js 
b/modules/ooui/mw.echo.ui.NotificationBadgeButtonPopupWidget.js
index 7f6192e..0e3b0a8 100644
--- a/modules/ooui/mw.echo.ui.NotificationBadgeButtonPopupWidget.js
+++ b/modules/ooui/mw.echo.ui.NotificationBadgeButtonPopupWidget.js
@@ -201,13 +201,9 @@
 
                                        // Mark notifications as 'read' if 
markReadOnOpen is set to true
                                        if ( widget.markReadOnOpen ) {
-                                               return 
widget.notifsPopupWidget.markAllRead()
+                                               return 
widget.notifsPopupWidget.markAllRead( /* markSeen = */ true )
                                                        .then( 
widget.updateUnreadCount.bind( widget ) );
                                        }
-                               } )
-                               .then( function () {
-                                       // Update seen time
-                                       
widget.notifsPopupWidget.updateSeenTime();
                                } );
                        this.updated = true;
                } else {
diff --git a/modules/ooui/mw.echo.ui.NotificationsWidget.js 
b/modules/ooui/mw.echo.ui.NotificationsWidget.js
index 6835578..cabc6bd 100644
--- a/modules/ooui/mw.echo.ui.NotificationsWidget.js
+++ b/modules/ooui/mw.echo.ui.NotificationsWidget.js
@@ -266,10 +266,12 @@
        /**
         * Mark all notifications as read
         *
+        * @param {boolean} markSeen Update the markseen time too
+        *
         * @return {jQuery.Promise} Promise that is resolved with the number of
         * remaining unread notifications when all notifications are marked 
unread.
         */
-       mw.echo.ui.NotificationsWidget.prototype.markAllRead = function () {
+       mw.echo.ui.NotificationsWidget.prototype.markAllRead = function ( 
markSeen ) {
                var widget = this,
                        data = {
                                action: 'echomarkread',
@@ -277,12 +279,19 @@
                                sections: this.type
                        };
 
+               if ( markSeen ) {
+                       data.markseen = true;
+               }
+
                if ( !this.howManyUnread ) {
                        return $.Deferred().resolve( 0 ).promise();
                }
 
                return this.api.postWithToken( 'edit', data )
                        .then( function ( result ) {
+                               if ( markSeen ) {
+                                       widget.setSeenTime( 
result.query.echomarkread.seentime );
+                               }
                                return 
result.query.echomarkread[widget.type].rawcount || 0;
                        } )
                        .then( function ( readNotificationCount ) {
@@ -310,6 +319,21 @@
        };
 
        /**
+        * Set the new seen time
+        *
+        * @param {string} time
+        * @fires seen
+        */
+       mw.echo.ui.NotificationsWidget.prototype.setSeenTime = function ( time 
) {
+               // update wgEchoSeenTime value in JS (where it wouldn't
+               // otherwise propagate until page reload)
+               mw.config.set( 'wgEchoSeenTime', time );
+               this.seenTime = time;
+
+               this.emit( 'seen', this.seenTime );
+       };
+
+       /**
         * Update the seen timestamp
         *
         * @return {jQuery.Promise} A promise that resolves with the seen 
timestamp
@@ -321,14 +345,7 @@
                return this.api.postWithToken( 'edit', {
                        action: 'echomarkseen'
                } ).then( function ( data ) {
-                       var time = data.query.echomarkseen.timestamp;
-
-                       // update wgEchoSeenTime value in JS (where it wouldn't
-                       // otherwise propagate until page reload)
-                       mw.config.set( 'wgEchoSeenTime', time );
-                       widget.seenTime = time;
-
-                       widget.emit( 'seen', widget.seenTime );
+                       widget.setSeenTime( data.query.echomarkseen.timestamp );
 
                        return widget.seenTime;
                } );

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

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

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

Reply via email to