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:
@@ -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>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user