Browse Source

Adding configurable url history changing

Shaun Wu 4 years ago
parent
commit
1cb2b1f7a9

+ 1 - 0
CHANGES.md

@@ -7,6 +7,7 @@
 - #2348: `auto_join_room` not showing the room in `fullscreen` `view_mode`.
 - #2400: Fixes infinite loop bug when appending .png to allowed image urls
 - #2409: Integrate App Badging API for unread messages
+- #2464: New configuration setting [allow-url-history-change](https://conversejs.org/docs/html/configuration.html#allow-url-history-change)
 - Add support for XEP-0437 Room Activity Indicators see [muc-subscribe-to-rai](https://conversejs.org/docs/html/configuration.html#muc-subscribe-to-rai)
 - Bugfix: Use real JID in XEP-0372 references only when the MUC is non-anonymous
 - Bugfix: Connection protocol not updated based on XEP-0156 connection methods

+ 6 - 0
docs/source/configuration.rst

@@ -250,6 +250,12 @@ Support for `XEP-0077: In band registration <https://xmpp.org/extensions/xep-007
 
 Allow XMPP account registration showing the corresponding UI register form interface.
 
+allow_url_history_change
+------------------------
+
+* Default:  ``true``
+
+Allow Converse to change the browser url bar through the History API <https://developer.mozilla.org/en-US/docs/Web/API/History_API>.
 
 allow_user_trust_override
 -------------------------

+ 1 - 0
src/headless/shared/settings.js

@@ -15,6 +15,7 @@ let user_settings; // User settings, populated via api.users.settings
 // ----------------------------
 export const DEFAULT_SETTINGS = {
     allow_non_roster_messaging: false,
+    allow_url_history_change: true,
     assets_path: '/dist',
     authentication: 'login', // Available values are "login", "prebind", "anonymous" and "external".
     auto_login: false, // Currently only used in connection with anonymous login

+ 4 - 2
src/plugins/mam-views/utils.js

@@ -1,5 +1,5 @@
 import { fetchArchivedMessages } from '@converse/headless/plugins/mam/utils';
-import { _converse } from '@converse/headless/core';
+import { _converse, api } from '@converse/headless/core';
 
 export async function fetchMessagesOnScrollUp (view) {
     if (view.model.messages.length) {
@@ -15,7 +15,9 @@ export async function fetchMessagesOnScrollUp (view) {
                 await fetchArchivedMessages(view.model, { 'end': oldest_message.get('time') });
             }
             view.clearSpinner();
-            _converse.router.history.navigate(`#${oldest_message.get('msgid')}`);
+            if (api.settings.get('allow_url_history_change')) {
+                _converse.router.history.navigate(`#${oldest_message.get('msgid')}`);
+            }
         }
     }
 }

+ 5 - 3
src/plugins/muc-views/chatarea.js

@@ -120,9 +120,11 @@ export default class MUCChatArea extends CustomElement {
     onScrolledDown () {
         if (!this.model.isHidden()) {
             this.model.clearUnreadMsgCounter();
-            // Clear location hash if set to one of the messages in our history
-            const hash = window.location.hash;
-            hash && this.model.messages.get(hash.slice(1)) && _converse.router.history.navigate();
+            if (api.settings.get('allow_url_history_change')) {
+                // Clear location hash if set to one of the messages in our history
+                const hash = window.location.hash;
+                hash && this.model.messages.get(hash.slice(1)) && _converse.router.history.navigate();
+            }
         }
         /**
          * Triggered once the chat's message area has been scrolled down to the bottom.

+ 5 - 3
src/shared/chat/baseview.js

@@ -209,9 +209,11 @@ export default class BaseChatView extends ElementView {
         this.hideNewMessagesIndicator();
         if (!this.model.isHidden()) {
             this.model.clearUnreadMsgCounter();
-            // Clear location hash if set to one of the messages in our history
-            const hash = window.location.hash;
-            hash && this.model.messages.get(hash.slice(1)) && _converse.router.history.navigate();
+            if (api.settings.get('allow_url_history_change')) {
+                // Clear location hash if set to one of the messages in our history
+                const hash = window.location.hash;
+                hash && this.model.messages.get(hash.slice(1)) && _converse.router.history.navigate();
+            }
         }
         /**
          * Triggered once the chat's message area has been scrolled down to the bottom.