From a1388b7876fa2a5f9fb6e169320ea95600d1396a Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 4 Dec 2021 19:30:31 -0500 Subject: [PATCH] chat: Move chat-specific option processing to `chat.js` --- src/static/js/chat.js | 12 ++++++++++++ src/static/js/pad.js | 24 ------------------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/static/js/chat.js b/src/static/js/chat.js index 164b5da98..3d8ec405c 100755 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -292,6 +292,18 @@ exports.chat = (() => { pad.collabClient.sendMessage({type: 'GET_CHAT_MESSAGES', start, end}); this.historyPointer = start; }); + + const {searchParams} = new URL(window.location.href); + const {showChat = true, alwaysShowChat = false, chatAndUsers = false} = clientVars.padOptions; + const settings = this._pad.settings; + settings.hideChat = showChat.toString() === 'false'; + if (settings.hideChat) this.hide(); + if (alwaysShowChat.toString() === 'true' && !settings.hideChat) this.stickToScreen(); + if (chatAndUsers.toString() === 'true') this.chatAndUsers(); + settings.hideChat = searchParams.get('showChat') === 'false'; + if (settings.hideChat) this.hide(); + if (searchParams.get('alwaysShowChat') === 'true' && !settings.hideChat) this.stickToScreen(); + if (searchParams.get('chatAndUsers') === 'true') this.chatAndUsers(); }, }; })(); diff --git a/src/static/js/pad.js b/src/static/js/pad.js index 0d619b6f1..b0c63aeac 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -70,16 +70,6 @@ const getParameters = [ $('#editbar').css('display', 'flex'); }, }, - { - name: 'showChat', - checkVal: null, - callback: (val) => { - if (val === 'false') { - settings.hideChat = true; - chat.hide(); - } - }, - }, { name: 'showLineNumbers', checkVal: 'false', @@ -117,20 +107,6 @@ const getParameters = [ settings.rtlIsTrue = true; }, }, - { - name: 'alwaysShowChat', - checkVal: 'true', - callback: (val) => { - if (!settings.hideChat) chat.stickToScreen(); - }, - }, - { - name: 'chatAndUsers', - checkVal: 'true', - callback: (val) => { - chat.chatAndUsers(); - }, - }, { name: 'lang', checkVal: null,