atagen

malice

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