atagen

malice

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

Blame: web/src/lib/MentionsInbox.svelte

668ab5c30531atagen2026-10-25 03:13 UTC1
<script lang="ts">
668ab5c30531atagen2026-10-25 03:13 UTC2
  import { get } from 'svelte/store';
668ab5c30531atagen2026-10-25 03:13 UTC3
  import { onDestroy, onMount, tick } from 'svelte';
fe847416ebd8atagen2026-10-27 03:27 UTC4
  import { mentionContext, mentionsPage, recoverMentions, retryMentionContext, setMentionsRead, markMentionsReadThrough } from './api';
668ab5c30531atagen2026-10-25 03:13 UTC5
  import ContextTimeline from './ContextTimeline.svelte';
668ab5c30531atagen2026-10-25 03:13 UTC6
  import EmojiText from './EmojiText.svelte';
668ab5c30531atagen2026-10-25 03:13 UTC7
  import MessageRow from './MessageRow.svelte';
668ab5c30531atagen2026-10-25 03:13 UTC8
  import { mentionsSnapshot, publishMentionsPage, rooms, sessionUser } from './store';
668ab5c30531atagen2026-10-25 03:13 UTC9
  import { TimelineViewport } from './timeline-viewport';
668ab5c30531atagen2026-10-25 03:13 UTC10
  import { ApiError } from './transport';
668ab5c30531atagen2026-10-25 03:13 UTC11
  import type { TimelineItem } from './types';
668ab5c30531atagen2026-10-25 03:13 UTC12
  import { mentionKey } from './mentions-model';
668ab5c30531atagen2026-10-25 03:13 UTC13
  import type { MentionEntry, MentionsPage, SavedMentionContext } from './mentions-model';
668ab5c30531atagen2026-10-25 03:13 UTC14
668ab5c30531atagen2026-10-25 03:13 UTC15
  export let self: string;
4f91f89d99faatagen2026-10-25 10:47 UTC16
  export let onLive: (roomId: string, eventId: string, threadRoot: string | null) => void;
668ab5c30531atagen2026-10-25 03:13 UTC17
668ab5c30531atagen2026-10-25 03:13 UTC18
  let page: MentionsPage | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC19
  let entries: MentionEntry[] = [];
668ab5c30531atagen2026-10-25 03:13 UTC20
  let selected: MentionEntry | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC21
  let saved: SavedMentionContext | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC22
  let list: HTMLDivElement;
668ab5c30531atagen2026-10-25 03:13 UTC23
  let viewport: TimelineViewport | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC24
  let observer: ResizeObserver | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC25
  let error = '';
668ab5c30531atagen2026-10-25 03:13 UTC26
  let busy = false;
668ab5c30531atagen2026-10-25 03:13 UTC27
  let actionBusy = false;
668ab5c30531atagen2026-10-25 03:13 UTC28
  let loadingContext = false;
668ab5c30531atagen2026-10-25 03:13 UTC29
  let mounted = false;
668ab5c30531atagen2026-10-25 03:13 UTC30
  let alive = true;
668ab5c30531atagen2026-10-25 03:13 UTC31
  let generation = 0;
668ab5c30531atagen2026-10-25 03:13 UTC32
  let contextGeneration = 0;
668ab5c30531atagen2026-10-25 03:13 UTC33
  let depth = 1;
668ab5c30531atagen2026-10-25 03:13 UTC34
  let pendingRevision = 0;
668ab5c30531atagen2026-10-25 03:13 UTC35
  let refreshTimer: ReturnType<typeof setTimeout> | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC36
  let renderedAccount = '';
668ab5c30531atagen2026-10-25 03:13 UTC37
  let selectedRevision = -1;
668ab5c30531atagen2026-10-25 03:13 UTC38
  let contextKey = '';
668ab5c30531atagen2026-10-25 03:13 UTC39
  let contextRequest: { key: string; revision: number } | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC40
  let queuedContext: MentionEntry | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC41
  let pendingExplicitOpen = false;
668ab5c30531atagen2026-10-25 03:13 UTC42
  let savedListTop = 0;
668ab5c30531atagen2026-10-25 03:13 UTC43
  $: unreadCount = $mentionsSnapshot?.boundary.account === self ? $mentionsSnapshot.unread_count : page?.unread_count ?? 0;
668ab5c30531atagen2026-10-25 03:13 UTC44
  $: joinedRooms = new Map($rooms.filter((room) => room.membership === 'Joined').map((room) => [room.room_id, room]));
668ab5c30531atagen2026-10-25 03:13 UTC45
  $: selectedRoom = selected ? joinedRooms.get(selected.key.room_id) : undefined;
668ab5c30531atagen2026-10-25 03:13 UTC46
  $: contextCanPaginate = !!selectedRoom;
668ab5c30531atagen2026-10-25 03:13 UTC47
668ab5c30531atagen2026-10-25 03:13 UTC48
  function itemEvent(item: TimelineItem) {
668ab5c30531atagen2026-10-25 03:13 UTC49
    return item.kind === 'event' ? item.event : null;
668ab5c30531atagen2026-10-25 03:13 UTC50
  }
668ab5c30531atagen2026-10-25 03:13 UTC51
  function roomName(entry: MentionEntry): string {
668ab5c30531atagen2026-10-25 03:13 UTC52
    return entry.room_name || joinedRooms.get(entry.key.room_id)?.name || entry.key.room_id;
668ab5c30531atagen2026-10-25 03:13 UTC53
  }
249e439c27e5atagen2026-10-25 13:26 UTC54
  const GAP_LABELS: Record<string, string> = {
249e439c27e5atagen2026-10-25 13:26 UTC55
    SyncDiscontinuity: 'Sync was interrupted',
249e439c27e5atagen2026-10-25 13:26 UTC56
    LimitedTimeline: 'Too many messages arrived at once',
249e439c27e5atagen2026-10-25 13:26 UTC57
    RoomLeft: 'You left the room',
249e439c27e5atagen2026-10-25 13:26 UTC58
    ContextUnavailable: 'Context could not be loaded',
249e439c27e5atagen2026-10-25 13:26 UTC59
    NotificationHistoryUnavailable: 'Notification history unavailable',
249e439c27e5atagen2026-10-25 13:26 UTC60
    CandidateExpired: 'A message could not be read',
249e439c27e5atagen2026-10-25 13:26 UTC61
    StoreReset: 'Inbox was reset',
249e439c27e5atagen2026-10-25 13:26 UTC62
    StoreFailed: 'Inbox could not be saved',
249e439c27e5atagen2026-10-25 13:26 UTC63
    HookTimedOut: 'Checking a message timed out'
249e439c27e5atagen2026-10-25 13:26 UTC64
  };
