refactor: extract resolveActiveRole() as single source of status→role mapping
resolveCursorKey and resolveChannel both duplicated the same taskStatus→role switch. Now resolveActiveRole() is the single mapping, and both functions derive from it.
This commit is contained in:
@@ -39,28 +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.
|
||||
*/
|
||||
/** Map task status to the active role. */
|
||||
export function resolveActiveRole(
|
||||
taskStatus?: string | null,
|
||||
): 'owner' | 'reviewer' | 'arbiter' {
|
||||
switch (taskStatus) {
|
||||
case 'review_ready':
|
||||
case 'in_review':
|
||||
return 'reviewer';
|
||||
case 'arbiter_requested':
|
||||
case 'in_arbitration':
|
||||
return 'arbiter';
|
||||
default:
|
||||
return 'owner';
|
||||
}
|
||||
}
|
||||
|
||||
/** Cursor key for a role. Owner uses chatJid, others use chatJid:role. */
|
||||
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;
|
||||
}
|
||||
const role = resolveActiveRole(taskStatus);
|
||||
return role === 'owner' ? chatJid : `${chatJid}:${role}`;
|
||||
}
|
||||
|
||||
export function createImplicitContinuationTracker(idleTimeout: number) {
|
||||
|
||||
Reference in New Issue
Block a user