refactor: centralize cursor key resolution with resolveCursorKey()

Replace all manual cursor key construction (hardcoded chatJid:reviewer,
chatJid:arbiter, pairedCursorKey, 3-way ternary) with a single
resolveCursorKey(chatJid, taskStatus) function.

- Removed pairedCursorKey import (no longer needed)
- Removed loopIsReviewerTurn, loopIsArbiterTurn intermediate variables
- All cursor key logic now flows through one function that maps
  task status to the correct role-specific key
This commit is contained in:
Eyejoker
2026-03-30 22:54:35 +09:00
parent 46926f32f3
commit 7ad40276d9
2 changed files with 29 additions and 17 deletions

View File

@@ -39,6 +39,30 @@ export function pairedCursorKey(
return isReviewerTurn ? `${chatJid}:reviewer` : chatJid;
}
/**
* Auto-resolve the cursor key based on current paired task status.
* Non-paired rooms always return chatJid.
* Paired rooms return role-specific keys so owner/reviewer/arbiter
* cursors are independent.
*/
export function resolveCursorKey(
chatJid: string,
taskStatus?: string | null,
): string {
if (!isPairedRoomJid(chatJid)) return chatJid;
if (!taskStatus) return chatJid;
switch (taskStatus) {
case 'review_ready':
case 'in_review':
return `${chatJid}:reviewer`;
case 'arbiter_requested':
case 'in_arbitration':
return `${chatJid}:arbiter`;
default:
return chatJid;
}
}
export function createImplicitContinuationTracker(idleTimeout: number) {
const implicitContinuationUntil = new Map<string, number>();