249e439c27e5atagen2026-10-25 13:26 UTC65
249e439c27e5atagen2026-10-25 13:26 UTC66
  function gapLabel(reason: string): string {
249e439c27e5atagen2026-10-25 13:26 UTC67
    return GAP_LABELS[reason] ?? reason;
249e439c27e5atagen2026-10-25 13:26 UTC68
  }
249e439c27e5atagen2026-10-25 13:26 UTC69
668ab5c30531atagen2026-10-25 03:13 UTC70
  function reasonLabel(reason: string): string {
a4555a7eae2datagen2026-10-25 09:18 UTC71
    return reason === 'Direct' ? 'Direct mention' : reason === 'Reply' ? 'Reply' : reason === 'Keyword' ? 'Keyword' : 'Room mention';
668ab5c30531atagen2026-10-25 03:13 UTC72
  }
668ab5c30531atagen2026-10-25 03:13 UTC73
  function captureLabel(state: MentionEntry['capture']): string {
668ab5c30531atagen2026-10-25 03:13 UTC74
    if (state.kind === 'Failed') return state.message;
668ab5c30531atagen2026-10-25 03:13 UTC75
    return state.kind === 'Ready' ? 'Context saved' : state.kind === 'Partial' ? 'Partial context saved' : state.kind === 'Pending' ? 'Saving context' : 'Context unavailable';
668ab5c30531atagen2026-10-25 03:13 UTC76
  }
668ab5c30531atagen2026-10-25 03:13 UTC77
  function keyOf(entry: MentionEntry): string { return mentionKey(entry.key); }
668ab5c30531atagen2026-10-25 03:13 UTC78
  function bindViewport(node: HTMLDivElement) {
668ab5c30531atagen2026-10-25 03:13 UTC79
    list = node;
668ab5c30531atagen2026-10-25 03:13 UTC80
    viewport?.releaseScroll();
668ab5c30531atagen2026-10-25 03:13 UTC81
    observer?.disconnect();
668ab5c30531atagen2026-10-25 03:13 UTC82
    node.scrollTop = savedListTop;
668ab5c30531atagen2026-10-25 03:13 UTC83
    viewport = new TimelineViewport(node, null);
668ab5c30531atagen2026-10-25 03:13 UTC84
    const content = node.querySelector<HTMLElement>('.entry-content');
668ab5c30531atagen2026-10-25 03:13 UTC85
    observer = new ResizeObserver(() => viewport?.restore());
668ab5c30531atagen2026-10-25 03:13 UTC86
    if (content) observer.observe(content);
668ab5c30531atagen2026-10-25 03:13 UTC87
    void tick().then(() => {
668ab5c30531atagen2026-10-25 03:13 UTC88
      if (!alive || selected || list !== node) return;
668ab5c30531atagen2026-10-25 03:13 UTC89
      node.scrollTop = savedListTop;
668ab5c30531atagen2026-10-25 03:13 UTC90
      viewport?.capture();
668ab5c30531atagen2026-10-25 03:13 UTC91
    });
668ab5c30531atagen2026-10-25 03:13 UTC92
    return {
668ab5c30531atagen2026-10-25 03:13 UTC93
      destroy() {
668ab5c30531atagen2026-10-25 03:13 UTC94
        if (!selected) savedListTop = node.scrollTop;
668ab5c30531atagen2026-10-25 03:13 UTC95
        observer?.disconnect();
668ab5c30531atagen2026-10-25 03:13 UTC96
        observer = null;
668ab5c30531atagen2026-10-25 03:13 UTC97
        viewport?.releaseScroll();
668ab5c30531atagen2026-10-25 03:13 UTC98
        viewport = null;
668ab5c30531atagen2026-10-25 03:13 UTC99
      }
668ab5c30531atagen2026-10-25 03:13 UTC100
    };
668ab5c30531atagen2026-10-25 03:13 UTC101
  }
668ab5c30531atagen2026-10-25 03:13 UTC102
  function openContext(entry: MentionEntry): void {
668ab5c30531atagen2026-10-25 03:13 UTC103
    if (!selected) savedListTop = list?.scrollTop ?? savedListTop;
668ab5c30531atagen2026-10-25 03:13 UTC104
    void loadContext(entry);
668ab5c30531atagen2026-10-25 03:13 UTC105
  }
668ab5c30531atagen2026-10-25 03:13 UTC106
  function currentAccount(account: string): boolean {
668ab5c30531atagen2026-10-25 03:13 UTC107
    return alive && account === self && get(sessionUser) === account;
668ab5c30531atagen2026-10-25 03:13 UTC108
  }
668ab5c30531atagen2026-10-25 03:13 UTC109
  function captureViewport(): void { viewport?.capture(); }
668ab5c30531atagen2026-10-25 03:13 UTC110
  async function restoreViewport(): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC111
    await tick();
668ab5c30531atagen2026-10-25 03:13 UTC112
    if (alive) viewport?.restore();
668ab5c30531atagen2026-10-25 03:13 UTC113
  }
668ab5c30531atagen2026-10-25 03:13 UTC114
  async function fetchPage(cursor: string | null): Promise<MentionsPage> {
668ab5c30531atagen2026-10-25 03:13 UTC115
    return mentionsPage(cursor, 50);
668ab5c30531atagen2026-10-25 03:13 UTC116
  }
668ab5c30531atagen2026-10-25 03:13 UTC117
  async function fetchRange(targetDepth: number, request: number, account: string): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC118
    busy = true;
668ab5c30531atagen2026-10-25 03:13 UTC119
    error = '';
668ab5c30531atagen2026-10-25 03:13 UTC120
    const anchorPage = page;
668ab5c30531atagen2026-10-25 03:13 UTC121
    const anchorRevision = anchorPage?.revision ?? 0;
668ab5c30531atagen2026-10-25 03:13 UTC122
    let succeeded = false;
