From f7cf76d7f816f92fcc7b885902ec1c15996a2971 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Mon, 2 Oct 2023 20:43:11 +0100 Subject: [PATCH 1/2] Avoid lots of unnecessary callbacks being executed --- .../home/AggregateCommonEvents.svelte | 6 ------ .../src/components/home/ChatEventList.svelte | 1 + .../app/src/components/home/ChatMessage.svelte | 6 ------ frontend/openchat-client/src/openchat.ts | 18 +++++++++--------- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/frontend/app/src/components/home/AggregateCommonEvents.svelte b/frontend/app/src/components/home/AggregateCommonEvents.svelte index e256a81c8e..31408a568d 100644 --- a/frontend/app/src/components/home/AggregateCommonEvents.svelte +++ b/frontend/app/src/components/home/AggregateCommonEvents.svelte @@ -28,12 +28,6 @@ : $_("nMessagesDeleted", { values: { number: messagesDeleted.length } }) : undefined; - afterUpdate(() => { - if (readByMe && observer && deletedMessagesElement) { - observer.unobserve(deletedMessagesElement); - } - }); - onMount(() => { if (!readByMe && deletedMessagesElement) { observer?.observe(deletedMessagesElement); diff --git a/frontend/app/src/components/home/ChatEventList.svelte b/frontend/app/src/components/home/ChatEventList.svelte index 1965a138ba..6c4659c363 100644 --- a/frontend/app/src/components/home/ChatEventList.svelte +++ b/frontend/app/src/components/home/ChatEventList.svelte @@ -184,6 +184,7 @@ const timer = window.setTimeout(() => { if (messageContextsEqual(context, messageContext)) { client.markMessageRead(messageContext, idx, id); + messageObserver.unobserve(entry.target); } delete messageReadTimers[idx]; }, MESSAGE_READ_THRESHOLD); diff --git a/frontend/app/src/components/home/ChatMessage.svelte b/frontend/app/src/components/home/ChatMessage.svelte index 12aad6bafe..4ca89bf754 100644 --- a/frontend/app/src/components/home/ChatMessage.svelte +++ b/frontend/app/src/components/home/ChatMessage.svelte @@ -139,12 +139,6 @@ $: lastCryptoSent = client.lastCryptoSent; $: tips = msg.tips ? Object.entries(msg.tips) : []; - afterUpdate(() => { - if (readByMe && observer && msgElement) { - observer.unobserve(msgElement); - } - }); - onMount(() => { if (!readByMe) { tick().then(() => { diff --git a/frontend/openchat-client/src/openchat.ts b/frontend/openchat-client/src/openchat.ts index 2dcdc0ffea..c8626db83f 100644 --- a/frontend/openchat-client/src/openchat.ts +++ b/frontend/openchat-client/src/openchat.ts @@ -782,6 +782,10 @@ export class OpenChat extends OpenChatAgentWorker { messageIndex: number, messageId: bigint | undefined, ): void { + if (this.messagesRead.isRead(context, messageIndex, messageId)) { + return; + } + this.messagesRead.markMessageRead(context, messageIndex, messageId); const selectedChat = this._liveState.selectedChat; @@ -1209,29 +1213,25 @@ export class OpenChat extends OpenChatAgentWorker { }); } - followThread( - chatId: ChatIdentifier, - message: Message, - follow: boolean - ): Promise { + followThread(chatId: ChatIdentifier, message: Message, follow: boolean): Promise { // Assume it will succeed localMessageUpdates.markThreadSummaryUpdated(message.messageId, { - followedByMe: follow + followedByMe: follow, }); return this.sendRequest({ kind: "followThread", chatId, threadRootMessageIndex: message.messageIndex, - follow + follow, }).then((resp) => { if (resp === "failed") { localMessageUpdates.markThreadSummaryUpdated(message.messageId, { - followedByMe: !follow + followedByMe: !follow, }); return false; } else { - return true + return true; } }); } From acc8baae39a11d691577d1366ab3b2b882c089f2 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Mon, 2 Oct 2023 20:48:41 +0100 Subject: [PATCH 2/2] Remove unused imports --- frontend/app/src/components/home/AggregateCommonEvents.svelte | 2 +- frontend/app/src/components/home/ChatMessage.svelte | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/app/src/components/home/AggregateCommonEvents.svelte b/frontend/app/src/components/home/AggregateCommonEvents.svelte index 31408a568d..f9705a57ba 100644 --- a/frontend/app/src/components/home/AggregateCommonEvents.svelte +++ b/frontend/app/src/components/home/AggregateCommonEvents.svelte @@ -2,7 +2,7 @@