Skip to content

Commit

Permalink
Add getLastUnthreadedReceiptFor utility to Thread delegating to the u…
Browse files Browse the repository at this point in the history
…nderlying Room (#3493)
  • Loading branch information
t3chguy authored Jun 21, 2023
1 parent 8b9672b commit 80fec81
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/models/event-timeline-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
*/
public insertEventIntoTimeline(event: MatrixEvent, timeline: EventTimeline, roomState: RoomState): void {
if (timeline.getTimelineSet() !== this) {
throw new Error(`EventTimelineSet.addEventToTimeline: Timeline=${timeline.toString()} does not belong " +
throw new Error(`EventTimelineSet.insertEventIntoTimeline: Timeline=${timeline.toString()} does not belong " +
"in timelineSet(threadId=${this.thread?.id})`);
}

Expand All @@ -793,7 +793,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
eventDebugString += `(belongs to thread=${event.threadRootId})`;
}
logger.warn(
`EventTimelineSet.addEventToTimeline: Ignoring ${eventDebugString} that does not belong ` +
`EventTimelineSet.insertEventIntoTimeline: Ignoring ${eventDebugString} that does not belong ` +
`in timeline=${timeline.toString()} timelineSet(threadId=${this.thread?.id})`,
);
return;
Expand Down
9 changes: 9 additions & 0 deletions src/models/read-receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,13 @@ export abstract class ReadReceipt<
// We don't know if the user has read it, so assume not.
return false;
}

/**
* Returns the most recent unthreaded receipt for a given user
* @param userId - the MxID of the User
* @returns an unthreaded Receipt. Can be undefined if receipts have been disabled
* or a user chooses to use private read receipts (or we have simply not received
* a receipt from this user yet).
*/
public abstract getLastUnthreadedReceiptFor(userId: string): Receipt | undefined;
}
13 changes: 12 additions & 1 deletion src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { RoomState } from "./room-state";
import { ServerControlledNamespacedValue } from "../NamespacedValue";
import { logger } from "../logger";
import { ReadReceipt } from "./read-receipt";
import { CachedReceiptStructure, ReceiptType } from "../@types/read_receipts";
import { CachedReceiptStructure, Receipt, ReceiptType } from "../@types/read_receipts";
import { Feature, ServerSupport } from "../feature";

export enum ThreadEvent {
Expand Down Expand Up @@ -711,6 +711,17 @@ export class Thread extends ReadReceipt<ThreadEmittedEvents, ThreadEventHandlerM
public setUnread(type: NotificationCountType, count: number): void {
return this.room.setThreadUnreadNotificationCount(this.id, type, count);
}

/**
* Returns the most recent unthreaded receipt for a given user
* @param userId - the MxID of the User
* @returns an unthreaded Receipt. Can be undefined if receipts have been disabled
* or a user chooses to use private read receipts (or we have simply not received
* a receipt from this user yet).
*/
public getLastUnthreadedReceiptFor(userId: string): Receipt | undefined {
return this.room.getLastUnthreadedReceiptFor(userId);
}
}

/**
Expand Down

0 comments on commit 80fec81

Please sign in to comment.