668ab5c30531atagen2026-10-25 03:13 UTC123
    try {
668ab5c30531atagen2026-10-25 03:13 UTC124
      const first = await fetchPage(null);
668ab5c30531atagen2026-10-25 03:13 UTC125
      if (!currentAccount(account) || request !== generation || first.boundary.account !== account) return;
668ab5c30531atagen2026-10-25 03:13 UTC126
      const firstSnapshot = first;
668ab5c30531atagen2026-10-25 03:13 UTC127
      const gathered = [...first.entries];
668ab5c30531atagen2026-10-25 03:13 UTC128
      let loadedDepth = 1;
668ab5c30531atagen2026-10-25 03:13 UTC129
      let cursor = first.next_cursor;
668ab5c30531atagen2026-10-25 03:13 UTC130
      let last = first;
668ab5c30531atagen2026-10-25 03:13 UTC131
      for (let index = 1; index < targetDepth && cursor; index++) {
668ab5c30531atagen2026-10-25 03:13 UTC132
        last = await fetchPage(cursor);
668ab5c30531atagen2026-10-25 03:13 UTC133
        if (!currentAccount(account) || request !== generation || last.boundary.account !== account) return;
668ab5c30531atagen2026-10-25 03:13 UTC134
        gathered.push(...last.entries);
668ab5c30531atagen2026-10-25 03:13 UTC135
        loadedDepth++;
668ab5c30531atagen2026-10-25 03:13 UTC136
        cursor = last.next_cursor;
668ab5c30531atagen2026-10-25 03:13 UTC137
      }
668ab5c30531atagen2026-10-25 03:13 UTC138
      const mirror = get(mentionsSnapshot);
668ab5c30531atagen2026-10-25 03:13 UTC139
      if (mirror?.boundary.account === account && mirror.revision > firstSnapshot.revision) {
668ab5c30531atagen2026-10-25 03:13 UTC140
        pendingRevision = Math.max(pendingRevision, mirror.revision);
668ab5c30531atagen2026-10-25 03:13 UTC141
      }
668ab5c30531atagen2026-10-25 03:13 UTC142
      if (firstSnapshot.revision < anchorRevision) return;
668ab5c30531atagen2026-10-25 03:13 UTC143
      captureViewport();
668ab5c30531atagen2026-10-25 03:13 UTC144
      const unique = new Map<string, MentionEntry>();
668ab5c30531atagen2026-10-25 03:13 UTC145
      for (const entry of gathered) unique.set(keyOf(entry), entry);
668ab5c30531atagen2026-10-25 03:13 UTC146
      if (mirror?.boundary.account === account) {
668ab5c30531atagen2026-10-25 03:13 UTC147
        for (const update of mirror.entries) {
668ab5c30531atagen2026-10-25 03:13 UTC148
          const key = keyOf(update);
668ab5c30531atagen2026-10-25 03:13 UTC149
          const previous = unique.get(key);
668ab5c30531atagen2026-10-25 03:13 UTC150
          if (previous && update.revision >= previous.revision) unique.set(key, update);
668ab5c30531atagen2026-10-25 03:13 UTC151
        }
668ab5c30531atagen2026-10-25 03:13 UTC152
      }
668ab5c30531atagen2026-10-25 03:13 UTC153
      const replacement = [...unique.values()];
668ab5c30531atagen2026-10-25 03:13 UTC154
      page = { ...firstSnapshot, next_cursor: last.next_cursor, end_reached: last.end_reached, entries: replacement };
668ab5c30531atagen2026-10-25 03:13 UTC155
      entries = replacement;
668ab5c30531atagen2026-10-25 03:13 UTC156
      if (selected) {
668ab5c30531atagen2026-10-25 03:13 UTC157
        const latestSelected = replacement.find((entry) => keyOf(entry) === keyOf(selected!));
668ab5c30531atagen2026-10-25 03:13 UTC158
        if (latestSelected && latestSelected.revision > selected.revision) selected = latestSelected;
668ab5c30531atagen2026-10-25 03:13 UTC159
        void loadContext(selected, false);
668ab5c30531atagen2026-10-25 03:13 UTC160
      }
668ab5c30531atagen2026-10-25 03:13 UTC161
      publishMentionsPage(firstSnapshot);
668ab5c30531atagen2026-10-25 03:13 UTC162
      if (pendingRevision <= firstSnapshot.revision) pendingRevision = 0;
668ab5c30531atagen2026-10-25 03:13 UTC163
      depth = loadedDepth;
668ab5c30531atagen2026-10-25 03:13 UTC164
      succeeded = true;
668ab5c30531atagen2026-10-25 03:13 UTC165
      await restoreViewport();
668ab5c30531atagen2026-10-25 03:13 UTC166
    } catch (cause) {
668ab5c30531atagen2026-10-25 03:13 UTC167
      if (currentAccount(account) && request === generation) error = cause instanceof Error ? cause.message : 'Could not load mentions';
668ab5c30531atagen2026-10-25 03:13 UTC168
    } finally {
668ab5c30531atagen2026-10-25 03:13 UTC169
      if (currentAccount(account) && request === generation) {
668ab5c30531atagen2026-10-25 03:13 UTC170
        busy = false;
668ab5c30531atagen2026-10-25 03:13 UTC171
        if (succeeded && pendingRevision > (page?.revision ?? 0)) scheduleRefresh(pendingRevision);
668ab5c30531atagen2026-10-25 03:13 UTC172
      }
668ab5c30531atagen2026-10-25 03:13 UTC173
    }
668ab5c30531atagen2026-10-25 03:13 UTC174
  }
668ab5c30531atagen2026-10-25 03:13 UTC175
  function scheduleRefresh(revision: number): void {
668ab5c30531atagen2026-10-25 03:13 UTC176
    pendingRevision = Math.max(pendingRevision, revision);
668ab5c30531atagen2026-10-25 03:13 UTC177
    if (busy || !mounted) return;
668ab5c30531atagen2026-10-25 03:13 UTC178
    if (refreshTimer) clearTimeout(refreshTimer);
668ab5c30531atagen2026-10-25 03:13 UTC179
    refreshTimer = setTimeout(() => {
668ab5c30531atagen2026-10-25 03:13 UTC180
      refreshTimer = null;
668ab5c30531atagen2026-10-25 03:13 UTC181
      if (!alive || busy) return;
668ab5c30531atagen2026-10-25 03:13 UTC182
      const request = ++generation;
668ab5c30531atagen2026-10-25 03:13 UTC183
      void fetchRange(Math.max(1, depth), request, self);
668ab5c30531atagen2026-10-25 03:13 UTC184
    }, 200);
668ab5c30531atagen2026-10-25 03:13 UTC185
  }
668ab5c30531atagen2026-10-25 03:13 UTC186
  async function loadMore(): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC187
    if (!page?.next_cursor || page.end_reached || busy) return;
668ab5c30531atagen2026-10-25 03:13 UTC188
    const cursor = page.next_cursor;
668ab5c30531atagen2026-10-25 03:13 UTC189
    const request = ++generation;
668ab5c30531atagen2026-10-25 03:13 UTC190
    const account = self;
668ab5c30531atagen2026-10-25 03:13 UTC191
    busy = true;
668ab5c30531atagen2026-10-25 03:13 UTC192
    error = '';
668ab5c30531atagen2026-10-25 03:13 UTC193
    let succeeded = false;
