From 2eef226dbb70a6f24e3e296362dd5a24178faa02 Mon Sep 17 00:00:00 2001 From: Germain Date: Fri, 6 Jan 2023 10:23:07 +0000 Subject: [PATCH] undo changes to client --- src/client.ts | 4 ++-- src/models/thread.ts | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/client.ts b/src/client.ts index 096335d8253..ae42103f26e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -601,9 +601,9 @@ interface IJoinRequestBody { third_party_signed?: IThirdPartySigned; } -export interface ITagMetadata { +interface ITagMetadata { [key: string]: any; - order?: number; + order: number; } interface IMessagesResponse { diff --git a/src/models/thread.ts b/src/models/thread.ts index 8f5c9dc16a4..1eb4927fa9a 100644 --- a/src/models/thread.ts +++ b/src/models/thread.ts @@ -517,19 +517,19 @@ export class Thread extends ReadReceipt { const readUpToId = super.getEventReadUpTo(userId, ignoreSynthesized); - // Checking whether the unthreaded read receipt for that user is more recent - // than the read receipt inside that thread. - if (this.lastReply()) { - if (!this.room.unthreadedReceipts.has(userId)) { - return readUpToId; - } + const isLastTimelineEvent = readUpToId === this.timeline.at(-1)?.getId(); + const hasAnUnthreadedReceipt = this.room.unthreadedReceipts.has(userId); + if (isLastTimelineEvent && !hasAnUnthreadedReceipt) { + return readUpToId; + } - const unthreadedReceiptTs = this.room.unthreadedReceipts.get(userId)!.ts; - for (let i = this.timeline?.length - 1; i >= 0; --i) { - const ev = this.timeline[i]; - if (ev.getId() === readUpToId) return readUpToId; - if (ev.getTs() < unthreadedReceiptTs) return ev.getId() ?? readUpToId; - } + // Check whether the unthreaded receipt finds a more recent `readUpToId` + // If so, return that value. + const unthreadedReceiptTs = this.room.unthreadedReceipts.get(userId)!.ts; + for (let i = this.timeline?.length - 1; i >= 0; --i) { + const ev = this.timeline[i]; + if (ev.getId() === readUpToId) return readUpToId; + if (ev.getTs() < unthreadedReceiptTs) return ev.getId() ?? readUpToId; } return readUpToId;