2
0
Эх сурвалжийг харах

Fixes #1058 Send inactive CSN when user switches tab

JC Brand 6 жил өмнө
parent
commit
a8ef1d2904

+ 1 - 0
CHANGES.md

@@ -7,6 +7,7 @@
 - Don't show duplicate notification messages
 - Don't show duplicate notification messages
 - New config setting [show_images_inline](https://conversejs.org/docs/html/configuration.html#show-images-inline)
 - New config setting [show_images_inline](https://conversejs.org/docs/html/configuration.html#show-images-inline)
 - #537 Render `xmpp:` URI as link
 - #537 Render `xmpp:` URI as link
+- #1058 Send an inactive chat state notification when the user switches to another tab 
 - #1062 Collapse multiple join/leave messages into one
 - #1062 Collapse multiple join/leave messages into one
 - #1063 URLs in the topic / subject are not clickable
 - #1063 URLs in the topic / subject are not clickable
 - #1140 Add support for destroyed chatrooms
 - #1140 Add support for destroyed chatrooms

+ 20 - 3
dist/converse.js

@@ -61157,7 +61157,11 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
 
 
       function onWindowStateChanged(data) {
       function onWindowStateChanged(data) {
         if (_converse.chatboxviews) {
         if (_converse.chatboxviews) {
-          _converse.chatboxviews.each(view => view.onWindowStateChanged(data.state));
+          _converse.chatboxviews.each(view => {
+            if (view.model.get('id') !== 'controlbox') {
+              view.onWindowStateChanged(data.state);
+            }
+          });
         }
         }
       }
       }
 
 
@@ -62382,8 +62386,21 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
         },
         },
 
 
         onWindowStateChanged(state) {
         onWindowStateChanged(state) {
-          if (this.model.get('num_unread', 0) && !this.model.isHidden()) {
-            this.model.clearUnreadMsgCounter();
+          if (state === 'visible') {
+            if (!this.model.isHidden()) {
+              this.setChatState(_converse.ACTIVE);
+
+              if (this.model.get('num_unread', 0)) {
+                this.model.clearUnreadMsgCounter();
+              }
+            }
+          } else if (state === 'hidden') {
+            this.setChatState(_converse.INACTIVE, {
+              'silent': true
+            });
+            this.model.sendChatState();
+
+            _converse.connection.flush();
           }
           }
         }
         }
 
 

+ 16 - 3
src/converse-chatview.js

@@ -91,7 +91,11 @@
 
 
             function onWindowStateChanged (data) {
             function onWindowStateChanged (data) {
                 if (_converse.chatboxviews) {
                 if (_converse.chatboxviews) {
-                    _converse.chatboxviews.each(view => view.onWindowStateChanged(data.state));
+                    _converse.chatboxviews.each(view => {
+                        if (view.model.get('id') !== 'controlbox') {
+                            view.onWindowStateChanged(data.state);
+                        }
+                    });
                 }
                 }
             }
             }
             _converse.api.listen.on('windowStateChanged', onWindowStateChanged);
             _converse.api.listen.on('windowStateChanged', onWindowStateChanged);
@@ -1266,8 +1270,17 @@
                 },
                 },
 
 
                 onWindowStateChanged (state) {
                 onWindowStateChanged (state) {
-                    if (this.model.get('num_unread', 0) && !this.model.isHidden()) {
-                        this.model.clearUnreadMsgCounter();
+                    if (state === 'visible') {
+                        if (!this.model.isHidden()) {
+                            this.setChatState(_converse.ACTIVE);
+                            if (this.model.get('num_unread', 0)) {
+                                this.model.clearUnreadMsgCounter();
+                            }
+                        }
+                    } else if (state === 'hidden') {
+                        this.setChatState(_converse.INACTIVE, {'silent': true});
+                        this.model.sendChatState();
+                        _converse.connection.flush();
                     }
                     }
                 }
                 }
             });
             });

+ 2 - 2
src/converse-singleton.js

@@ -55,8 +55,8 @@
                     }
                     }
                     if (_converse.isSingleton()) {
                     if (_converse.isSingleton()) {
                         const any_chats_visible = _converse.chatboxes
                         const any_chats_visible = _converse.chatboxes
-                            .filter((cb) => cb.get('id') != 'controlbox')
-                            .filter((cb) => !cb.get('hidden')).length > 0;
+                            .filter(cb => cb.get('id') != 'controlbox')
+                            .filter(cb => !cb.get('hidden')).length > 0;
 
 
                         if (any_chats_visible) {
                         if (any_chats_visible) {
                             return !chatbox.get('hidden');
                             return !chatbox.get('hidden');