(
candidates: ChatStreamMarkerCandidate[],
options: ReconcileChatStreamMarkersOptions = {}
)
| 32 | * incorrectly hide a live stream owned by another pod. |
| 33 | */ |
| 34 | export async function reconcileChatStreamMarkers( |
| 35 | candidates: ChatStreamMarkerCandidate[], |
| 36 | options: ReconcileChatStreamMarkersOptions = {} |
| 37 | ): Promise<Map<string, ReconciledChatStreamMarker>> { |
| 38 | const results = new Map<string, ReconciledChatStreamMarker>() |
| 39 | |
| 40 | for (const candidate of candidates) { |
| 41 | if (candidate.streamId === null) { |
| 42 | results.set(candidate.chatId, { |
| 43 | chatId: candidate.chatId, |
| 44 | streamId: null, |
| 45 | status: 'inactive', |
| 46 | }) |
| 47 | continue |
| 48 | } |
| 49 | results.set(candidate.chatId, { |
| 50 | chatId: candidate.chatId, |
| 51 | streamId: candidate.streamId, |
| 52 | status: 'unknown', |
| 53 | }) |
| 54 | } |
| 55 | |
| 56 | const candidatesWithMarkers = candidates.filter((candidate) => candidate.streamId !== null) |
| 57 | if (candidatesWithMarkers.length === 0) { |
| 58 | return results |
| 59 | } |
| 60 | |
| 61 | const { status, ownersByChatId } = await getChatStreamLockOwners( |
| 62 | candidatesWithMarkers.map((candidate) => candidate.chatId) |
| 63 | ) |
| 64 | |
| 65 | for (const candidate of candidatesWithMarkers) { |
| 66 | const owner = ownersByChatId.get(candidate.chatId) |
| 67 | if (owner && (status === 'verified' || owner === candidate.streamId)) { |
| 68 | results.set(candidate.chatId, { |
| 69 | chatId: candidate.chatId, |
| 70 | streamId: owner, |
| 71 | status: 'active', |
| 72 | }) |
| 73 | continue |
| 74 | } |
| 75 | |
| 76 | if (status === 'verified') { |
| 77 | results.set(candidate.chatId, { |
| 78 | chatId: candidate.chatId, |
| 79 | streamId: null, |
| 80 | status: 'inactive', |
| 81 | }) |
| 82 | continue |
| 83 | } |
| 84 | |
| 85 | results.set(candidate.chatId, { |
| 86 | chatId: candidate.chatId, |
| 87 | streamId: candidate.streamId, |
| 88 | status: 'unknown', |
| 89 | }) |
| 90 | } |
| 91 |
no test coverage detected