bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 1 | import type { RoomSummary } from './types'; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 2 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 3 | export interface PaneBadge { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 4 | count: number; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 5 | mention: boolean; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 6 | } |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 7 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 8 | export interface PaneBadges { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 9 | rail: PaneBadge; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 10 | channels: PaneBadge; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 11 | } |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 12 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 13 | /** DMs and mentions, each counted on whichever folded pane reaches its room in the fewest clicks. */ |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 14 | export function paneBadges( |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 15 | rooms: RoomSummary[], |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 16 | channelIds: Set<string>, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 17 | openRoomId: string | null, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 18 | muted: (room: RoomSummary) => boolean |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 19 | ): PaneBadges { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 20 | const rail = { count: 0, mention: false }; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 21 | const channels = { count: 0, mention: false }; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 22 | for (const room of rooms) { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 23 | if (room.space || room.membership !== 'Joined' || room.room_id === openRoomId || muted(room)) continue; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 24 | const count = room.direct |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 25 | ? room.notification_mode === 'MentionsAndKeywordsOnly' ? room.unread_mentions : room.unread_messages + room.unread_mentions |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 26 | : room.unread_mentions; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 27 | if (count === 0) continue; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 28 | const badge = channelIds.has(room.room_id) ? channels : rail; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 29 | badge.count += count; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 30 | badge.mention ||= room.unread_mentions > 0; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 31 | } |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 32 | return { rail, channels }; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 33 | } |