668ab5c30531atagen2026-10-25 03:13 UTC194
    try {
668ab5c30531atagen2026-10-25 03:13 UTC195
      const next = await fetchPage(cursor);
668ab5c30531atagen2026-10-25 03:13 UTC196
      if (!currentAccount(account) || request !== generation || next.boundary.account !== account) return;
668ab5c30531atagen2026-10-25 03:13 UTC197
      const current = page;
668ab5c30531atagen2026-10-25 03:13 UTC198
      if (!current || next.revision < current.revision) return;
668ab5c30531atagen2026-10-25 03:13 UTC199
      captureViewport();
668ab5c30531atagen2026-10-25 03:13 UTC200
      const unique = new Map(entries.map((entry) => [keyOf(entry), entry]));
668ab5c30531atagen2026-10-25 03:13 UTC201
      for (const entry of next.entries) unique.set(keyOf(entry), entry);
668ab5c30531atagen2026-10-25 03:13 UTC202
      page = { ...current, next_cursor: next.next_cursor, end_reached: next.end_reached, entries: [...unique.values()] };
668ab5c30531atagen2026-10-25 03:13 UTC203
      entries = page.entries;
668ab5c30531atagen2026-10-25 03:13 UTC204
      const mirror = get(mentionsSnapshot);
668ab5c30531atagen2026-10-25 03:13 UTC205
      if (mirror?.boundary.account === account) {
668ab5c30531atagen2026-10-25 03:13 UTC206
        for (const update of mirror.entries) {
668ab5c30531atagen2026-10-25 03:13 UTC207
          const key = keyOf(update);
668ab5c30531atagen2026-10-25 03:13 UTC208
          const previous = unique.get(key);
668ab5c30531atagen2026-10-25 03:13 UTC209
          if (previous && update.revision >= previous.revision) unique.set(key, update);
668ab5c30531atagen2026-10-25 03:13 UTC210
        }
668ab5c30531atagen2026-10-25 03:13 UTC211
        entries = [...unique.values()];
668ab5c30531atagen2026-10-25 03:13 UTC212
        page = { ...page, entries };
668ab5c30531atagen2026-10-25 03:13 UTC213
      }
668ab5c30531atagen2026-10-25 03:13 UTC214
      depth++;
668ab5c30531atagen2026-10-25 03:13 UTC215
      succeeded = true;
668ab5c30531atagen2026-10-25 03:13 UTC216
      await restoreViewport();
668ab5c30531atagen2026-10-25 03:13 UTC217
    } catch (cause) {
668ab5c30531atagen2026-10-25 03:13 UTC218
      if (currentAccount(account) && request === generation) error = cause instanceof Error ? cause.message : 'Could not load mentions';
668ab5c30531atagen2026-10-25 03:13 UTC219
    } finally {
668ab5c30531atagen2026-10-25 03:13 UTC220
      if (currentAccount(account) && request === generation) {
668ab5c30531atagen2026-10-25 03:13 UTC221
        busy = false;
668ab5c30531atagen2026-10-25 03:13 UTC222
        if (succeeded && pendingRevision > (page?.revision ?? 0)) scheduleRefresh(pendingRevision);
668ab5c30531atagen2026-10-25 03:13 UTC223
      }
668ab5c30531atagen2026-10-25 03:13 UTC224
    }
668ab5c30531atagen2026-10-25 03:13 UTC225
  }
668ab5c30531atagen2026-10-25 03:13 UTC226
  async function loadContext(entry: MentionEntry, explicit = true): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC227
    const id = keyOf(entry);
668ab5c30531atagen2026-10-25 03:13 UTC228
    if (explicit) pendingExplicitOpen = true;
668ab5c30531atagen2026-10-25 03:13 UTC229
    if (contextRequest?.key === id) {
668ab5c30531atagen2026-10-25 03:13 UTC230
      if (entry.revision > contextRequest.revision) queuedContext = entry;
668ab5c30531atagen2026-10-25 03:13 UTC231
      return;
668ab5c30531atagen2026-10-25 03:13 UTC232
    }
668ab5c30531atagen2026-10-25 03:13 UTC233
    if (contextKey !== id) {
668ab5c30531atagen2026-10-25 03:13 UTC234
      if (!selected) savedListTop = list?.scrollTop ?? savedListTop;
668ab5c30531atagen2026-10-25 03:13 UTC235
      saved = null;
668ab5c30531atagen2026-10-25 03:13 UTC236
      selectedRevision = -1;
668ab5c30531atagen2026-10-25 03:13 UTC237
    }
668ab5c30531atagen2026-10-25 03:13 UTC238
    contextKey = id;
668ab5c30531atagen2026-10-25 03:13 UTC239
    selectedRevision = entry.revision;
668ab5c30531atagen2026-10-25 03:13 UTC240
    selected = entry;
668ab5c30531atagen2026-10-25 03:13 UTC241
    loadingContext = true;
668ab5c30531atagen2026-10-25 03:13 UTC242
    error = '';
668ab5c30531atagen2026-10-25 03:13 UTC243
    const account = self;
668ab5c30531atagen2026-10-25 03:13 UTC244
    const request = ++contextGeneration;
668ab5c30531atagen2026-10-25 03:13 UTC245
    contextRequest = { key: id, revision: entry.revision };
668ab5c30531atagen2026-10-25 03:13 UTC246
    try {
668ab5c30531atagen2026-10-25 03:13 UTC247
      const result = await mentionContext(entry.key.room_id, entry.key.event_id);
668ab5c30531atagen2026-10-25 03:13 UTC248
      if (!currentAccount(account) || request !== contextGeneration || contextKey !== id || mentionKey(result.key) !== id) return;
668ab5c30531atagen2026-10-25 03:13 UTC249
      saved = result;
668ab5c30531atagen2026-10-25 03:13 UTC250
      if (pendingExplicitOpen) {
668ab5c30531atagen2026-10-25 03:13 UTC251
        pendingExplicitOpen = false;
668ab5c30531atagen2026-10-25 03:13 UTC252
        const current = entries.find((item) => keyOf(item) === id);
668ab5c30531atagen2026-10-25 03:13 UTC253
        if (current && !current.read) {
668ab5c30531atagen2026-10-25 03:13 UTC254
          await setMentionsRead([current.key], true);
668ab5c30531atagen2026-10-25 03:13 UTC255
          if (currentAccount(account) && request === contextGeneration) scheduleRefresh(get(mentionsSnapshot)?.revision ?? page?.revision ?? 0);
668ab5c30531atagen2026-10-25 03:13 UTC256
        }
668ab5c30531atagen2026-10-25 03:13 UTC257
      }
668ab5c30531atagen2026-10-25 03:13 UTC258
    } catch (cause) {
668ab5c30531atagen2026-10-25 03:13 UTC259
      if (currentAccount(account) && request === contextGeneration) {
668ab5c30531atagen2026-10-25 03:13 UTC260
        pendingExplicitOpen = false;
668ab5c30531atagen2026-10-25 03:13 UTC261
        if (cause instanceof ApiError && cause.status === 404) {
668ab5c30531atagen2026-10-25 03:13 UTC262
          backToList();
668ab5c30531atagen2026-10-25 03:13 UTC263
          error = 'This mention is no longer available';
668ab5c30531atagen2026-10-25 03:13 UTC264
          scheduleRefresh(page?.revision ?? 0);
668ab5c30531atagen2026-10-25 03:13 UTC265
        } else {
668ab5c30531atagen2026-10-25 03:13 UTC266
          error = cause instanceof Error ? cause.message : 'Could not load saved context';
668ab5c30531atagen2026-10-25 03:13 UTC267
        }
668ab5c30531atagen2026-10-25 03:13 UTC268
      }
668ab5c30531atagen2026-10-25 03:13 UTC269
    } finally {
668ab5c30531atagen2026-10-25 03:13 UTC270
      if (currentAccount(account) && request === contextGeneration) {
668ab5c30531atagen2026-10-25 03:13 UTC271
        contextRequest = null;
668ab5c30531atagen2026-10-25 03:13 UTC272
        loadingContext = false;
668ab5c30531atagen2026-10-25 03:13 UTC273
        const queued = queuedContext;
668ab5c30531atagen2026-10-25 03:13 UTC274
        queuedContext = null;
668ab5c30531atagen2026-10-25 03:13 UTC275
        if (queued && keyOf(queued) === id && queued.revision !== selectedRevision) void loadContext(queued, false);
668ab5c30531atagen2026-10-25 03:13 UTC276
      }
668ab5c30531atagen2026-10-25 03:13 UTC277
    }
