Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid lots of unnecessary callbacks being executed #4477

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<script lang="ts">
import type { ChatIdentifier, Level, OpenChat, UserLookup, UserSummary } from "openchat-client";
import { afterUpdate, getContext, onDestroy, onMount } from "svelte";
import { getContext, onDestroy, onMount } from "svelte";
import { _ } from "svelte-i18n";
import Markdown from "./Markdown.svelte";
import { interpolateLevel } from "../../utils/i18n";
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions frontend/app/src/components/home/ChatEventList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions frontend/app/src/components/home/ChatMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import { rtlStore } from "../../stores/rtl";
import { now } from "../../stores/time";
import {
afterUpdate,
createEventDispatcher,
getContext,
onDestroy,
Expand Down Expand Up @@ -138,12 +137,6 @@
$: messageContext = { chatId, threadRootMessageIndex };
$: tips = msg.tips ? Object.entries(msg.tips) : [];

afterUpdate(() => {
julianjelfs marked this conversation as resolved.
Show resolved Hide resolved
if (readByMe && observer && msgElement) {
observer.unobserve(msgElement);
}
});

onMount(() => {
if (!readByMe) {
tick().then(() => {
Expand Down
18 changes: 9 additions & 9 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1209,29 +1213,25 @@ export class OpenChat extends OpenChatAgentWorker {
});
}

followThread(
chatId: ChatIdentifier,
message: Message,
follow: boolean
): Promise<boolean> {
followThread(chatId: ChatIdentifier, message: Message, follow: boolean): Promise<boolean> {
// 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;
}
});
}
Expand Down
Loading