From e0f28cfe86ab6453ef95fc2fd0440423125e0505 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 6 Dec 2021 14:32:00 -0500 Subject: [PATCH] chat: Move cookie pref handling to chat init in `chat.js` It's unclear why this logic was previously triggered by connection state changes, but it doesn't make sense for it to be there. --- CHANGELOG.md | 4 ++++ src/static/js/chat.js | 8 ++++++++ src/static/js/pad.js | 21 --------------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c48c2da20..b578adac7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,6 +91,10 @@ instead. * `padUpdate`: The `author` context property is deprecated; use the new `authorId` context property instead. Also, the hook now runs asynchronously. +* Chat API deprecations and removals (no replacements planned): + * Client-side: + * The `pad.determineChatVisibility()` method was removed. + * The `pad.determineChatAndUsersVisibility()` method was removed. * Returning `true` from a `handleMessageSecurity` hook function is deprecated; return `'permitOnce'` instead. * Changes to the `src/static/js/Changeset.js` library: diff --git a/src/static/js/chat.js b/src/static/js/chat.js index fa3c57436..d095522b1 100755 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -293,6 +293,14 @@ exports.chat = (() => { if (settings.hideChat) this.hide(); if (searchParams.get('alwaysShowChat') === 'true' && !settings.hideChat) this.stickToScreen(); if (searchParams.get('chatAndUsers') === 'true') this.chatAndUsers(); + + const chatVisCookie = !!padcookie.getPref('chatAlwaysVisible'); + if (chatVisCookie) this.stickToScreen(true); + $('#options-stickychat').prop('checked', chatVisCookie); + + const chatAUVisCookie = !!padcookie.getPref('chatAndUsersVisible'); + if (chatAUVisCookie) this.chatAndUsers(true); + $('#options-chatandusers').prop('checked', chatAUVisCookie); }, }; })(); diff --git a/src/static/js/pad.js b/src/static/js/pad.js index 8efab08ce..c99e4fdef 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -31,7 +31,6 @@ require('./vendors/farbtastic'); require('./vendors/gritter'); const Cookies = require('./pad_utils').Cookies; -const chat = require('./chat').chat; const getCollabClient = require('./collab_client').getCollabClient; const padconnectionstatus = require('./pad_connectionstatus').padconnectionstatus; const padcookie = require('./pad_cookie').padcookie; @@ -585,31 +584,11 @@ const pad = { } }, handleIsFullyConnected: (isConnected, isInitialConnect) => { - pad.determineChatVisibility(isConnected && !isInitialConnect); - pad.determineChatAndUsersVisibility(isConnected && !isInitialConnect); pad.determineAuthorshipColorsVisibility(); setTimeout(() => { padeditbar.toggleDropDown('none'); }, 1000); }, - determineChatVisibility: (asNowConnectedFeedback) => { - const chatVisCookie = padcookie.getPref('chatAlwaysVisible'); - if (chatVisCookie) { // if the cookie is set for chat always visible - chat.stickToScreen(true); // stick it to the screen - $('#options-stickychat').prop('checked', true); // set the checkbox to on - } else { - $('#options-stickychat').prop('checked', false); // set the checkbox for off - } - }, - determineChatAndUsersVisibility: (asNowConnectedFeedback) => { - const chatAUVisCookie = padcookie.getPref('chatAndUsersVisible'); - if (chatAUVisCookie) { // if the cookie is set for chat always visible - chat.chatAndUsers(true); // stick it to the screen - $('#options-chatandusers').prop('checked', true); // set the checkbox to on - } else { - $('#options-chatandusers').prop('checked', false); // set the checkbox for off - } - }, determineAuthorshipColorsVisibility: () => { const authColCookie = padcookie.getPref('showAuthorshipColors'); if (authColCookie) {