668ab5c30531atagen2026-10-25 03:13 UTC278
  }
668ab5c30531atagen2026-10-25 03:13 UTC279
  async function setRead(entry: MentionEntry, read: boolean): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC280
    if (actionBusy) return;
668ab5c30531atagen2026-10-25 03:13 UTC281
    actionBusy = true;
668ab5c30531atagen2026-10-25 03:13 UTC282
    const account = self;
668ab5c30531atagen2026-10-25 03:13 UTC283
    try {
668ab5c30531atagen2026-10-25 03:13 UTC284
      await setMentionsRead([entry.key], read);
668ab5c30531atagen2026-10-25 03:13 UTC285
      if (!currentAccount(account)) return;
668ab5c30531atagen2026-10-25 03:13 UTC286
      const mirror = get(mentionsSnapshot);
668ab5c30531atagen2026-10-25 03:13 UTC287
      if (mirror?.boundary.account === account) scheduleRefresh(mirror.revision);
668ab5c30531atagen2026-10-25 03:13 UTC288
      else scheduleRefresh((page?.revision ?? 0) + 1);
668ab5c30531atagen2026-10-25 03:13 UTC289
    } catch (cause) {
668ab5c30531atagen2026-10-25 03:13 UTC290
      if (currentAccount(account)) error = cause instanceof Error ? cause.message : 'Could not update mention';
668ab5c30531atagen2026-10-25 03:13 UTC291
    } finally {
668ab5c30531atagen2026-10-25 03:13 UTC292
      if (currentAccount(account)) actionBusy = false;
668ab5c30531atagen2026-10-25 03:13 UTC293
    }
668ab5c30531atagen2026-10-25 03:13 UTC294
  }
668ab5c30531atagen2026-10-25 03:13 UTC295
  async function markAllRead(): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC296
    if (!page || actionBusy) return;
668ab5c30531atagen2026-10-25 03:13 UTC297
    actionBusy = true;
668ab5c30531atagen2026-10-25 03:13 UTC298
    const account = self;
668ab5c30531atagen2026-10-25 03:13 UTC299
    const boundary = page.boundary;
668ab5c30531atagen2026-10-25 03:13 UTC300
    try {
668ab5c30531atagen2026-10-25 03:13 UTC301
      await markMentionsReadThrough(boundary);
668ab5c30531atagen2026-10-25 03:13 UTC302
      if (!currentAccount(account)) return;
668ab5c30531atagen2026-10-25 03:13 UTC303
      const mirror = get(mentionsSnapshot);
668ab5c30531atagen2026-10-25 03:13 UTC304
      scheduleRefresh(mirror?.boundary.account === account ? mirror.revision : page?.revision ?? 0);
668ab5c30531atagen2026-10-25 03:13 UTC305
    } catch (cause) {
668ab5c30531atagen2026-10-25 03:13 UTC306
      if (currentAccount(account)) error = cause instanceof Error ? cause.message : 'Could not mark mentions read';
668ab5c30531atagen2026-10-25 03:13 UTC307
    } finally {
668ab5c30531atagen2026-10-25 03:13 UTC308
      if (currentAccount(account)) actionBusy = false;
668ab5c30531atagen2026-10-25 03:13 UTC309
    }
668ab5c30531atagen2026-10-25 03:13 UTC310
  }
668ab5c30531atagen2026-10-25 03:13 UTC311
  async function recover(): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC312
    if (actionBusy) return;
668ab5c30531atagen2026-10-25 03:13 UTC313
    actionBusy = true;
668ab5c30531atagen2026-10-25 03:13 UTC314
    const account = self;
668ab5c30531atagen2026-10-25 03:13 UTC315
    try {
668ab5c30531atagen2026-10-25 03:13 UTC316
      await recoverMentions();
668ab5c30531atagen2026-10-25 03:13 UTC317
      if (!currentAccount(account)) return;
668ab5c30531atagen2026-10-25 03:13 UTC318
      scheduleRefresh(get(mentionsSnapshot)?.revision ?? page?.revision ?? 0);
668ab5c30531atagen2026-10-25 03:13 UTC319
    } catch (cause) {
668ab5c30531atagen2026-10-25 03:13 UTC320
      if (currentAccount(account)) error = cause instanceof Error ? cause.message : 'Could not recover mention history';
668ab5c30531atagen2026-10-25 03:13 UTC321
    } finally {
668ab5c30531atagen2026-10-25 03:13 UTC322
      if (currentAccount(account)) actionBusy = false;
668ab5c30531atagen2026-10-25 03:13 UTC323
    }
668ab5c30531atagen2026-10-25 03:13 UTC324
  }
668ab5c30531atagen2026-10-25 03:13 UTC325
  async function retryCapture(): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC326
    if (!selected || !selectedRoom || actionBusy || loadingContext) return;
668ab5c30531atagen2026-10-25 03:13 UTC327
    actionBusy = true;
668ab5c30531atagen2026-10-25 03:13 UTC328
    const request = contextGeneration;
668ab5c30531atagen2026-10-25 03:13 UTC329
    const account = self;
