Mooeypoo has uploaded a new change for review.

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

Change subject: Separate 'seen time' for alerts and messages
......................................................................

Separate 'seen time' for alerts and messages

Bug: T111285
Change-Id: I277f94ae705d3323ac8612111d7fd704b36793cb
---
M Hooks.php
M i18n/en.json
M includes/SeenTime.php
M includes/api/ApiEchoMarkSeen.php
M modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
M modules/viewmodel/mw.echo.dm.NotificationsModel.js
6 files changed, 44 insertions(+), 24 deletions(-)


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

diff --git a/Hooks.php b/Hooks.php
index 9fe91b2..74ec0e2 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -638,8 +638,13 @@
                $msgNotificationTimestamp = 
$notifUser->getLastUnreadMessageTime();
                $alertNotificationTimestamp = 
$notifUser->getLastUnreadAlertTime();
 
-               $seenTime = EchoSeenTime::newFromUser( $user )->getTime();
-               $sk->getOutput()->addJsConfigVars( 'wgEchoSeenTime', $seenTime 
);
+               $seenAlertTime = EchoSeenTime::newFromUser( $user )->getTime( 
'alert' );
+               $seenMsgTime = EchoSeenTime::newFromUser( $user )->getTime( 
'message' );
+
+               $sk->getOutput()->addJsConfigVars( 'wgEchoSeenTime', array(
+                       'alert' => $seenAlertTime,
+                       'message' => $seenMsgTime
+               ) );
 
                $msgText = EchoNotificationController::formatNotificationCount( 
$msgCount );
                $alertText = 
EchoNotificationController::formatNotificationCount( $alertCount );
@@ -652,7 +657,7 @@
                if (
                        $msgCount != 0 && // no unread notifications
                        $msgNotificationTimestamp !== false && // should 
already always be false if count === 0
-                       ( $seenTime === null || $seenTime < 
$msgNotificationTimestamp->getTimestamp( TS_MW ) ) // there are no unseen 
notifications
+                       ( $seenMsgTime === null || $seenMsgTime < 
$msgNotificationTimestamp->getTimestamp( TS_MW ) ) // there are no unseen 
notifications
                ) {
                        $msgLinkClasses[] = 'mw-echo-unseen-notifications';
                }
