Skip to content

Commit

Permalink
Merge branch 'master' into refund-prize
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Oct 2, 2023
2 parents 28e891a + d904e43 commit 4b51928
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/ProposalGroupFilters.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
export let selectedChat: ChatSummary;
const OC_PROPOSALS_NAME = "OpenChat Proposals";
const OC_GOVERNANCE_CANISTER_ID = "2jvtu-yqaaa-aaaaq-aaama-cai";
type SectionLabels = Record<ProposalActionCategory, string>;
Expand All @@ -38,7 +38,7 @@
$: topics = [...$proposalTopicsStore];
$: groupTopics =
selectedChat.kind !== "direct_chat" &&
selectedChat.name === OC_PROPOSALS_NAME;
selectedChat.subtype?.governanceCanisterId === OC_GOVERNANCE_CANISTER_ID;
$: grouped = [
...client.groupBy(topics, ([id, _]) => {
Expand Down
8 changes: 6 additions & 2 deletions frontend/app/src/components/home/thread/Thread.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
$: readonly = client.isChatReadOnly(chat.id);
$: thread = rootEvent.event.thread;
$: loading = !initialised && $threadEvents.length === 0 && thread !== undefined;
$: isFollowedByMe = thread !== undefined && (thread.followedByMe || thread.participantIds.has(user.userId));
function createTestMessages(ev: CustomEvent<number>): void {
if (process.env.NODE_ENV === "production") return;
Expand Down Expand Up @@ -271,8 +272,11 @@
me={evt.event.sender === user.userId}
confirmed={isConfirmed($unconfirmed, evt)}
failed={isFailed($failedMessagesStore, evt)}
readByMe={evt.event.messageId === rootEvent.event.messageId ||
isReadByMe($messagesRead, evt)}
readByMe={
evt.event.messageId === rootEvent.event.messageId ||
!isFollowedByMe ||
isReadByMe($messagesRead, evt)
}
readByThem
observer={messageObserver}
focused={evt.event.kind === "message" &&
Expand Down
19 changes: 0 additions & 19 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2174,15 +2174,6 @@ export class OpenChat extends OpenChatAgentWorker {
this.config.meteredApiKey,
);

const isFollowedByMe =
this._liveState.threadsFollowedByMe.get(chat.id)?.has(threadRootMessageIndex) ??
false;
if (isFollowedByMe) {
const lastLoadedMessageIdx = this.lastMessageIndex(this._liveState.threadEvents);
if (lastLoadedMessageIdx !== undefined) {
this.markThreadRead(chat.id, threadRootMessageIndex, lastLoadedMessageIdx);
}
}
if (ascending) {
this.dispatchEvent(new LoadedNewThreadMessages());
} else {
Expand Down Expand Up @@ -2217,16 +2208,6 @@ export class OpenChat extends OpenChatAgentWorker {
return [resp.events, userIds];
}

private lastMessageIndex(events: EventWrapper<ChatEvent>[]): number | undefined {
for (let i = events.length - 1; i >= 0; i--) {
const evt = events[i].event;
if (evt.kind === "message") {
return evt.messageIndex;
}
}
return undefined;
}

removeChat(chatId: ChatIdentifier): void {
if (this._liveState.uninitializedDirectChats.has(chatId)) {
removeUninitializedDirectChat(chatId);
Expand Down
7 changes: 5 additions & 2 deletions frontend/openchat-client/src/stores/markRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export class MessagesRead {
}

updateThread(rootIndex: number, readUpTo: number): void {
this.threads[rootIndex] = readUpTo;
const current = this.threads[rootIndex];
if (current === undefined || current < readUpTo) {
this.threads[rootIndex] = readUpTo;
}
}

setThreads(threads: ThreadRead[]): void {
Expand Down Expand Up @@ -378,7 +381,7 @@ export class MessageReadTracker {
return this.waiting.get(context)?.has(messageId) ?? false;
} else if (context.threadRootMessageIndex !== undefined) {
const serverState = this.serverState.get(context.chatId);
if ((serverState?.threads[context.threadRootMessageIndex] ?? -1) > messageIndex)
if ((serverState?.threads[context.threadRootMessageIndex] ?? -1) >= messageIndex)
return true;
const localState = this.state.get(context.chatId);
if ((localState?.threads[context.threadRootMessageIndex] ?? -1) >= messageIndex)
Expand Down

0 comments on commit 4b51928

Please sign in to comment.