668ab5c30531atagen2026-10-25 03:13 UTC330
    try {
668ab5c30531atagen2026-10-25 03:13 UTC331
      const result = await retryMentionContext(selected.key.room_id, selected.key.event_id);
668ab5c30531atagen2026-10-25 03:13 UTC332
      if (!currentAccount(account) || request !== contextGeneration || mentionKey(result.key) !== contextKey) return;
668ab5c30531atagen2026-10-25 03:13 UTC333
      saved = result;
668ab5c30531atagen2026-10-25 03:13 UTC334
      scheduleRefresh(get(mentionsSnapshot)?.revision ?? page?.revision ?? 0);
668ab5c30531atagen2026-10-25 03:13 UTC335
    } catch (cause) {
668ab5c30531atagen2026-10-25 03:13 UTC336
      if (currentAccount(account) && request === contextGeneration) error = cause instanceof Error ? cause.message : 'Could not retry context capture';
668ab5c30531atagen2026-10-25 03:13 UTC337
    } finally {
668ab5c30531atagen2026-10-25 03:13 UTC338
      if (currentAccount(account)) actionBusy = false;
668ab5c30531atagen2026-10-25 03:13 UTC339
    }
668ab5c30531atagen2026-10-25 03:13 UTC340
  }
668ab5c30531atagen2026-10-25 03:13 UTC341
  async function retryEntry(entry: MentionEntry): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC342
    if (selected?.revision !== entry.revision || keyOf(selected) !== keyOf(entry)) await loadContext(entry, false);
668ab5c30531atagen2026-10-25 03:13 UTC343
    else await tick();
668ab5c30531atagen2026-10-25 03:13 UTC344
    await retryCapture();
668ab5c30531atagen2026-10-25 03:13 UTC345
  }
668ab5c30531atagen2026-10-25 03:13 UTC346
  function backToList(): void {
668ab5c30531atagen2026-10-25 03:13 UTC347
    contextGeneration++;
668ab5c30531atagen2026-10-25 03:13 UTC348
    contextRequest = null;
668ab5c30531atagen2026-10-25 03:13 UTC349
    queuedContext = null;
668ab5c30531atagen2026-10-25 03:13 UTC350
    loadingContext = false;
668ab5c30531atagen2026-10-25 03:13 UTC351
    pendingExplicitOpen = false;
668ab5c30531atagen2026-10-25 03:13 UTC352
    selected = null;
668ab5c30531atagen2026-10-25 03:13 UTC353
    saved = null;
668ab5c30531atagen2026-10-25 03:13 UTC354
    contextKey = '';
668ab5c30531atagen2026-10-25 03:13 UTC355
  }
668ab5c30531atagen2026-10-25 03:13 UTC356
668ab5c30531atagen2026-10-25 03:13 UTC357
  const unsubscribe = mentionsSnapshot.subscribe((snapshot) => {
668ab5c30531atagen2026-10-25 03:13 UTC358
    if (!snapshot || snapshot.boundary.account !== self) return;
668ab5c30531atagen2026-10-25 03:13 UTC359
    if (snapshot.revision < (page?.revision ?? -1)) return;
668ab5c30531atagen2026-10-25 03:13 UTC360
    const updated = new Map(snapshot.entries.map((entry) => [keyOf(entry), entry]));
668ab5c30531atagen2026-10-25 03:13 UTC361
    if (entries.length) {
668ab5c30531atagen2026-10-25 03:13 UTC362
      captureViewport();
668ab5c30531atagen2026-10-25 03:13 UTC363
      entries = entries.map((entry) => {
668ab5c30531atagen2026-10-25 03:13 UTC364
        const update = updated.get(keyOf(entry));
668ab5c30531atagen2026-10-25 03:13 UTC365
        return update && update.revision >= entry.revision ? update : entry;
668ab5c30531atagen2026-10-25 03:13 UTC366
      });
668ab5c30531atagen2026-10-25 03:13 UTC367
      if (page) page = { ...page, entries };
668ab5c30531atagen2026-10-25 03:13 UTC368
      void restoreViewport();
668ab5c30531atagen2026-10-25 03:13 UTC369
    }
668ab5c30531atagen2026-10-25 03:13 UTC370
    if (selected) {
668ab5c30531atagen2026-10-25 03:13 UTC371
      const update = snapshot.entries.find((entry) => keyOf(entry) === keyOf(selected!));
668ab5c30531atagen2026-10-25 03:13 UTC372
      if (update && update.revision > selected.revision) selected = update;
668ab5c30531atagen2026-10-25 03:13 UTC373
    }
668ab5c30531atagen2026-10-25 03:13 UTC374
    if (busy) {
668ab5c30531atagen2026-10-25 03:13 UTC375
      pendingRevision = Math.max(pendingRevision, snapshot.revision);
668ab5c30531atagen2026-10-25 03:13 UTC376
      return;
668ab5c30531atagen2026-10-25 03:13 UTC377
    }
668ab5c30531atagen2026-10-25 03:13 UTC378
    if (!page || snapshot.revision > page.revision) scheduleRefresh(snapshot.revision);
668ab5c30531atagen2026-10-25 03:13 UTC379
  });
668ab5c30531atagen2026-10-25 03:13 UTC380
  $: if (self && self !== renderedAccount) {
668ab5c30531atagen2026-10-25 03:13 UTC381
    generation++;
668ab5c30531atagen2026-10-25 03:13 UTC382
    contextGeneration++;
668ab5c30531atagen2026-10-25 03:13 UTC383
    page = null;
668ab5c30531atagen2026-10-25 03:13 UTC384
    entries = [];
668ab5c30531atagen2026-10-25 03:13 UTC385
    error = '';
668ab5c30531atagen2026-10-25 03:13 UTC386
    selected = null;
668ab5c30531atagen2026-10-25 03:13 UTC387
    saved = null;
668ab5c30531atagen2026-10-25 03:13 UTC388
    depth = 1;
668ab5c30531atagen2026-10-25 03:13 UTC389
    busy = false;
668ab5c30531atagen2026-10-25 03:13 UTC390
    actionBusy = false;
668ab5c30531atagen2026-10-25 03:13 UTC391
    loadingContext = false;
668ab5c30531atagen2026-10-25 03:13 UTC392
    contextRequest = null;
668ab5c30531atagen2026-10-25 03:13 UTC393
    queuedContext = null;
668ab5c30531atagen2026-10-25 03:13 UTC394
    pendingExplicitOpen = false;
668ab5c30531atagen2026-10-25 03:13 UTC395
    pendingRevision = 0;
668ab5c30531atagen2026-10-25 03:13 UTC396
    savedListTop = 0;
668ab5c30531atagen2026-10-25 03:13 UTC397
    if (refreshTimer) clearTimeout(refreshTimer);
668ab5c30531atagen2026-10-25 03:13 UTC398
    renderedAccount = self;
668ab5c30531atagen2026-10-25 03:13 UTC399
    if (mounted) void fetchRange(1, generation, self);
668ab5c30531atagen2026-10-25 03:13 UTC400
  }
668ab5c30531atagen2026-10-25 03:13 UTC401
  $: if (selected && selected.revision !== selectedRevision) void loadContext(selected, false);
668ab5c30531atagen2026-10-25 03:13 UTC402
  onMount(() => {
668ab5c30531atagen2026-10-25 03:13 UTC403
    mounted = true;
668ab5c30531atagen2026-10-25 03:13 UTC404
    if (!page) void fetchRange(1, ++generation, self);
668ab5c30531atagen2026-10-25 03:13 UTC405
  });