@@ -661,7 +666,7 @@
                if (
                        $alertCount != 0 && // no unread notifications
                        $alertNotificationTimestamp !== false && // should 
already always be false if count === 0
-                       ( $seenTime === null || $seenTime < 
$alertNotificationTimestamp->getTimestamp( TS_MW ) ) // all notifications have 
already been seen
+                       ( $seenAlertTime === null || $seenAlertTime < 
$alertNotificationTimestamp->getTimestamp( TS_MW ) ) // all notifications have 
already been seen
                ) {
                        $alertLinkClasses[] = 'mw-echo-unseen-notifications';
                        $alertIcon = "bellOn";
diff --git a/i18n/en.json b/i18n/en.json
index 52e96f6..0ee1d44 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -121,7 +121,7 @@
        "apihelp-echomarkread-example-1": "Mark notification 8 as read",
        "apihelp-echomarkread-example-2": "Mark all notifications as read",
        "apihelp-echomarkseen-description": "Mark notifications as seen for the 
current user.",
-       "apihelp-echomarkseen-example-1": "Mark notifications as seen",
+       "apihelp-echomarkseen-example-1": "Mark notifications of all types as 
seen.",
        "apihelp-query+notifications-description": "Get notifications waiting 
for the current user.",
        "apihelp-query+notifications-param-prop": "Details to request.",
        "apihelp-query+notifications-param-sections": "The notification 
sections to query.",
diff --git a/includes/SeenTime.php b/includes/SeenTime.php
index b157a1c..2b910a3 100644
--- a/includes/SeenTime.php
+++ b/includes/SeenTime.php
@@ -12,11 +12,6 @@
        private $user;
 
        /**
-        * @var string
-        */
-       private $key;
-
-       /**
         * @var BagOStuff
         */
        private $cache;
@@ -26,7 +21,6 @@
         */
        private function __construct( User $user ) {
                $this->user = $user;
-               $this->key = wfMemcKey( 'echo', 'seen', 'time', $user->getId() 
);
                $this->cache = ObjectCache::getInstance( 'db-replicated' );
        }
 
@@ -42,9 +36,16 @@
         * @param int $flags BagOStuff::READ_LATEST to use the master
         * @return string|bool false if no stored time
         */
-       public function getTime( $flags = 0 ) {
+       public function getTime( $type = 'all', $flags = 0 ) {
+               if ( $type === 'all' ) {
+                       $alertSeen = $this->getTime( 'alert' );
+                       $msgSeen = $this->getTime( 'message' );
+                       return max( $alertSeen, $msgSeen );
+               }
+
+               $key = wfMemcKey( 'echo', 'seen', $type, 'time', 
$this->user->getId() );
                $cas = 0; // Unused, but we have to pass something by reference
-               $data = $this->cache->get( $this->key, $cas, $flags );
+               $data = $this->cache->get( $key, $cas, $flags );
                if ( $data === false ) {
                        // Check if the user still has it set in their 
preferences
                        $data = $this->user->getOption( 'echo-seen-time', false 
);
@@ -53,7 +54,16 @@
                return $data;
        }
 
-       public function setTime( $time ) {
-               return $this->cache->set( $this->key, $time );
+       public function setTime( $time, $type = 'all' ) {
+               if ( $type === 'all' ) {
+                       $key = wfMemcKey( 'echo', 'seen', 'alert', 'time', 
$this->user->getId() );
+                       $this->cache->set( $key, $time );
+
+                       $key = wfMemcKey( 'echo', 'seen', 'message', 'time', 
$this->user->getId() );
+                       $this->cache->set( $key, $time );
+               } else {
+                       $key = wfMemcKey( 'echo', 'seen', $type, 'time', 
$this->user->getId() );
+                       return $this->cache->set( $key, $time );
+               }
        }
 }
diff --git a/includes/api/ApiEchoMarkSeen.php b/includes/api/ApiEchoMarkSeen.php
index a8851fb..ce4e442 100755
--- a/includes/api/ApiEchoMarkSeen.php
+++ b/includes/api/ApiEchoMarkSeen.php
@@ -11,9 +11,10 @@
                        $this->dieUsage( 'Login is required', 'login-required' 
);
                }
 
+               $params = $this->extractRequestParams();
                $timestamp = wfTimestamp( TS_MW );
                $seenTime = EchoSeenTime::newFromUser( $user );
-               $seenTime->setTime( $timestamp );
+               $seenTime->setTime( $timestamp, $params['type'] );
 
                $this->getResult()->addValue( 'query', $this->getModuleName(), 
array(
                        'result' => 'success',
@@ -26,6 +27,10 @@
                        'token' => array(
                                ApiBase::PARAM_REQUIRED => true,
                        ),
+                       'type' => array(
+                               ApiBase::PARAM_REQUIRED => true,
+                               ApiBase::PARAM_TYPE => array( 'alert', 
'message', 'all' ),
+                       )
                );
        }
 
@@ -75,7 +80,7 @@
         */
        protected function getExamplesMessages() {
                return array(
-                       'action=echomarkseen' => 
'apihelp-echomarkseen-example-1',
+                       'action=echomarkseen&type=all' => 
'apihelp-echomarkseen-example-1',
                );
        }
 
diff --git a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js 
b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
index a464175..ab460f2 100644
--- a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
+++ b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
@@ -148,7 +148,7 @@
        mw.echo.ui.NotificationBadgeWidget.prototype.updateBadge = function () {
                var unseenCount = this.notificationsModel.getUnseenCount(),
                        unreadCount = this.notificationsModel.getUnreadCount();
-
+debugger;
                // Update numbers and seen/unseen state
                this.setFlags( { unseen: !!unseenCount } );
                this.setLabel( String( unreadCount ) );
diff --git a/modules/viewmodel/mw.echo.dm.NotificationsModel.js 
b/modules/viewmodel/mw.echo.dm.NotificationsModel.js
index f7c8419..1d511ea 100644
--- a/modules/viewmodel/mw.echo.dm.NotificationsModel.js
+++ b/modules/viewmodel/mw.echo.dm.NotificationsModel.js
@@ -152,7 +152,7 @@
         * @param {string} Mediawiki seen timestamp in Mediawiki timestamp 
format
         */
        mw.echo.dm.NotificationsModel.prototype.setSeenTime = function ( time ) 
{
-               this.seenTime = time;
+               this.seenTime[this.type] = time;
        };
 
        /**
@@ -161,7 +161,7 @@
         * @return {string} Mediawiki seen timestamp in Mediawiki timestamp 
format
         */
        mw.echo.dm.NotificationsModel.prototype.getSeenTime = function () {
-               return this.seenTime;
+               return this.seenTime[this.type];
        };
 
        /**
@@ -181,9 +181,10 @@
         */
        mw.echo.dm.NotificationsModel.prototype.updateSeenTime = function () {
                var model = this;
-
+debugger;
                return this.api.postWithToken( 'edit', {
-                       action: 'echomarkseen'
+                       action: 'echomarkseen',
+                       type: this.type
                } ).then( function ( data ) {
                        var i, len,
                                items = model.unseenNotifications.getItems(),
@@ -191,7 +192,6 @@
 
                        // update wgEchoSeenTime value in JS (where it wouldn't
                        // otherwise propagate until page reload)
-                       mw.config.set( 'wgEchoSeenTime', time );
                        model.setSeenTime( time );
 
                        // Update the notifications seen status
@@ -200,7 +200,7 @@
                        }
                        model.unseenNotifications.clearItems();
 
-                       model.emit( 'updateSeenTime' );
+                       model.emit( 'updateSeenTime', model.getSeenTime() );
                } );
        };
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I277f94ae705d3323ac8612111d7fd704b36793cb
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