fix: use separate cursors for owner and reviewer in paired rooms
Root cause: owner and reviewer shared the same message cursor. When the owner's turn completed, the cursor advanced past the owner's message. The reviewer's turn then only saw messages after that cursor, missing the owner's response entirely. Now paired rooms use role-aware cursor keys (chatJid for owner, chatJid:reviewer for reviewer). Each role advances only its own cursor, so the reviewer always sees the owner's latest messages and vice versa.
This commit is contained in:
@@ -16,11 +16,14 @@ export function advanceLastAgentCursor(
|
||||
saveState: () => void,
|
||||
chatJid: string,
|
||||
cursorOrTimestamp: string | number,
|
||||
/** Override cursor key (e.g. `${chatJid}:reviewer` for paired rooms). */
|
||||
cursorKey?: string,
|
||||
): void {
|
||||
const key = cursorKey ?? chatJid;
|
||||
if (typeof cursorOrTimestamp === 'number') {
|
||||
lastAgentTimestamps[chatJid] = String(cursorOrTimestamp);
|
||||
lastAgentTimestamps[key] = String(cursorOrTimestamp);
|
||||
} else {
|
||||
lastAgentTimestamps[chatJid] = normalizeStoredSeqCursor(
|
||||
lastAgentTimestamps[key] = normalizeStoredSeqCursor(
|
||||
cursorOrTimestamp,
|
||||
chatJid,
|
||||
);
|
||||
@@ -28,6 +31,14 @@ export function advanceLastAgentCursor(
|
||||
saveState();
|
||||
}
|
||||
|
||||
/** Returns the cursor key for a paired room role. */
|
||||
export function pairedCursorKey(
|
||||
chatJid: string,
|
||||
isReviewerTurn: boolean,
|
||||
): string {
|
||||
return isReviewerTurn ? `${chatJid}:reviewer` : chatJid;
|
||||
}
|
||||
|
||||
export function createImplicitContinuationTracker(idleTimeout: number) {
|
||||
const implicitContinuationUntil = new Map<string, number>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user