668ab5c30531atagen2026-10-25 03:13 UTC406
  onDestroy(() => {
668ab5c30531atagen2026-10-25 03:13 UTC407
    alive = false;
668ab5c30531atagen2026-10-25 03:13 UTC408
    generation++;
668ab5c30531atagen2026-10-25 03:13 UTC409
    contextGeneration++;
668ab5c30531atagen2026-10-25 03:13 UTC410
    unsubscribe();
668ab5c30531atagen2026-10-25 03:13 UTC411
    observer?.disconnect();
668ab5c30531atagen2026-10-25 03:13 UTC412
    viewport?.releaseScroll();
668ab5c30531atagen2026-10-25 03:13 UTC413
    if (refreshTimer) clearTimeout(refreshTimer);
668ab5c30531atagen2026-10-25 03:13 UTC414
  });
668ab5c30531atagen2026-10-25 03:13 UTC415
</script>
668ab5c30531atagen2026-10-25 03:13 UTC416
668ab5c30531atagen2026-10-25 03:13 UTC417
<section class="mentions-inbox">
668ab5c30531atagen2026-10-25 03:13 UTC418
  {#if selected}
668ab5c30531atagen2026-10-25 03:13 UTC419
    {#if error}<div class="error" role="alert"><EmojiText text={error} /><button disabled={loadingContext} onclick={() => void loadContext(selected!)}>Retry</button></div>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC420
    {#if saved?.context}
fe847416ebd8atagen2026-10-27 03:27 UTC421
      <ContextTimeline context={saved.context} roomId={selected.key.room_id} eventId={selected.key.event_id} roomName={roomName(selected)} {self} canPaginate={contextCanPaginate} onClose={backToList} {onLive} />
668ab5c30531atagen2026-10-25 03:13 UTC422
      {#if selected.capture.kind === 'Partial' || selected.capture.kind === 'Failed' || selected.capture.kind === 'Unavailable' || saved.state.kind === 'Partial' || saved.state.kind === 'Failed'}<button class="capture-retry" disabled={!selectedRoom || actionBusy} onclick={retryCapture}>Retry context capture</button>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC423
      {#if !contextCanPaginate}<p class="status">This room is no longer joined. Saved context remains available.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC424
      {#if saved.state.kind === 'Partial'}<p class="status">This saved context is partial.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC425
      {#if saved.state.kind === 'Pending'}<p class="status">Saving context…</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC426
      {#if saved.state.kind === 'Failed'}<p class="status" role="alert"><EmojiText text={saved.state.message} /></p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC427
    {:else}
668ab5c30531atagen2026-10-25 03:13 UTC428
      <header><button onclick={backToList}>Back to mentions</button><strong><EmojiText text={roomName(selected)} /></strong></header>
668ab5c30531atagen2026-10-25 03:13 UTC429
      {#if loadingContext}<p class="status">Loading saved context…</p>
668ab5c30531atagen2026-10-25 03:13 UTC430
      {:else if saved?.state.kind === 'Failed'}<p class="status" role="alert"><EmojiText text={saved.state.message} /></p>
668ab5c30531atagen2026-10-25 03:13 UTC431
      {:else if saved?.state.kind === 'Unavailable'}<p class="status">Saved context is unavailable.</p>
668ab5c30531atagen2026-10-25 03:13 UTC432
      {:else if saved?.state.kind === 'Partial'}<p class="status">Saved context is partial and currently unavailable.</p>
668ab5c30531atagen2026-10-25 03:13 UTC433
      {:else}<p class="status">Saved context is not available yet.</p>{/if}
fe847416ebd8atagen2026-10-27 03:27 UTC434
      {@const preview = itemEvent(selected.event)}
668ab5c30531atagen2026-10-25 03:13 UTC435
      {#if preview}<MessageRow itemId={preview.item_id} event={preview} showSender={true} reacting={false} onReact={() => {}} readOnly={true} showSent={false} {self} senderAvatar={preview.sender.avatar} />{/if}
668ab5c30531atagen2026-10-25 03:13 UTC436
      {#if selected.capture.kind === 'Failed' || selected.capture.kind === 'Partial' || selected.capture.kind === 'Unavailable'}
668ab5c30531atagen2026-10-25 03:13 UTC437
        <button disabled={!selectedRoom || actionBusy} onclick={retryCapture}>Retry context capture</button>
668ab5c30531atagen2026-10-25 03:13 UTC438
      {/if}
668ab5c30531atagen2026-10-25 03:13 UTC439
    {/if}
668ab5c30531atagen2026-10-25 03:13 UTC440
  {:else}
668ab5c30531atagen2026-10-25 03:13 UTC441
    <header><h2>Mentions {#if page}<span>({unreadCount} unread)</span>{/if}</h2><button disabled={!page || unreadCount === 0 || actionBusy} onclick={markAllRead}>Mark all read</button></header>
668ab5c30531atagen2026-10-25 03:13 UTC442
    <details class="coverage">
249e439c27e5atagen2026-10-25 13:26 UTC443
      <summary>{page?.coverage.recovering ? 'Recovering mention history…' : 'History coverage'}{#if page?.coverage.gaps.length} · Incomplete{/if}</summary>
668ab5c30531atagen2026-10-25 03:13 UTC444
      <div class="coverage-body">
668ab5c30531atagen2026-10-25 03:13 UTC445
        {#if page}
668ab5c30531atagen2026-10-25 03:13 UTC446
          {#if page.coverage.recovering}<p>History recovery is in progress.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC447
          {#if page.coverage.truncated}<p>Results are truncated.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC448
          {#if page.coverage.historical_supported === false}<p>Historical mention search is unsupported.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC449
          {#if page.coverage.unresolved_candidates}<p>{page.coverage.unresolved_candidates} possible mentions could not be resolved.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC450
          {#if page.coverage.gaps.length}<p>{page.coverage.gaps.length} history gaps remain.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC451
          {#if page.coverage.earliest_timestamp_ms}<p>Oldest observed event from {new Date(page.coverage.earliest_timestamp_ms).toLocaleString()}.</p>{/if}
249e439c27e5atagen2026-10-25 13:26 UTC452
          {#each page.coverage.gaps as gap}<p><EmojiText text={gap.room_id ? joinedRooms.get(gap.room_id)?.name ?? gap.room_id : 'Unknown room'} /> · {gapLabel(gap.reason)}</p>{/each}
668ab5c30531atagen2026-10-25 03:13 UTC453
        {:else}<p>Coverage is loading.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC454
        <button disabled={actionBusy || page?.coverage.recovering} onclick={recover}>Recover history</button>
668ab5c30531atagen2026-10-25 03:13 UTC455
      </div>
668ab5c30531atagen2026-10-25 03:13 UTC456
    </details>
668ab5c30531atagen2026-10-25 03:13 UTC457
    {#if error}<div class="error" role="alert"><EmojiText text={error} /><button disabled={busy} onclick={() => fetchRange(depth, ++generation, self)}>Retry</button></div>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC458
    <div class="entries" use:bindViewport onscroll={() => { if (!viewport?.consumeScroll()) viewport?.capture(); }}>
668ab5c30531atagen2026-10-25 03:13 UTC459
      <div class="entry-content">
668ab5c30531atagen2026-10-25 03:13 UTC460
      {#each entries as entry (keyOf(entry))}
fe847416ebd8atagen2026-10-27 03:27 UTC461
        {@const event = itemEvent(entry.event)}
668ab5c30531atagen2026-10-25 03:13 UTC462
        <article class:unread={!entry.read}>
668ab5c30531atagen2026-10-25 03:13 UTC463
          <div class="entry-head"><button class="room" onclick={() => openContext(entry)}><EmojiText text={roomName(entry)} /></button><time>{new Date(entry.timestamp_ms).toLocaleString()}</time><span>{entry.read ? 'Read' : 'Unread'}</span></div>
668ab5c30531atagen2026-10-25 03:13 UTC464
          <div class="labels">{#each entry.reasons as reason}<span>{reasonLabel(reason)}</span>{/each}<span>{captureLabel(entry.capture)}</span>{#if entry.notification_suppressed}<span>Notifications suppressed</span>{/if}</div>
668ab5c30531atagen2026-10-25 03:13 UTC465
          {#if event}<MessageRow itemId={keyOf(entry)} {event} showSender={true} reacting={false} onReact={() => {}} readOnly={true} showSent={false} {self} senderAvatar={event.sender.avatar} />{:else}<p>Mention message unavailable</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC466
          <div class="entry-actions"><button onclick={() => openContext(entry)}>Open saved context</button><button disabled={actionBusy} onclick={() => void setRead(entry, !entry.read)}>{entry.read ? 'Mark unread' : 'Mark read'}</button>{#if entry.capture.kind === 'Failed' || entry.capture.kind === 'Partial' || entry.capture.kind === 'Unavailable'}<button disabled={!joinedRooms.has(entry.key.room_id) || actionBusy} onclick={() => void retryEntry(entry)}>Retry capture</button>{/if}</div>
668ab5c30531atagen2026-10-25 03:13 UTC467
        </article>
668ab5c30531atagen2026-10-25 03:13 UTC468
      {/each}
668ab5c30531atagen2026-10-25 03:13 UTC469
      </div>
668ab5c30531atagen2026-10-25 03:13 UTC470
    </div>
668ab5c30531atagen2026-10-25 03:13 UTC471
    <footer><button disabled={!page?.next_cursor || page.end_reached || busy} onclick={loadMore}>{busy ? 'Loading…' : 'Load older mentions'}</button></footer>
668ab5c30531atagen2026-10-25 03:13 UTC472
    {#if entries.length === 0 && !busy && !error}<p class="status">No mentions yet.</p>{/if}
668ab5c30531atagen2026-10-25 03:13 UTC473
  {/if}
668ab5c30531atagen2026-10-25 03:13 UTC474
</section>
668ab5c30531atagen2026-10-25 03:13 UTC475
668ab5c30531atagen2026-10-25 03:13 UTC476
<style>
668ab5c30531atagen2026-10-25 03:13 UTC477
  .mentions-inbox { display:flex; flex-direction:column; min-width:0; min-height:0; height:100%; color:var(--text); }
668ab5c30531atagen2026-10-25 03:13 UTC478
  header { display:flex; align-items:center; gap:.6rem; padding:.6rem; border-bottom:1px solid var(--border); }
668ab5c30531atagen2026-10-25 03:13 UTC479
  header h2 { flex:1; margin:0; font-size:1rem; }
668ab5c30531atagen2026-10-25 03:13 UTC480
  header h2 span { color:var(--muted); font-size:.85em; }
668ab5c30531atagen2026-10-25 03:13 UTC481
  button { color:var(--text); background:var(--panel); border:1px solid var(--border); border-radius:.4rem; padding:.4rem .65rem; cursor:pointer; }
668ab5c30531atagen2026-10-25 03:13 UTC482
  button:disabled { opacity:.55; cursor:default; }
668ab5c30531atagen2026-10-25 03:13 UTC483
  .entries { flex:1; min-height:0; overflow:auto; overflow-anchor:none; padding:.5rem; }
668ab5c30531atagen2026-10-25 03:13 UTC484
  article { border:1px solid var(--border); border-radius:.6rem; padding:.5rem; margin-bottom:.6rem; }
668ab5c30531atagen2026-10-25 03:13 UTC485
  article.unread { border-color:var(--accent); }
668ab5c30531atagen2026-10-25 03:13 UTC486
  .entry-head,.entry-actions,.labels { display:flex; align-items:center; gap:.5rem; flex-wrap:wrap; }
20fe182f3204atagen2026-10-26 05:50 UTC487
  .entry-head .room { font-weight:600; text-align:left; }
668ab5c30531atagen2026-10-25 03:13 UTC488
  .entry-head time,.entry-head span { color:var(--muted); font-size:.8rem; }
668ab5c30531atagen2026-10-25 03:13 UTC489
  .entry-head time { margin-left:auto; }
668ab5c30531atagen2026-10-25 03:13 UTC490
  .labels { margin:.35rem 0; color:var(--muted); font-size:.78rem; }
668ab5c30531atagen2026-10-25 03:13 UTC491
  .labels span { border:1px solid var(--border); border-radius:1rem; padding:.1rem .4rem; }
668ab5c30531atagen2026-10-25 03:13 UTC492
  .entry-actions { justify-content:flex-end; margin-top:.4rem; }
668ab5c30531atagen2026-10-25 03:13 UTC493
  footer { display:flex; justify-content:center; padding:.45rem; }
668ab5c30531atagen2026-10-25 03:13 UTC494
  .coverage { padding:.55rem .75rem; background:var(--panel); border-bottom:1px solid var(--border); }
668ab5c30531atagen2026-10-25 03:13 UTC495
  .coverage-body { max-height:min(15rem, 35vh); overflow:auto; }
668ab5c30531atagen2026-10-25 03:13 UTC496
  .coverage p,.status { margin:.25rem 0; color:var(--muted); }
668ab5c30531atagen2026-10-25 03:13 UTC497
  .error { display:flex; align-items:center; gap:.5rem; padding:.5rem; color:var(--danger); }
668ab5c30531atagen2026-10-25 03:13 UTC498
  .capture-retry { align-self:flex-start; margin:.4rem; }
668ab5c30531atagen2026-10-25 03:13 UTC499
</style>