From 8c75b96696c512dcba9a2716ec27e1cec168ceac Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Wed, 31 Aug 2022 11:40:10 +0300 Subject: [PATCH] add config settings for typing notifications, message history and typing updates --- frontend/src/storage.js | 6 +++++- frontend/src/stores.js | 44 ++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/frontend/src/storage.js b/frontend/src/storage.js index e08f609..fe0c9f8 100644 --- a/frontend/src/storage.js +++ b/frontend/src/storage.js @@ -8,7 +8,11 @@ const defaults = { "log:Gateway": false, "log:Store": false, "ui:stateful:presistSelectedChannel": true, - "ui:showSidebarToggle": false + "ui:showSidebarToggle": false, + "ui:online:processRemoteTypingEvents": true, + "ui:online:processRemotePresenceEvents": true, + "ui:online:loadMessageHistory": true, + "ui:online:sendTypingUpdates": true }; const store = new Map(Object.entries(defaults)); const persistentProvider = localStorage; diff --git a/frontend/src/stores.js b/frontend/src/stores.js index 7e841b3..5984c77 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -229,7 +229,7 @@ class MessageStore extends Store { } async loadOlderMessages(beforeCommitToStore=null) { - if (this.channelId === -1) + if (!getItem("ui:online:loadMessageHistory") || this.channelId === -1) return; const oldestMessage = this.value[0]; @@ -331,17 +331,19 @@ class TypingStore extends Store { this.ownTimeout = null; this.ownNeedsUpdate = true; - gateway.subscribe(GatewayPayloadType.TypingStart, ({ user, channel, time }) => { - if (userInfoStore && user.id === userInfoStore.value.id) - return; - - this.startedTyping(user, channel.id, time); - }); - - // assume someone has stopped typing once they send a message - gateway.subscribe(GatewayPayloadType.MessageCreate, ({ author_id }) => { - this.stoppedTyping(author_id); - }); + if (getItem("ui:online:processRemoteTypingEvents")) { + gateway.subscribe(GatewayPayloadType.TypingStart, ({ user, channel, time }) => { + if (userInfoStore && user.id === userInfoStore.value.id) + return; + + this.startedTyping(user, channel.id, time); + }); + + // assume someone has stopped typing once they send a message + gateway.subscribe(GatewayPayloadType.MessageCreate, ({ author_id }) => { + this.stoppedTyping(author_id); + }); + } } stoppedTyping(id) { @@ -392,7 +394,7 @@ class TypingStore extends Store { } async didInputKey() { - if (!userInfoStore.value) + if (!userInfoStore.value || !getItem("ui:online:sendTypingUpdates")) return; this.startedTyping(userInfoStore.value, selectedChannel.value.id, 6500); @@ -407,13 +409,15 @@ class PresenceStore extends Store { constructor() { super([], "PresenceStore"); - gateway.subscribe(GatewayEventType.Ready, ({ presence }) => { - this.ingestPresenceUpdate(presence); - }); - - gateway.subscribe(GatewayEventType.PresenceUpdate, (data) => { - this.ingestPresenceUpdate(data); - }); + if (getItem("ui:online:processRemotePresenceEvents")) { + gateway.subscribe(GatewayEventType.Ready, ({ presence }) => { + this.ingestPresenceUpdate(presence); + }); + + gateway.subscribe(GatewayEventType.PresenceUpdate, (data) => { + this.ingestPresenceUpdate(data); + }); + } } entryIndexByUserId(userId) {