atagen

malice

public
Star0
Watch0
81d6bf15e59bfcfc57f792500008a796939cdbd5
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git

Blame: web/src/lib/pane-badges.ts

bcf2234c33f6atagen2026-10-27 03:55 UTC1
import type { RoomSummary } from './types';
bcf2234c33f6atagen2026-10-27 03:55 UTC2
bcf2234c33f6atagen2026-10-27 03:55 UTC3
export interface PaneBadge {
bcf2234c33f6atagen2026-10-27 03:55 UTC4
  count: number;
bcf2234c33f6atagen2026-10-27 03:55 UTC5
  mention: boolean;
bcf2234c33f6atagen2026-10-27 03:55 UTC6
}
bcf2234c33f6atagen2026-10-27 03:55 UTC7
bcf2234c33f6atagen2026-10-27 03:55 UTC8
export interface PaneBadges {
bcf2234c33f6atagen2026-10-27 03:55 UTC9
  rail: PaneBadge;
bcf2234c33f6atagen2026-10-27 03:55 UTC10
  channels: PaneBadge;
bcf2234c33f6atagen2026-10-27 03:55 UTC11
}
bcf2234c33f6atagen2026-10-27 03:55 UTC12
bcf2234c33f6atagen2026-10-27 03:55 UTC13
/** DMs and mentions, each counted on whichever folded pane reaches its room in the fewest clicks. */
bcf2234c33f6atagen2026-10-27 03:55 UTC14
export function paneBadges(
bcf2234c33f6atagen2026-10-27 03:55 UTC15
  rooms: RoomSummary[],
bcf2234c33f6atagen2026-10-27 03:55 UTC16
  channelIds: Set<string>,
bcf2234c33f6atagen2026-10-27 03:55 UTC17
  openRoomId: string | null,
bcf2234c33f6atagen2026-10-27 03:55 UTC18
  muted: (room: RoomSummary) => boolean
bcf2234c33f6atagen2026-10-27 03:55 UTC19
): PaneBadges {
bcf2234c33f6atagen2026-10-27 03:55 UTC20
  const rail = { count: 0, mention: false };
bcf2234c33f6atagen2026-10-27 03:55 UTC21
  const channels = { count: 0, mention: false };
bcf2234c33f6atagen2026-10-27 03:55 UTC22
  for (const room of rooms) {
bcf2234c33f6atagen2026-10-27 03:55 UTC23
    if (room.space || room.membership !== 'Joined' || room.room_id === openRoomId || muted(room)) continue;
bcf2234c33f6atagen2026-10-27 03:55 UTC24
    const count = room.direct
bcf2234c33f6atagen2026-10-27 03:55 UTC25
      ? room.notification_mode === 'MentionsAndKeywordsOnly' ? room.unread_mentions : room.unread_messages + room.unread_mentions
bcf2234c33f6atagen2026-10-27 03:55 UTC26
      : room.unread_mentions;
bcf2234c33f6atagen2026-10-27 03:55 UTC27
    if (count === 0) continue;
bcf2234c33f6atagen2026-10-27 03:55 UTC28
    const badge = channelIds.has(room.room_id) ? channels : rail;
bcf2234c33f6atagen2026-10-27 03:55 UTC29
    badge.count += count;
bcf2234c33f6atagen2026-10-27 03:55 UTC30
    badge.mention ||= room.unread_mentions > 0;
bcf2234c33f6atagen2026-10-27 03:55 UTC31
  }
bcf2234c33f6atagen2026-10-27 03:55 UTC32
  return { rail, channels };
bcf2234c33f6atagen2026-10-27 03:55 UTC33
}