atagen

malice

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

Blame: web/src/App.svelte

973f8fbdaf80atagen2026-09-28 09:10 UTC1
<script lang="ts">
973f8fbdaf80atagen2026-09-28 09:10 UTC2
  import { onMount, tick } from 'svelte';
d4c0d65f690aatagen2026-10-24 12:50 UTC3
  import { fade, fly } from 'svelte/transition';
973f8fbdaf80atagen2026-09-28 09:10 UTC4
  import LoginPanel from './lib/LoginPanel.svelte';
973f8fbdaf80atagen2026-09-28 09:10 UTC5
  import MessageRow from './lib/MessageRow.svelte';
668ab5c30531atagen2026-10-25 03:13 UTC6
  import MentionsInbox from './lib/MentionsInbox.svelte';
9f996e377406atagen2026-10-25 03:32 UTC7
  import HistoryRepairPanel from './lib/HistoryRepairPanel.svelte';
9f996e377406atagen2026-10-25 03:32 UTC8
  import type { HistoryRepairPolicy, HistoryRepairReport } from './lib/repair-model';
973f8fbdaf80atagen2026-09-28 09:10 UTC9
  import MxcAvatar from './lib/MxcAvatar.svelte';
7cca1d5628d1atagen2026-10-24 07:36 UTC10
  import PinButton from './lib/PinButton.svelte';
d8624c214c04atagen2026-10-24 08:24 UTC11
  import ContextMenu, { type MenuItem } from './lib/ContextMenu.svelte';
d095131eec0eatagen2026-10-24 08:39 UTC12
  import StickerPicker from './lib/StickerPicker.svelte';
d095131eec0eatagen2026-10-24 08:39 UTC13
  import PackManager from './lib/PackManager.svelte';
d095131eec0eatagen2026-10-24 08:39 UTC14
  import { clonePackDestinations, editableChoices, shortcodeFor } from './lib/packs';
d095131eec0eatagen2026-10-24 08:39 UTC15
  import type { CommandRequest } from './lib/transport';
d8624c214c04atagen2026-10-24 08:24 UTC16
  import UserCard, { type UserAction } from './lib/UserCard.svelte';
dfd1feaae855atagen2026-10-24 10:54 UTC17
  import { allowed, canRedact, groupMembers, isMuted, parsePowerLevels, type PowerLevels } from './lib/permissions';
7cca1d5628d1atagen2026-10-24 07:36 UTC18
  import { moveBefore, pinnedFirst, sortSpaces } from './lib/rail-order';
cf23dbf4e77catagen2026-10-23 06:36 UTC19
  import ImageLightbox from './lib/ImageLightbox.svelte';
cf23dbf4e77catagen2026-10-23 06:36 UTC20
  import { lightbox } from './lib/lightbox';
973f8fbdaf80atagen2026-09-28 09:10 UTC21
  import SecurityPanel from './lib/SecurityPanel.svelte';
973f8fbdaf80atagen2026-09-28 09:10 UTC22
  import {
973f8fbdaf80atagen2026-09-28 09:10 UTC23
    closeRoom,
973f8fbdaf80atagen2026-09-28 09:10 UTC24
    createRoom,
973f8fbdaf80atagen2026-09-28 09:10 UTC25
    getEncryption,
973f8fbdaf80atagen2026-09-28 09:10 UTC26
    getMembers,
973f8fbdaf80atagen2026-09-28 09:10 UTC27
    getProfile,
973f8fbdaf80atagen2026-09-28 09:10 UTC28
    getRooms,
973f8fbdaf80atagen2026-09-28 09:10 UTC29
    getSession,
973f8fbdaf80atagen2026-09-28 09:10 UTC30
    getSpaceChildren,
9f996e377406atagen2026-10-25 03:32 UTC31
    historyRepair,
9f996e377406atagen2026-10-25 03:32 UTC32
    continueHistoryRepair,
9f996e377406atagen2026-10-25 03:32 UTC33
    cancelHistoryRepair,
9f996e377406atagen2026-10-25 03:32 UTC34
    startRecentHistory,
973f8fbdaf80atagen2026-09-28 09:10 UTC35
    joinRoom,
973f8fbdaf80atagen2026-09-28 09:10 UTC36
    leaveRoom,
973f8fbdaf80atagen2026-09-28 09:10 UTC37
    logout,
973f8fbdaf80atagen2026-09-28 09:10 UTC38
    markRead,
973f8fbdaf80atagen2026-09-28 09:10 UTC39
    openRoom,
973f8fbdaf80atagen2026-09-28 09:10 UTC40
    paginateRoom,
973f8fbdaf80atagen2026-09-28 09:10 UTC41
    reactToMessage,
e4c64c36f105atagen2026-10-24 07:09 UTC42
    runCommand,
e4c64c36f105atagen2026-10-24 07:09 UTC43
    sendMessage,
cf23dbf4e77catagen2026-10-23 06:36 UTC44
    uploadAttachment,
e4c64c36f105atagen2026-10-24 07:09 UTC45
    uploadAvatar,
6c8fd192fb8catagen2026-10-24 08:20 UTC46
    uploadRoomAvatar,
05a48e9e7942atagen2026-10-24 09:32 UTC47
    editMessage,
05a48e9e7942atagen2026-10-24 09:32 UTC48
    mediaUrl
973f8fbdaf80atagen2026-09-28 09:10 UTC49
  } from './lib/api';
05a48e9e7942atagen2026-10-24 09:32 UTC50
  import EmojiText from './lib/EmojiText.svelte';
05a48e9e7942atagen2026-10-24 09:32 UTC51
  import { loadEmoji, type EmojiEntry } from './lib/emoji';
05a48e9e7942atagen2026-10-24 09:32 UTC52
  import { completeShortcode, customEmotes, emoteQueryAt, rankEmotes, resolveEmotes, type EmoteCandidate, type EmoteQuery } from './lib/emotes';
05a48e9e7942atagen2026-10-24 09:32 UTC53
  import { COMMAND_USAGE, commandQueryAt, isKnownCommand, matchCommands, parseCommand, splitTarget, unescapeCommand } from './lib/commands';
05a48e9e7942atagen2026-10-24 09:32 UTC54
  import type { CommandName } from './lib/commands';
e4c64c36f105atagen2026-10-24 07:09 UTC55
  import type { ParsedCommand } from './lib/commands';
973f8fbdaf80atagen2026-09-28 09:10 UTC56
  import {
973f8fbdaf80atagen2026-09-28 09:10 UTC57
    banners,
973f8fbdaf80atagen2026-09-28 09:10 UTC58
    blocked,
973f8fbdaf80atagen2026-09-28 09:10 UTC59
    connectEvents,
973f8fbdaf80atagen2026-09-28 09:10 UTC60
    connection,
973f8fbdaf80atagen2026-09-28 09:10 UTC61
    disconnectEvents,
973f8fbdaf80atagen2026-09-28 09:10 UTC62
    dismissBanner,
973f8fbdaf80atagen2026-09-28 09:10 UTC63
    encryption,
973f8fbdaf80atagen2026-09-28 09:10 UTC64
    membersByRoom,
973f8fbdaf80atagen2026-09-28 09:10 UTC65
    membersLoading,
668ab5c30531atagen2026-10-25 03:13 UTC66
    mentionsSnapshot,
973f8fbdaf80atagen2026-09-28 09:10 UTC67
    pushBanner,
ecb8598b38afatagen2026-10-22 09:19 UTC68
    imagePacks,
9f996e377406atagen2026-10-25 03:32 UTC69
    historyRepairs,
9f996e377406atagen2026-10-25 03:32 UTC70
    publishHistoryRepair,
973f8fbdaf80atagen2026-09-28 09:10 UTC71
    resetClientState,
973f8fbdaf80atagen2026-09-28 09:10 UTC72
    rooms,
973f8fbdaf80atagen2026-09-28 09:10 UTC73
    selectedRoomId,
973f8fbdaf80atagen2026-09-28 09:10 UTC74
    sessionUser,
973f8fbdaf80atagen2026-09-28 09:10 UTC75
    softLogout,
973f8fbdaf80atagen2026-09-28 09:10 UTC76
    timelines,
05a48e9e7942atagen2026-10-24 09:32 UTC77
    pinnedTimelines,
9f996e377406atagen2026-10-25 03:32 UTC78
    pinnedTimelineVersions,
973f8fbdaf80atagen2026-09-28 09:10 UTC79
    verification
973f8fbdaf80atagen2026-09-28 09:10 UTC80
  } from './lib/store';
973f8fbdaf80atagen2026-09-28 09:10 UTC81
  import { discardPending, pendingByRoom, queueSend, resetPending, retryPending } from './lib/pending';
973f8fbdaf80atagen2026-09-28 09:10 UTC82
  import type { PendingMessage } from './lib/pending';
6d6a4c34bdc1atagen2026-10-24 06:51 UTC83
  import { insideOpenFence } from './lib/markdown';
1b586ca05859atagen2026-10-25 02:37 UTC84
  import { TimelineViewport } from './lib/timeline-viewport';
2021154f9e16atagen2026-10-25 02:37 UTC85
  import ComposerText from './lib/ComposerText.svelte';
05a48e9e7942atagen2026-10-24 09:32 UTC86
  import { markMentions } from './lib/composer-marks';
cf23dbf4e77catagen2026-10-23 06:36 UTC87
  import { mentionQueryAt, mentionsFromHtml, rankPeople, resolveMentions } from './lib/mentions';
cf23dbf4e77catagen2026-10-23 06:36 UTC88
  import type { Mention, MentionQuery } from './lib/mentions';
544a170ead2catagen2026-10-20 11:47 UTC89
  import { loadQuickReactions, quickReactions, saveQuickReactions } from './lib/quick-reactions';
ecb8598b38afatagen2026-10-22 09:19 UTC90
  import {
ecb8598b38afatagen2026-10-22 09:19 UTC91
    linkPreviews,
ecb8598b38afatagen2026-10-22 09:19 UTC92
    loadUrlPreviewSettings,
ecb8598b38afatagen2026-10-22 09:19 UTC93
    requestLinkPreview,
ecb8598b38afatagen2026-10-22 09:19 UTC94
    saveUrlPreviewSettings,
ecb8598b38afatagen2026-10-22 09:19 UTC95
    urlPreviewSettings
ecb8598b38afatagen2026-10-22 09:19 UTC96
  } from './lib/link-previews';
973f8fbdaf80atagen2026-09-28 09:10 UTC97
  import { notifyTyping, stopTyping } from './lib/typing';
973f8fbdaf80atagen2026-09-28 09:10 UTC98
  import { formatDay } from './lib/format';
05a48e9e7942atagen2026-10-24 09:32 UTC99
  import {
05a48e9e7942atagen2026-10-24 09:32 UTC100
    MEMBERS_WIDTH,
05a48e9e7942atagen2026-10-24 09:32 UTC101
    SIDE_WIDTH,
05a48e9e7942atagen2026-10-24 09:32 UTC102
    lastSpaceRooms,
05a48e9e7942atagen2026-10-24 09:32 UTC103
    lineHeight,
05a48e9e7942atagen2026-10-24 09:32 UTC104
    membersWidth,
05a48e9e7942atagen2026-10-24 09:32 UTC105
    messageSpacing,
05a48e9e7942atagen2026-10-24 09:32 UTC106
    navFolded,
05a48e9e7942atagen2026-10-24 09:32 UTC107
    railFolded,
05a48e9e7942atagen2026-10-24 09:32 UTC108
    sideWidth
05a48e9e7942atagen2026-10-24 09:32 UTC109
  } from './lib/appearance';
df3c0f2b3da4atagen2026-10-22 13:07 UTC110
  import SettingsPanel from './lib/SettingsPanel.svelte';
df3c0f2b3da4atagen2026-10-22 13:07 UTC111
  import { packsForRoom, parseEncryptionState, parseOwnProfile, parseVerificationState, contentPreview, senderLabel } from './lib/types';
d095131eec0eatagen2026-10-24 08:39 UTC112
  import type { ImagePack, MemberSummary, OwnProfile, PackImage, Person, QuickReaction, ReplyReference, RoomSummary, SendState, TimelineEvent, TimelineItem } from './lib/types';
973f8fbdaf80atagen2026-09-28 09:10 UTC113
973f8fbdaf80atagen2026-09-28 09:10 UTC114
  let roomsLoading = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC115
  let booted = false;
544a170ead2catagen2026-10-20 11:47 UTC116
  let wasOnline = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC117
  let search = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC118
  let sidebarOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC119
  let membersOpen = false;
df3c0f2b3da4atagen2026-10-22 13:07 UTC120
  let replyingTo: ReplyReference | null = null;
d095131eec0eatagen2026-10-24 08:39 UTC121
  let dialog: 'join' | 'create' | 'security' | 'settings' | 'packs' | null = null;
d095131eec0eatagen2026-10-24 08:39 UTC122
  let stickersOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC123
  let joinTarget = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC124
  let joinBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC125
  let createName = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC126
  let createTopic = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC127
  let createBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC128
  let leaveBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC129
  let paginateBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC130
  let reacting = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC131
  let composer = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC132
  let drafts: Record<string, string> = {};
973f8fbdaf80atagen2026-09-28 09:10 UTC133
  let stickToBottom = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC134
  let timelineEl: HTMLElement | null = null;
1b586ca05859atagen2026-10-25 02:37 UTC135
  let timelineViewport: TimelineViewport | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC136
  let composerEl: HTMLTextAreaElement | null = null;
05a48e9e7942atagen2026-10-24 09:32 UTC137
  let marksEl: HTMLDivElement | null = null;
2021154f9e16atagen2026-10-25 02:37 UTC138
  let composerComposing = false;
05a48e9e7942atagen2026-10-24 09:32 UTC139
  $: composerMarks = markMentions(
05a48e9e7942atagen2026-10-24 09:32 UTC140
    composer,
05a48e9e7942atagen2026-10-24 09:32 UTC141
    ($selectedRoomId && pickedMentions[$selectedRoomId]) || [],
05a48e9e7942atagen2026-10-24 09:32 UTC142
    resolveEmotes(composer, roomEmotes).map((e) => `:${e.shortcode}:`)
05a48e9e7942atagen2026-10-24 09:32 UTC143
  );
973f8fbdaf80atagen2026-09-28 09:10 UTC144
  let fileInput: HTMLInputElement | null = null;
e4c64c36f105atagen2026-10-24 07:09 UTC145
  let avatarInput: HTMLInputElement | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC146
  let uploadBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC147
  let uploadName: string | null = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC148
  interface StagedAttachment {
cf23dbf4e77catagen2026-10-23 06:36 UTC149
    id: number;
cf23dbf4e77catagen2026-10-23 06:36 UTC150
    file: File;
cf23dbf4e77catagen2026-10-23 06:36 UTC151
    previewUrl: string | null;
cf23dbf4e77catagen2026-10-23 06:36 UTC152
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC153
  let staged: Record<string, StagedAttachment[]> = {};
cf23dbf4e77catagen2026-10-23 06:36 UTC154
  let editing: { roomId: string; eventId: string; original: string; stash: string } | null = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC155
  /** Everyone picked from the finder per room; only those whose name is still in the text get linked on send. */
cf23dbf4e77catagen2026-10-23 06:36 UTC156
  let pickedMentions: Record<string, Mention[]> = {};
cf23dbf4e77catagen2026-10-23 06:36 UTC157
  let mentionQuery: MentionQuery | null = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC158
  let mentionIndex = 0;
cf23dbf4e77catagen2026-10-23 06:36 UTC159
  let nextStagedId = 1;
cf23dbf4e77catagen2026-10-23 06:36 UTC160
  const WARM_ROOM_LIMIT = 8;
cf23dbf4e77catagen2026-10-23 06:36 UTC161
  /** Rooms left open after switching away so coming back is instant, least recently viewed first. */
cf23dbf4e77catagen2026-10-23 06:36 UTC162
  let warmRooms: string[] = [];
973f8fbdaf80atagen2026-09-28 09:10 UTC163
  let openReady: Record<string, boolean> = {};
973f8fbdaf80atagen2026-09-28 09:10 UTC164
  let openFailed: Record<string, string> = {};
973f8fbdaf80atagen2026-09-28 09:10 UTC165
  let membersFor: string | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC166
  let lastReadKey = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC167
  let readTimer: number | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC168
  let profile: OwnProfile | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC169
  let profileMxc: string | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC170
  let selectedSpaceId: string | null = null;
668ab5c30531atagen2026-10-25 03:13 UTC171
  let mentionsOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC172
  let spaceChildIds: string[] | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC173
  let spaceChildrenLoading = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC174
  let spaceChildrenError: string | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC175
  let avatarByUser: Record<string, string | null> = {};
11cc2db16d17atagen2026-10-24 12:36 UTC176
  let restoringRoute = false;
9f996e377406atagen2026-10-25 03:32 UTC177
  let repairPanels: Record<string, boolean> = {};
9f996e377406atagen2026-10-25 03:32 UTC178
  let repairBusy: Record<string, boolean> = {};
9f996e377406atagen2026-10-25 03:32 UTC179
  let repairCancelling: Record<string, boolean> = {};
9f996e377406atagen2026-10-25 03:32 UTC180
  let repairErrors: Record<string, string | null> = {};
9f996e377406atagen2026-10-25 03:32 UTC181
  let repairJumps: Record<string, { previous: HistoryRepairReport | null }> = {};
9f996e377406atagen2026-10-25 03:32 UTC182
  let repairAccount: string | null | undefined;
9f996e377406atagen2026-10-25 03:32 UTC183
  let repairEpoch = 0;
9f996e377406atagen2026-10-25 03:32 UTC184
  $: if ($sessionUser !== repairAccount) {
9f996e377406atagen2026-10-25 03:32 UTC185
    repairAccount = $sessionUser;
9f996e377406atagen2026-10-25 03:32 UTC186
    repairEpoch++;
9f996e377406atagen2026-10-25 03:32 UTC187
    repairPanels = {};
9f996e377406atagen2026-10-25 03:32 UTC188
    repairBusy = {};
9f996e377406atagen2026-10-25 03:32 UTC189
    repairCancelling = {};
9f996e377406atagen2026-10-25 03:32 UTC190
    repairErrors = {};
9f996e377406atagen2026-10-25 03:32 UTC191
    repairJumps = {};
9f996e377406atagen2026-10-25 03:32 UTC192
  }
9f996e377406atagen2026-10-25 03:32 UTC193
  $: currentRepair = $selectedRoomId ? $historyRepairs[$selectedRoomId] ?? null : null;
9f996e377406atagen2026-10-25 03:32 UTC194
  $: currentRepairActive = !!($selectedRoomId && repairBusy[$selectedRoomId]) || repairActive(currentRepair);
9f996e377406atagen2026-10-25 03:32 UTC195
  $: maybeJumpAfterRepair($selectedRoomId, currentRepair, repairJumps);
9f996e377406atagen2026-10-25 03:32 UTC196
  $: settleRepairCancellation($historyRepairs, repairBusy);
9f996e377406atagen2026-10-25 03:32 UTC197
9f996e377406atagen2026-10-25 03:32 UTC198
  function repairActive(report: HistoryRepairReport | null | undefined): boolean {
9f996e377406atagen2026-10-25 03:32 UTC199
    return report?.phase === 'FetchingRecent' || report?.phase === 'Bridging';
9f996e377406atagen2026-10-25 03:32 UTC200
  }
9f996e377406atagen2026-10-25 03:32 UTC201
9f996e377406atagen2026-10-25 03:32 UTC202
  function settleRepairCancellation(reports: Record<string, HistoryRepairReport>, busy: Record<string, boolean>): void {
9f996e377406atagen2026-10-25 03:32 UTC203
    for (const [roomId, report] of Object.entries(reports)) {
9f996e377406atagen2026-10-25 03:32 UTC204
      if (repairCancelling[roomId] && !busy[roomId] && !repairActive(report)) {
9f996e377406atagen2026-10-25 03:32 UTC205
        repairCancelling = { ...repairCancelling, [roomId]: false };
9f996e377406atagen2026-10-25 03:32 UTC206
      }
9f996e377406atagen2026-10-25 03:32 UTC207
    }
9f996e377406atagen2026-10-25 03:32 UTC208
  }
9f996e377406atagen2026-10-25 03:32 UTC209
9f996e377406atagen2026-10-25 03:32 UTC210
  function maybeJumpAfterRepair(roomId: string | null, report: HistoryRepairReport | null, jumps: typeof repairJumps): void {
9f996e377406atagen2026-10-25 03:32 UTC211
    if (!roomId || roomId !== $selectedRoomId || !report?.recent_available || !jumps[roomId] || report === jumps[roomId].previous) return;
9f996e377406atagen2026-10-25 03:32 UTC212
    const next = { ...repairJumps };
9f996e377406atagen2026-10-25 03:32 UTC213
    delete next[roomId];
9f996e377406atagen2026-10-25 03:32 UTC214
    repairJumps = next;
9f996e377406atagen2026-10-25 03:32 UTC215
    stickToBottom = true;
9f996e377406atagen2026-10-25 03:32 UTC216
    const epoch = repairEpoch;
9f996e377406atagen2026-10-25 03:32 UTC217
    void tick().then(() => {
9f996e377406atagen2026-10-25 03:32 UTC218
      if (epoch === repairEpoch && $selectedRoomId === roomId) scrollToBottom();
9f996e377406atagen2026-10-25 03:32 UTC219
    });
9f996e377406atagen2026-10-25 03:32 UTC220
  }
9f996e377406atagen2026-10-25 03:32 UTC221
9f996e377406atagen2026-10-25 03:32 UTC222
  async function showHistoryRepair(roomId: string): Promise<void> {
9f996e377406atagen2026-10-25 03:32 UTC223
    if ($selectedRoomId !== roomId) await selectRoom(roomId);
9f996e377406atagen2026-10-25 03:32 UTC224
    if ($selectedRoomId === roomId) repairPanels = { ...repairPanels, [roomId]: true };
9f996e377406atagen2026-10-25 03:32 UTC225
  }
9f996e377406atagen2026-10-25 03:32 UTC226
9f996e377406atagen2026-10-25 03:32 UTC227
  async function runHistoryRepair(roomId: string, action: 'start' | 'continue' | 'recent', policy: HistoryRepairPolicy | null = null): Promise<void> {
9f996e377406atagen2026-10-25 03:32 UTC228
    if (!$sessionUser || repairBusy[roomId] || repairActive($historyRepairs[roomId]) || repairCancelling[roomId]) return;
9f996e377406atagen2026-10-25 03:32 UTC229
    const account = $sessionUser;
9f996e377406atagen2026-10-25 03:32 UTC230
    const epoch = repairEpoch;
9f996e377406atagen2026-10-25 03:32 UTC231
    repairPanels = { ...repairPanels, [roomId]: true };
9f996e377406atagen2026-10-25 03:32 UTC232
    repairBusy = { ...repairBusy, [roomId]: true };
9f996e377406atagen2026-10-25 03:32 UTC233
    repairErrors = { ...repairErrors, [roomId]: null };
9f996e377406atagen2026-10-25 03:32 UTC234
    if (action !== 'continue') repairJumps = { ...repairJumps, [roomId]: { previous: $historyRepairs[roomId] ?? null } };
9f996e377406atagen2026-10-25 03:32 UTC235
    try {
9f996e377406atagen2026-10-25 03:32 UTC236
      if (!openReady[roomId]) {
9f996e377406atagen2026-10-25 03:32 UTC237
        await openRoom(roomId);
9f996e377406atagen2026-10-25 03:32 UTC238
        if ($sessionUser !== account || epoch !== repairEpoch) return;
9f996e377406atagen2026-10-25 03:32 UTC239
        openReady = { ...openReady, [roomId]: true };
9f996e377406atagen2026-10-25 03:32 UTC240
        const failures = { ...openFailed };
9f996e377406atagen2026-10-25 03:32 UTC241
        delete failures[roomId];
9f996e377406atagen2026-10-25 03:32 UTC242
        openFailed = failures;
9f996e377406atagen2026-10-25 03:32 UTC243
        touchWarmRoom(roomId);
9f996e377406atagen2026-10-25 03:32 UTC244
      }
9f996e377406atagen2026-10-25 03:32 UTC245
      if (repairCancelling[roomId]) return;
9f996e377406atagen2026-10-25 03:32 UTC246
      const report = action === 'continue' ? await continueHistoryRepair(roomId)
9f996e377406atagen2026-10-25 03:32 UTC247
        : action === 'recent' ? await startRecentHistory(roomId) : await historyRepair(roomId, policy);
9f996e377406atagen2026-10-25 03:32 UTC248
      if ($sessionUser !== account || epoch !== repairEpoch) return;
9f996e377406atagen2026-10-25 03:32 UTC249
      if (report.room_id !== roomId) throw new Error('History repair returned a different room');
9f996e377406atagen2026-10-25 03:32 UTC250
      publishHistoryRepair(report, account);
9f996e377406atagen2026-10-25 03:32 UTC251
      maybeJumpAfterRepair(roomId, report, repairJumps);
9f996e377406atagen2026-10-25 03:32 UTC252
    } catch (cause) {
9f996e377406atagen2026-10-25 03:32 UTC253
      if ($sessionUser === account && epoch === repairEpoch) {
9f996e377406atagen2026-10-25 03:32 UTC254
        repairErrors = { ...repairErrors, [roomId]: cause instanceof Error ? cause.message : 'Could not repair history' };
9f996e377406atagen2026-10-25 03:32 UTC255
      }
9f996e377406atagen2026-10-25 03:32 UTC256
    } finally {
9f996e377406atagen2026-10-25 03:32 UTC257
      if ($sessionUser === account && epoch === repairEpoch) {
9f996e377406atagen2026-10-25 03:32 UTC258
        repairBusy = { ...repairBusy, [roomId]: false };
9f996e377406atagen2026-10-25 03:32 UTC259
        repairCancelling = { ...repairCancelling, [roomId]: false };
9f996e377406atagen2026-10-25 03:32 UTC260
        if (repairJumps[roomId]) {
9f996e377406atagen2026-10-25 03:32 UTC261
          const next = { ...repairJumps };
9f996e377406atagen2026-10-25 03:32 UTC262
          delete next[roomId];
9f996e377406atagen2026-10-25 03:32 UTC263
          repairJumps = next;
9f996e377406atagen2026-10-25 03:32 UTC264
        }
9f996e377406atagen2026-10-25 03:32 UTC265
      }
9f996e377406atagen2026-10-25 03:32 UTC266
    }
9f996e377406atagen2026-10-25 03:32 UTC267
  }
9f996e377406atagen2026-10-25 03:32 UTC268
9f996e377406atagen2026-10-25 03:32 UTC269
  async function cancelRoomRepair(roomId: string): Promise<void> {
9f996e377406atagen2026-10-25 03:32 UTC270
    if (!$sessionUser || repairCancelling[roomId]) return;
9f996e377406atagen2026-10-25 03:32 UTC271
    const account = $sessionUser;
9f996e377406atagen2026-10-25 03:32 UTC272
    const epoch = repairEpoch;
9f996e377406atagen2026-10-25 03:32 UTC273
    repairCancelling = { ...repairCancelling, [roomId]: true };
9f996e377406atagen2026-10-25 03:32 UTC274
    try {
9f996e377406atagen2026-10-25 03:32 UTC275
      await cancelHistoryRepair(roomId);
9f996e377406atagen2026-10-25 03:32 UTC276
      if ($sessionUser === account && epoch === repairEpoch && !repairBusy[roomId] && !repairActive($historyRepairs[roomId])) {
9f996e377406atagen2026-10-25 03:32 UTC277
        repairCancelling = { ...repairCancelling, [roomId]: false };
9f996e377406atagen2026-10-25 03:32 UTC278
      }
9f996e377406atagen2026-10-25 03:32 UTC279
    } catch (cause) {
9f996e377406atagen2026-10-25 03:32 UTC280
      if ($sessionUser === account && epoch === repairEpoch) {
9f996e377406atagen2026-10-25 03:32 UTC281
        repairCancelling = { ...repairCancelling, [roomId]: false };
9f996e377406atagen2026-10-25 03:32 UTC282
        repairErrors = { ...repairErrors, [roomId]: cause instanceof Error ? cause.message : 'Could not cancel history repair' };
9f996e377406atagen2026-10-25 03:32 UTC283
      }
9f996e377406atagen2026-10-25 03:32 UTC284
    }
9f996e377406atagen2026-10-25 03:32 UTC285
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC286
d4c0d65f690aatagen2026-10-24 12:50 UTC287
  function motionDuration(ms: number): number {
d4c0d65f690aatagen2026-10-24 12:50 UTC288
    return typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : ms;
d4c0d65f690aatagen2026-10-24 12:50 UTC289
  }
d4c0d65f690aatagen2026-10-24 12:50 UTC290
544a170ead2catagen2026-10-20 11:47 UTC291
  // account data is read from the local cache, which is empty on a fresh device until the first sync lands
544a170ead2catagen2026-10-20 11:47 UTC292
  $: {
544a170ead2catagen2026-10-20 11:47 UTC293
    const online = $connection === 'online';
ecb8598b38afatagen2026-10-22 09:19 UTC294
    if (online && !wasOnline) {
ecb8598b38afatagen2026-10-22 09:19 UTC295
      void loadQuickReactions();
ecb8598b38afatagen2026-10-22 09:19 UTC296
      void loadUrlPreviewSettings();
ecb8598b38afatagen2026-10-22 09:19 UTC297
    }
544a170ead2catagen2026-10-20 11:47 UTC298
    wasOnline = online;
544a170ead2catagen2026-10-20 11:47 UTC299
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC300
  $: selectedRoom = $rooms.find((r) => r.room_id === $selectedRoomId) ?? null;
ecb8598b38afatagen2026-10-22 09:19 UTC301
  $: roomPacks = packsForRoom($imagePacks, $selectedRoomId);
05a48e9e7942atagen2026-10-24 09:32 UTC302
  $: roomEmotes = customEmotes(roomPacks);
ecb8598b38afatagen2026-10-22 09:19 UTC303
  $: previewsAllowed = selectedRoom !== null && (!selectedRoom.encrypted || $urlPreviewSettings.encrypted_rooms);
ecb8598b38afatagen2026-10-22 09:19 UTC304
  $: loadPreview = previewsAllowed && $selectedRoomId ? previewLoader($selectedRoomId) : null;
973f8fbdaf80atagen2026-09-28 09:10 UTC305
  $: spaceRooms = $rooms.filter((r) => r.space);
cf23dbf4e77catagen2026-10-23 06:36 UTC306
  $: spaceParents = parentSpaceMap(spaceRooms);
cf23dbf4e77catagen2026-10-23 06:36 UTC307
  $: railSpaces = spaceRooms.filter((s) => !spaceParents.has(s.room_id));
7cca1d5628d1atagen2026-10-24 07:36 UTC308
  let railOverride: string[] | null = null;
7cca1d5628d1atagen2026-10-24 07:36 UTC309
  $: if (railOverride && sortSpaces(railSpaces, null).map((s) => s.room_id).join() === railOverride.join()) railOverride = null;
7cca1d5628d1atagen2026-10-24 07:36 UTC310
  $: orderedRail = sortSpaces(railSpaces, railOverride);
7cca1d5628d1atagen2026-10-24 07:36 UTC311
  $: pinnedRail = orderedRail.filter((s) => s.favourite);
7cca1d5628d1atagen2026-10-24 07:36 UTC312
  $: otherRail = orderedRail.filter((s) => !s.favourite);
cf23dbf4e77catagen2026-10-23 06:36 UTC313
  $: railSelected = selectedSpaceId ? topSpaceOf(selectedSpaceId, spaceParents) : null;
973f8fbdaf80atagen2026-09-28 09:10 UTC314
  $: invites = $rooms.filter((r) => r.membership === 'Invited');
973f8fbdaf80atagen2026-09-28 09:10 UTC315
  $: query = search.trim().toLowerCase();
973f8fbdaf80atagen2026-09-28 09:10 UTC316
  $: selectedSpace = selectedSpaceId ? ($rooms.find((r) => r.room_id === selectedSpaceId) ?? null) : null;
973f8fbdaf80atagen2026-09-28 09:10 UTC317
  // While a space's children load (or fail), show no channels rather than the
973f8fbdaf80atagen2026-09-28 09:10 UTC318
  // full list — listing everything would falsely imply it belongs to the space.
f12c7de2a3abatagen2026-10-23 08:10 UTC319
  $: baseRooms = selectedSpaceId ? (spaceChildIds ? $rooms.filter((r) => spaceChildIds?.includes(r.room_id)) : []) : $rooms;
973f8fbdaf80atagen2026-09-28 09:10 UTC320
  $: visibleRooms = query
973f8fbdaf80atagen2026-09-28 09:10 UTC321
    ? baseRooms.filter(
973f8fbdaf80atagen2026-09-28 09:10 UTC322
        (r) =>
973f8fbdaf80atagen2026-09-28 09:10 UTC323
          r.name.toLowerCase().includes(query) || r.room_id.toLowerCase().includes(query)
973f8fbdaf80atagen2026-09-28 09:10 UTC324
      )
973f8fbdaf80atagen2026-09-28 09:10 UTC325
    : baseRooms;
7cca1d5628d1atagen2026-10-24 07:36 UTC326
  $: directRooms = pinnedFirst(visibleRooms.filter((r) => r.direct && !r.space && r.membership !== 'Invited'));
7cca1d5628d1atagen2026-10-24 07:36 UTC327
  $: groupRooms = pinnedFirst(visibleRooms.filter((r) => !r.direct && !r.space && r.membership !== 'Invited'));
7cca1d5628d1atagen2026-10-24 07:36 UTC328
  $: spaceList = pinnedFirst(visibleRooms.filter((r) => r.space && r.membership !== 'Invited'));
973f8fbdaf80atagen2026-09-28 09:10 UTC329
  $: channelRooms = baseRooms.filter((r) => !r.space && r.membership !== 'Invited');
973f8fbdaf80atagen2026-09-28 09:10 UTC330
  $: recoveryBanner = $encryption && ($encryption.recovery === 'Disabled' || $encryption.recovery === 'Incomplete') ? $encryption : null;
973f8fbdaf80atagen2026-09-28 09:10 UTC331
  $: verificationBanner = $verification && $verification.kind !== 'Done' ? $verification : null;
973f8fbdaf80atagen2026-09-28 09:10 UTC332
  $: items = $selectedRoomId ? ($timelines[$selectedRoomId] ?? []) : [];
cf23dbf4e77catagen2026-10-23 06:36 UTC333
  $: currentStaged = $selectedRoomId ? (staged[$selectedRoomId] ?? []) : [];
973f8fbdaf80atagen2026-09-28 09:10 UTC334
  $: members = $selectedRoomId ? ($membersByRoom[$selectedRoomId] ?? []) : [];
dfd1feaae855atagen2026-10-24 10:54 UTC335
  $: memberGroups = groupMembers(members, roomLevels);
df3c0f2b3da4atagen2026-10-22 13:07 UTC336
  $: people = peopleIn(items, members);
cf23dbf4e77catagen2026-10-23 06:36 UTC337
  $: mentionCandidates = mentionQuery ? rankPeople(Object.values(people), mentionQuery.query, $sessionUser ?? null) : [];
cf23dbf4e77catagen2026-10-23 06:36 UTC338
  $: if (mentionIndex >= mentionCandidates.length) mentionIndex = 0;
973f8fbdaf80atagen2026-09-28 09:10 UTC339
  $: hasStart = items.some((i) => i.kind === 'start');
973f8fbdaf80atagen2026-09-28 09:10 UTC340
  $: grouped = buildGroups(items);
df3c0f2b3da4atagen2026-10-22 13:07 UTC341
  $: lastSentId = lastOwnSent(items);
973f8fbdaf80atagen2026-09-28 09:10 UTC342
  $: pendingItems = $selectedRoomId ? ($pendingByRoom[$selectedRoomId] ?? []) : [];
973f8fbdaf80atagen2026-09-28 09:10 UTC343
  $: lastRealOwn = lastSenderIsOwn(items);
973f8fbdaf80atagen2026-09-28 09:10 UTC344
973f8fbdaf80atagen2026-09-28 09:10 UTC345
  function lastSenderIsOwn(list: TimelineItem[]): boolean {
973f8fbdaf80atagen2026-09-28 09:10 UTC346
    for (let i = list.length - 1; i >= 0; i -= 1) {
973f8fbdaf80atagen2026-09-28 09:10 UTC347
      const it = list[i];
973f8fbdaf80atagen2026-09-28 09:10 UTC348
      if (it.kind === 'event') return it.event.sender.user_id === $sessionUser;
973f8fbdaf80atagen2026-09-28 09:10 UTC349
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC350
    return false;
973f8fbdaf80atagen2026-09-28 09:10 UTC351
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC352
973f8fbdaf80atagen2026-09-28 09:10 UTC353
  function pendingShowSender(index: number): boolean {
973f8fbdaf80atagen2026-09-28 09:10 UTC354
    return index === 0 ? !lastRealOwn : false;
973f8fbdaf80atagen2026-09-28 09:10 UTC355
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC356
973f8fbdaf80atagen2026-09-28 09:10 UTC357
  function pendingToEvent(p: PendingMessage): TimelineEvent {
973f8fbdaf80atagen2026-09-28 09:10 UTC358
    const state: SendState = p.status === 'failed' ? { kind: 'Failed', will_retry: false } : { kind: 'Sending' };
973f8fbdaf80atagen2026-09-28 09:10 UTC359
    return {
973f8fbdaf80atagen2026-09-28 09:10 UTC360
      item_id: `pending-${p.id}`,
973f8fbdaf80atagen2026-09-28 09:10 UTC361
      event_id: null,
973f8fbdaf80atagen2026-09-28 09:10 UTC362
      transaction_id: p.id,
973f8fbdaf80atagen2026-09-28 09:10 UTC363
      sender: {
973f8fbdaf80atagen2026-09-28 09:10 UTC364
        user_id: $sessionUser ?? '',
973f8fbdaf80atagen2026-09-28 09:10 UTC365
        display_name: profile?.display_name ?? null,
973f8fbdaf80atagen2026-09-28 09:10 UTC366
        avatar: null,
973f8fbdaf80atagen2026-09-28 09:10 UTC367
        name_ambiguous: false
973f8fbdaf80atagen2026-09-28 09:10 UTC368
      },
973f8fbdaf80atagen2026-09-28 09:10 UTC369
      timestamp_ms: p.createdAt,
973f8fbdaf80atagen2026-09-28 09:10 UTC370
      own: true,
973f8fbdaf80atagen2026-09-28 09:10 UTC371
      send_state: state,
973f8fbdaf80atagen2026-09-28 09:10 UTC372
      content: {
973f8fbdaf80atagen2026-09-28 09:10 UTC373
        kind: 'Message',
6d6a4c34bdc1atagen2026-10-24 06:51 UTC374
        message: { kind: 'Text', body: p.body, geo_uri: null, formatted_body: p.formatted, edited: false, media: null, link_previews: [] }
973f8fbdaf80atagen2026-09-28 09:10 UTC375
      },
df3c0f2b3da4atagen2026-10-22 13:07 UTC376
      reply_to: p.replyTo,
973f8fbdaf80atagen2026-09-28 09:10 UTC377
      thread_root: null,
973f8fbdaf80atagen2026-09-28 09:10 UTC378
      thread_summary: null,
973f8fbdaf80atagen2026-09-28 09:10 UTC379
      reactions: [],
973f8fbdaf80atagen2026-09-28 09:10 UTC380
      read_by: [],
973f8fbdaf80atagen2026-09-28 09:10 UTC381
      editable: false
973f8fbdaf80atagen2026-09-28 09:10 UTC382
    };
973f8fbdaf80atagen2026-09-28 09:10 UTC383
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC384
973f8fbdaf80atagen2026-09-28 09:10 UTC385
  interface Group {
973f8fbdaf80atagen2026-09-28 09:10 UTC386
    key: string;
973f8fbdaf80atagen2026-09-28 09:10 UTC387
    item: TimelineItem;
973f8fbdaf80atagen2026-09-28 09:10 UTC388
    showSender: boolean;
973f8fbdaf80atagen2026-09-28 09:10 UTC389
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC390
df3c0f2b3da4atagen2026-10-22 13:07 UTC391
  function lastOwnSent(list: TimelineItem[]): string | null {
df3c0f2b3da4atagen2026-10-22 13:07 UTC392
    for (let i = list.length - 1; i >= 0; i--) {
df3c0f2b3da4atagen2026-10-22 13:07 UTC393
      const item = list[i];
df3c0f2b3da4atagen2026-10-22 13:07 UTC394
      if (item.kind === 'event' && item.event.own && item.event.send_state.kind === 'Sent') return item.event.item_id;
df3c0f2b3da4atagen2026-10-22 13:07 UTC395
    }
df3c0f2b3da4atagen2026-10-22 13:07 UTC396
    return null;
df3c0f2b3da4atagen2026-10-22 13:07 UTC397
  }
df3c0f2b3da4atagen2026-10-22 13:07 UTC398
973f8fbdaf80atagen2026-09-28 09:10 UTC399
  function buildGroups(list: TimelineItem[]): Group[] {
973f8fbdaf80atagen2026-09-28 09:10 UTC400
    const out: Group[] = [];
973f8fbdaf80atagen2026-09-28 09:10 UTC401
    let prevSender: string | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC402
    let prevTs = 0;
973f8fbdaf80atagen2026-09-28 09:10 UTC403
    list.forEach((item, index) => {
973f8fbdaf80atagen2026-09-28 09:10 UTC404
      let showSender = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC405
      if (item.kind === 'event') {
973f8fbdaf80atagen2026-09-28 09:10 UTC406
        const e = item.event;
973f8fbdaf80atagen2026-09-28 09:10 UTC407
        showSender =
973f8fbdaf80atagen2026-09-28 09:10 UTC408
          prevSender !== e.sender.user_id || Math.abs(e.timestamp_ms - prevTs) > 5 * 60 * 1000;
973f8fbdaf80atagen2026-09-28 09:10 UTC409
        prevSender = e.sender.user_id;
973f8fbdaf80atagen2026-09-28 09:10 UTC410
        prevTs = e.timestamp_ms;
973f8fbdaf80atagen2026-09-28 09:10 UTC411
        out.push({ key: e.item_id || e.event_id || `m-${index}`, item, showSender });
973f8fbdaf80atagen2026-09-28 09:10 UTC412
      } else {
973f8fbdaf80atagen2026-09-28 09:10 UTC413
        prevSender = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC414
        out.push({ key: `${item.kind}-${index}`, item, showSender });
973f8fbdaf80atagen2026-09-28 09:10 UTC415
      }
973f8fbdaf80atagen2026-09-28 09:10 UTC416
    });
973f8fbdaf80atagen2026-09-28 09:10 UTC417
    return out;
973f8fbdaf80atagen2026-09-28 09:10 UTC418
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC419
973f8fbdaf80atagen2026-09-28 09:10 UTC420
  function roomUnread(r: RoomSummary): number {
973f8fbdaf80atagen2026-09-28 09:10 UTC421
    return r.unread_messages + r.unread_mentions;
973f8fbdaf80atagen2026-09-28 09:10 UTC422
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC423
668ab5c30531atagen2026-10-25 03:13 UTC424
  function recordRoute(spaceId: string | null, roomId: string | null, view?: string): void {
11cc2db16d17atagen2026-10-24 12:36 UTC425
    if (restoringRoute) return;
11cc2db16d17atagen2026-10-24 12:36 UTC426
    const url = new URL(window.location.href);
11cc2db16d17atagen2026-10-24 12:36 UTC427
    url.searchParams.delete('space');
11cc2db16d17atagen2026-10-24 12:36 UTC428
    url.searchParams.delete('room');
668ab5c30531atagen2026-10-25 03:13 UTC429
    url.searchParams.delete('view');
668ab5c30531atagen2026-10-25 03:13 UTC430
    if (view) url.searchParams.set('view', view);
11cc2db16d17atagen2026-10-24 12:36 UTC431
    if (spaceId) url.searchParams.set('space', spaceId);
11cc2db16d17atagen2026-10-24 12:36 UTC432
    if (roomId) url.searchParams.set('room', roomId);
11cc2db16d17atagen2026-10-24 12:36 UTC433
    const next = `${url.pathname}${url.search}${url.hash}`;
11cc2db16d17atagen2026-10-24 12:36 UTC434
    const current = `${window.location.pathname}${window.location.search}${window.location.hash}`;
11cc2db16d17atagen2026-10-24 12:36 UTC435
    if (next !== current) window.history.pushState({ spaceId, roomId }, '', next);
11cc2db16d17atagen2026-10-24 12:36 UTC436
  }
11cc2db16d17atagen2026-10-24 12:36 UTC437
11cc2db16d17atagen2026-10-24 12:36 UTC438
  async function restoreRoute(): Promise<void> {
11cc2db16d17atagen2026-10-24 12:36 UTC439
    const url = new URL(window.location.href);
11cc2db16d17atagen2026-10-24 12:36 UTC440
    const roomId = url.searchParams.get('room');
11cc2db16d17atagen2026-10-24 12:36 UTC441
    const spaceId = url.searchParams.get('space');
11cc2db16d17atagen2026-10-24 12:36 UTC442
    restoringRoute = true;
11cc2db16d17atagen2026-10-24 12:36 UTC443
    try {
668ab5c30531atagen2026-10-25 03:13 UTC444
      if (url.searchParams.get('view') === 'mentions') {
668ab5c30531atagen2026-10-25 03:13 UTC445
        selectMentions();
668ab5c30531atagen2026-10-25 03:13 UTC446
      } else if (roomId && $rooms.some((room) => room.room_id === roomId && !room.space)) {
11cc2db16d17atagen2026-10-24 12:36 UTC447
        selectedSpaceId = spaceId && $rooms.some((room) => room.room_id === spaceId && room.space) ? spaceId : null;
11cc2db16d17atagen2026-10-24 12:36 UTC448
        spaceChildrenError = null;
11cc2db16d17atagen2026-10-24 12:36 UTC449
        spaceChildIds = selectedSpaceId ? (await getSpaceChildren(selectedSpaceId)).room_ids ?? [] : null;
11cc2db16d17atagen2026-10-24 12:36 UTC450
        await selectRoom(roomId);
11cc2db16d17atagen2026-10-24 12:36 UTC451
      } else if (spaceId && $rooms.some((room) => room.room_id === spaceId && room.space)) {
11cc2db16d17atagen2026-10-24 12:36 UTC452
        await selectSpace(spaceId);
11cc2db16d17atagen2026-10-24 12:36 UTC453
      } else {
11cc2db16d17atagen2026-10-24 12:36 UTC454
        await selectHome();
11cc2db16d17atagen2026-10-24 12:36 UTC455
      }
11cc2db16d17atagen2026-10-24 12:36 UTC456
    } catch (e) {
11cc2db16d17atagen2026-10-24 12:36 UTC457
      pushBanner(e instanceof Error ? e.message : 'Could not restore navigation');
11cc2db16d17atagen2026-10-24 12:36 UTC458
    } finally {
11cc2db16d17atagen2026-10-24 12:36 UTC459
      restoringRoute = false;
11cc2db16d17atagen2026-10-24 12:36 UTC460
    }
11cc2db16d17atagen2026-10-24 12:36 UTC461
  }
11cc2db16d17atagen2026-10-24 12:36 UTC462
973f8fbdaf80atagen2026-09-28 09:10 UTC463
  onMount(() => {
11cc2db16d17atagen2026-10-24 12:36 UTC464
    const onPopState = () => void restoreRoute();
11cc2db16d17atagen2026-10-24 12:36 UTC465
    window.addEventListener('popstate', onPopState);
973f8fbdaf80atagen2026-09-28 09:10 UTC466
    void boot();
973f8fbdaf80atagen2026-09-28 09:10 UTC467
    return () => {
11cc2db16d17atagen2026-10-24 12:36 UTC468
      window.removeEventListener('popstate', onPopState);
973f8fbdaf80atagen2026-09-28 09:10 UTC469
      disconnectEvents();
973f8fbdaf80atagen2026-09-28 09:10 UTC470
      stopTyping();
973f8fbdaf80atagen2026-09-28 09:10 UTC471
      if (readTimer !== null) window.clearTimeout(readTimer);
973f8fbdaf80atagen2026-09-28 09:10 UTC472
    };
973f8fbdaf80atagen2026-09-28 09:10 UTC473
  });
973f8fbdaf80atagen2026-09-28 09:10 UTC474
973f8fbdaf80atagen2026-09-28 09:10 UTC475
  async function boot(): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC476
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC477
      const session = await getSession();
973f8fbdaf80atagen2026-09-28 09:10 UTC478
      blocked.set(session.blocked ?? false);
973f8fbdaf80atagen2026-09-28 09:10 UTC479
      sessionUser.set(session.user_id);
973f8fbdaf80atagen2026-09-28 09:10 UTC480
      if (session.user_id) {
973f8fbdaf80atagen2026-09-28 09:10 UTC481
        softLogout.set(null);
973f8fbdaf80atagen2026-09-28 09:10 UTC482
        await refreshRooms();
11cc2db16d17atagen2026-10-24 12:36 UTC483
        await restoreRoute();
973f8fbdaf80atagen2026-09-28 09:10 UTC484
        connectEvents();
973f8fbdaf80atagen2026-09-28 09:10 UTC485
        void loadProfile();
973f8fbdaf80atagen2026-09-28 09:10 UTC486
        void loadEncryption();
544a170ead2catagen2026-10-20 11:47 UTC487
        void loadQuickReactions();
ecb8598b38afatagen2026-10-22 09:19 UTC488
        void loadUrlPreviewSettings();
973f8fbdaf80atagen2026-09-28 09:10 UTC489
      } else {
973f8fbdaf80atagen2026-09-28 09:10 UTC490
        softLogout.set(session.soft_logout ?? null);
973f8fbdaf80atagen2026-09-28 09:10 UTC491
      }
973f8fbdaf80atagen2026-09-28 09:10 UTC492
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC493
      pushBanner(e instanceof Error ? `Session check failed: ${e.message}` : 'Session check failed');
973f8fbdaf80atagen2026-09-28 09:10 UTC494
      sessionUser.set(null);
973f8fbdaf80atagen2026-09-28 09:10 UTC495
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC496
      booted = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC497
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC498
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC499
973f8fbdaf80atagen2026-09-28 09:10 UTC500
  async function refreshRooms(): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC501
    roomsLoading = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC502
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC503
      const res = await getRooms();
973f8fbdaf80atagen2026-09-28 09:10 UTC504
      rooms.set(res.rooms);
973f8fbdaf80atagen2026-09-28 09:10 UTC505
      pruneSpaceFilter();
973f8fbdaf80atagen2026-09-28 09:10 UTC506
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC507
      pushBanner(e instanceof Error ? e.message : 'Could not load rooms');
973f8fbdaf80atagen2026-09-28 09:10 UTC508
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC509
      roomsLoading = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC510
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC511
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC512
973f8fbdaf80atagen2026-09-28 09:10 UTC513
  async function loadProfile(): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC514
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC515
      const raw = await getProfile();
973f8fbdaf80atagen2026-09-28 09:10 UTC516
      profile = parseOwnProfile(raw);
973f8fbdaf80atagen2026-09-28 09:10 UTC517
      profileMxc = profile.avatar_url;
973f8fbdaf80atagen2026-09-28 09:10 UTC518
    } catch {
973f8fbdaf80atagen2026-09-28 09:10 UTC519
      profile = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC520
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC521
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC522
973f8fbdaf80atagen2026-09-28 09:10 UTC523
  async function loadEncryption(): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC524
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC525
      const res = await getEncryption();
973f8fbdaf80atagen2026-09-28 09:10 UTC526
      const state = parseEncryptionState(res.state);
973f8fbdaf80atagen2026-09-28 09:10 UTC527
      if (state) encryption.set(state);
973f8fbdaf80atagen2026-09-28 09:10 UTC528
      const verificationState = parseVerificationState(res.verification);
973f8fbdaf80atagen2026-09-28 09:10 UTC529
      if (verificationState) verification.set(verificationState);
973f8fbdaf80atagen2026-09-28 09:10 UTC530
    } catch {
973f8fbdaf80atagen2026-09-28 09:10 UTC531
      // Encryption status also arrives over SSE; a failed first fetch is not fatal.
973f8fbdaf80atagen2026-09-28 09:10 UTC532
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC533
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC534
973f8fbdaf80atagen2026-09-28 09:10 UTC535
  function afterLogin(userId: string): void {
973f8fbdaf80atagen2026-09-28 09:10 UTC536
    sessionUser.set(userId);
973f8fbdaf80atagen2026-09-28 09:10 UTC537
    softLogout.set(null);
973f8fbdaf80atagen2026-09-28 09:10 UTC538
    blocked.set(false);
973f8fbdaf80atagen2026-09-28 09:10 UTC539
    void refreshRooms();
973f8fbdaf80atagen2026-09-28 09:10 UTC540
    connectEvents();
973f8fbdaf80atagen2026-09-28 09:10 UTC541
    void loadProfile();
973f8fbdaf80atagen2026-09-28 09:10 UTC542
    void loadEncryption();
544a170ead2catagen2026-10-20 11:47 UTC543
    void loadQuickReactions();
ecb8598b38afatagen2026-10-22 09:19 UTC544
    void loadUrlPreviewSettings();
973f8fbdaf80atagen2026-09-28 09:10 UTC545
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC546
973f8fbdaf80atagen2026-09-28 09:10 UTC547
  async function doLogout(): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC548
    stopTyping();
973f8fbdaf80atagen2026-09-28 09:10 UTC549
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC550
      await logout();
973f8fbdaf80atagen2026-09-28 09:10 UTC551
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC552
      pushBanner(e instanceof Error ? e.message : 'Logout failed');
973f8fbdaf80atagen2026-09-28 09:10 UTC553
      return;
973f8fbdaf80atagen2026-09-28 09:10 UTC554
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC555
    disconnectEvents();
973f8fbdaf80atagen2026-09-28 09:10 UTC556
    resetClientState();
973f8fbdaf80atagen2026-09-28 09:10 UTC557
    softLogout.set(null);
973f8fbdaf80atagen2026-09-28 09:10 UTC558
    blocked.set(false);
973f8fbdaf80atagen2026-09-28 09:10 UTC559
    sessionUser.set(null);
cf23dbf4e77catagen2026-10-23 06:36 UTC560
    lightbox.set(null);
973f8fbdaf80atagen2026-09-28 09:10 UTC561
    composer = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC562
    drafts = {};
973f8fbdaf80atagen2026-09-28 09:10 UTC563
    dialog = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC564
    membersOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC565
    sidebarOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC566
    profile = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC567
    profileMxc = null;
668ab5c30531atagen2026-10-25 03:13 UTC568
    mentionsOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC569
    selectedSpaceId = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC570
    spaceChildIds = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC571
    spaceChildrenError = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC572
    openReady = {};
973f8fbdaf80atagen2026-09-28 09:10 UTC573
    openFailed = {};
cf23dbf4e77catagen2026-10-23 06:36 UTC574
    warmRooms = [];
cf23dbf4e77catagen2026-10-23 06:36 UTC575
    pickedMentions = {};
cf23dbf4e77catagen2026-10-23 06:36 UTC576
    mentionQuery = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC577
    clearAllStaged();
973f8fbdaf80atagen2026-09-28 09:10 UTC578
    avatarByUser = {};
973f8fbdaf80atagen2026-09-28 09:10 UTC579
    resetPending();
973f8fbdaf80atagen2026-09-28 09:10 UTC580
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC581
cf23dbf4e77catagen2026-10-23 06:36 UTC582
  /** Joined spaces that sit inside another joined space, keyed to one such parent. Either side of the link counts. */
cf23dbf4e77catagen2026-10-23 06:36 UTC583
  function parentSpaceMap(spaces: RoomSummary[]): Map<string, string> {
cf23dbf4e77catagen2026-10-23 06:36 UTC584
    const ids = new Set(spaces.map((s) => s.room_id));
cf23dbf4e77catagen2026-10-23 06:36 UTC585
    const parents = new Map<string, string>();
cf23dbf4e77catagen2026-10-23 06:36 UTC586
    for (const space of spaces) {
cf23dbf4e77catagen2026-10-23 06:36 UTC587
      for (const child of space.children) {
cf23dbf4e77catagen2026-10-23 06:36 UTC588
        if (child !== space.room_id && ids.has(child) && !parents.has(child)) parents.set(child, space.room_id);
cf23dbf4e77catagen2026-10-23 06:36 UTC589
      }
cf23dbf4e77catagen2026-10-23 06:36 UTC590
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC591
    for (const space of spaces) {
cf23dbf4e77catagen2026-10-23 06:36 UTC592
      const parent = space.parent_spaces.find((id) => id !== space.room_id && ids.has(id));
cf23dbf4e77catagen2026-10-23 06:36 UTC593
      if (parent && !parents.has(space.room_id)) parents.set(space.room_id, parent);
cf23dbf4e77catagen2026-10-23 06:36 UTC594
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC595
    for (const id of [...parents.keys()]) {
cf23dbf4e77catagen2026-10-23 06:36 UTC596
      const seen = new Set<string>([id]);
cf23dbf4e77catagen2026-10-23 06:36 UTC597
      let at = parents.get(id);
cf23dbf4e77catagen2026-10-23 06:36 UTC598
      while (at && !seen.has(at)) {
cf23dbf4e77catagen2026-10-23 06:36 UTC599
        seen.add(at);
cf23dbf4e77catagen2026-10-23 06:36 UTC600
        at = parents.get(at);
cf23dbf4e77catagen2026-10-23 06:36 UTC601
      }
cf23dbf4e77catagen2026-10-23 06:36 UTC602
      if (at) parents.delete(id);
cf23dbf4e77catagen2026-10-23 06:36 UTC603
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC604
    return parents;
cf23dbf4e77catagen2026-10-23 06:36 UTC605
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC606
cf23dbf4e77catagen2026-10-23 06:36 UTC607
  function topSpaceOf(id: string, parents: Map<string, string>): string {
cf23dbf4e77catagen2026-10-23 06:36 UTC608
    let at = id;
cf23dbf4e77catagen2026-10-23 06:36 UTC609
    while (parents.has(at)) at = parents.get(at)!;
cf23dbf4e77catagen2026-10-23 06:36 UTC610
    return at;
cf23dbf4e77catagen2026-10-23 06:36 UTC611
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC612
973f8fbdaf80atagen2026-09-28 09:10 UTC613
  function pruneSpaceFilter(): void {
973f8fbdaf80atagen2026-09-28 09:10 UTC614
    if (!selectedSpaceId) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC615
    if (!$rooms.some((r) => r.room_id === selectedSpaceId)) {
973f8fbdaf80atagen2026-09-28 09:10 UTC616
      selectedSpaceId = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC617
      spaceChildIds = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC618
      spaceChildrenError = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC619
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC620
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC621
973f8fbdaf80atagen2026-09-28 09:10 UTC622
  async function selectHome(): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC623
    mentionsOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC624
    selectedSpaceId = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC625
    spaceChildIds = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC626
    spaceChildrenError = null;
7efc4c6d41abatagen2026-10-24 11:40 UTC627
    if (window.innerWidth > 640) navFolded.set(false);
973f8fbdaf80atagen2026-09-28 09:10 UTC628
    sidebarOpen = true;
11cc2db16d17atagen2026-10-24 12:36 UTC629
    recordRoute(null, null);
973f8fbdaf80atagen2026-09-28 09:10 UTC630
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC631
668ab5c30531atagen2026-10-25 03:13 UTC632
  function selectMentions(): void {
668ab5c30531atagen2026-10-25 03:13 UTC633
    if ($selectedRoomId && composer.trim()) drafts[$selectedRoomId] = composer;
668ab5c30531atagen2026-10-25 03:13 UTC634
    stopTyping();
668ab5c30531atagen2026-10-25 03:13 UTC635
    selectedSpaceId = null;
668ab5c30531atagen2026-10-25 03:13 UTC636
    spaceChildIds = null;
668ab5c30531atagen2026-10-25 03:13 UTC637
    spaceChildrenError = null;
668ab5c30531atagen2026-10-25 03:13 UTC638
    spaceChildrenLoading = false;
668ab5c30531atagen2026-10-25 03:13 UTC639
    selectedRoomId.set(null);
668ab5c30531atagen2026-10-25 03:13 UTC640
    replyingTo = null;
668ab5c30531atagen2026-10-25 03:13 UTC641
    editing = null;
668ab5c30531atagen2026-10-25 03:13 UTC642
    mentionQuery = null;
668ab5c30531atagen2026-10-25 03:13 UTC643
    peeking = null;
668ab5c30531atagen2026-10-25 03:13 UTC644
    membersOpen = false;
668ab5c30531atagen2026-10-25 03:13 UTC645
    sidebarOpen = false;
668ab5c30531atagen2026-10-25 03:13 UTC646
    mentionsOpen = true;
668ab5c30531atagen2026-10-25 03:13 UTC647
    recordRoute(null, null, 'mentions');
668ab5c30531atagen2026-10-25 03:13 UTC648
  }
668ab5c30531atagen2026-10-25 03:13 UTC649
dfd1feaae855atagen2026-10-24 10:54 UTC650
  function toggleChannelsPane(): void {
7efc4c6d41abatagen2026-10-24 11:40 UTC651
    if (window.innerWidth <= 640) sidebarOpen = !sidebarOpen;
dfd1feaae855atagen2026-10-24 10:54 UTC652
    else navFolded.update((v) => !v);
dfd1feaae855atagen2026-10-24 10:54 UTC653
  }
dfd1feaae855atagen2026-10-24 10:54 UTC654
973f8fbdaf80atagen2026-09-28 09:10 UTC655
  async function selectSpace(spaceId: string): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC656
    mentionsOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC657
    if ($selectedRoomId && composer.trim()) drafts[$selectedRoomId] = composer;
973f8fbdaf80atagen2026-09-28 09:10 UTC658
    stopTyping();
973f8fbdaf80atagen2026-09-28 09:10 UTC659
    selectedSpaceId = spaceId;
973f8fbdaf80atagen2026-09-28 09:10 UTC660
    spaceChildIds = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC661
    spaceChildrenError = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC662
    spaceChildrenLoading = true;
fddb0bcaabebatagen2026-10-24 07:02 UTC663
    const last = $lastSpaceRooms[spaceId];
fddb0bcaabebatagen2026-10-24 07:02 UTC664
    const resume = last && $rooms.some((r) => r.room_id === last && !r.space) ? last : null;
fddb0bcaabebatagen2026-10-24 07:02 UTC665
    if (resume) {
fddb0bcaabebatagen2026-10-24 07:02 UTC666
      void selectRoom(resume);
fddb0bcaabebatagen2026-10-24 07:02 UTC667
    } else {
fddb0bcaabebatagen2026-10-24 07:02 UTC668
      selectedRoomId.set(null);
fddb0bcaabebatagen2026-10-24 07:02 UTC669
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC670
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC671
      const res = await getSpaceChildren(spaceId);
705b1e1062c2atagen2026-10-23 09:05 UTC672
      if (selectedSpaceId === spaceId) {
705b1e1062c2atagen2026-10-23 09:05 UTC673
        spaceChildIds = res.room_ids ?? [];
00075327fc57atagen2026-10-24 11:54 UTC674
        const firstChannel = spaceChildIds
00075327fc57atagen2026-10-24 11:54 UTC675
          .map((id) => $rooms.find((room) => room.room_id === id))
00075327fc57atagen2026-10-24 11:54 UTC676
          .find((room) => room && !room.space);
00075327fc57atagen2026-10-24 11:54 UTC677
        if ((!resume || !spaceChildIds.includes(resume)) && firstChannel) {
00075327fc57atagen2026-10-24 11:54 UTC678
          await selectRoom(firstChannel.room_id);
705b1e1062c2atagen2026-10-23 09:05 UTC679
        }
705b1e1062c2atagen2026-10-23 09:05 UTC680
      }
973f8fbdaf80atagen2026-09-28 09:10 UTC681
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC682
      if (selectedSpaceId === spaceId) {
973f8fbdaf80atagen2026-09-28 09:10 UTC683
        spaceChildrenError = e instanceof Error ? e.message : 'Could not load rooms in this space';
973f8fbdaf80atagen2026-09-28 09:10 UTC684
        spaceChildIds = [];
973f8fbdaf80atagen2026-09-28 09:10 UTC685
      }
973f8fbdaf80atagen2026-09-28 09:10 UTC686
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC687
      if (selectedSpaceId === spaceId) spaceChildrenLoading = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC688
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC689
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC690
d8624c214c04atagen2026-10-24 08:24 UTC691
  async function selectRoom(roomId: string, peek = false): Promise<void> {
668ab5c30531atagen2026-10-25 03:13 UTC692
    mentionsOpen = false;
d8624c214c04atagen2026-10-24 08:24 UTC693
    peeking = peek ? roomId : null;
973f8fbdaf80atagen2026-09-28 09:10 UTC694
    if ($selectedRoomId && composer.trim()) drafts[$selectedRoomId] = composer;
973f8fbdaf80atagen2026-09-28 09:10 UTC695
    if (roomId === $selectedRoomId && openReady[roomId]) {
973f8fbdaf80atagen2026-09-28 09:10 UTC696
      sidebarOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC697
      return;
973f8fbdaf80atagen2026-09-28 09:10 UTC698
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC699
    stopTyping();
705b1e1062c2atagen2026-10-23 09:05 UTC700
    const spaceId = selectedSpaceId;
705b1e1062c2atagen2026-10-23 09:05 UTC701
    if (spaceId) lastSpaceRooms.update((all) => ({ ...all, [spaceId]: roomId }));
973f8fbdaf80atagen2026-09-28 09:10 UTC702
    selectedRoomId.set(roomId);
11cc2db16d17atagen2026-10-24 12:36 UTC703
    recordRoute(selectedSpaceId, roomId);
973f8fbdaf80atagen2026-09-28 09:10 UTC704
    composer = drafts[roomId] ?? '';
df3c0f2b3da4atagen2026-10-22 13:07 UTC705
    replyingTo = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC706
    editing = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC707
    mentionQuery = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC708
    stickToBottom = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC709
    lastReadKey = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC710
    sidebarOpen = false;
cf23dbf4e77catagen2026-10-23 06:36 UTC711
    touchWarmRoom(roomId);
cf23dbf4e77catagen2026-10-23 06:36 UTC712
    if (openReady[roomId]) {
cf23dbf4e77catagen2026-10-23 06:36 UTC713
      if (membersOpen) void loadMembers(roomId);
cf23dbf4e77catagen2026-10-23 06:36 UTC714
      await tick();
cf23dbf4e77catagen2026-10-23 06:36 UTC715
      scrollToBottom();
cf23dbf4e77catagen2026-10-23 06:36 UTC716
      queueReadReceipt();
cf23dbf4e77catagen2026-10-23 06:36 UTC717
      composerEl?.focus();
cf23dbf4e77catagen2026-10-23 06:36 UTC718
      return;
cf23dbf4e77catagen2026-10-23 06:36 UTC719
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC720
    if (openFailed[roomId]) {
973f8fbdaf80atagen2026-09-28 09:10 UTC721
      const nextFailed = { ...openFailed };
973f8fbdaf80atagen2026-09-28 09:10 UTC722
      delete nextFailed[roomId];
973f8fbdaf80atagen2026-09-28 09:10 UTC723
      openFailed = nextFailed;
973f8fbdaf80atagen2026-09-28 09:10 UTC724
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC725
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC726
      await openRoom(roomId);
cf23dbf4e77catagen2026-10-23 06:36 UTC727
      if (warmRooms.includes(roomId)) openReady = { ...openReady, [roomId]: true };
973f8fbdaf80atagen2026-09-28 09:10 UTC728
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC729
      const message = e instanceof Error ? e.message : `Could not open room ${roomId}`;
973f8fbdaf80atagen2026-09-28 09:10 UTC730
      openFailed = { ...openFailed, [roomId]: message };
973f8fbdaf80atagen2026-09-28 09:10 UTC731
      pushBanner(message);
973f8fbdaf80atagen2026-09-28 09:10 UTC732
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC733
    if (membersOpen) void loadMembers(roomId);
973f8fbdaf80atagen2026-09-28 09:10 UTC734
    await tick();
973f8fbdaf80atagen2026-09-28 09:10 UTC735
    scrollToBottom();
973f8fbdaf80atagen2026-09-28 09:10 UTC736
    queueReadReceipt();
973f8fbdaf80atagen2026-09-28 09:10 UTC737
    composerEl?.focus();
973f8fbdaf80atagen2026-09-28 09:10 UTC738
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC739
cf23dbf4e77catagen2026-10-23 06:36 UTC740
  function touchWarmRoom(roomId: string): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC741
    warmRooms = [...warmRooms.filter((id) => id !== roomId), roomId];
cf23dbf4e77catagen2026-10-23 06:36 UTC742
    while (warmRooms.length > WARM_ROOM_LIMIT) {
cf23dbf4e77catagen2026-10-23 06:36 UTC743
      const evicted = warmRooms[0];
cf23dbf4e77catagen2026-10-23 06:36 UTC744
      warmRooms = warmRooms.slice(1);
cf23dbf4e77catagen2026-10-23 06:36 UTC745
      forgetOpenRoom(evicted);
cf23dbf4e77catagen2026-10-23 06:36 UTC746
      closeRoom(evicted).catch(() => undefined);
cf23dbf4e77catagen2026-10-23 06:36 UTC747
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC748
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC749
cf23dbf4e77catagen2026-10-23 06:36 UTC750
  function forgetOpenRoom(roomId: string): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC751
    warmRooms = warmRooms.filter((id) => id !== roomId);
cf23dbf4e77catagen2026-10-23 06:36 UTC752
    const nextReady = { ...openReady };
cf23dbf4e77catagen2026-10-23 06:36 UTC753
    delete nextReady[roomId];
cf23dbf4e77catagen2026-10-23 06:36 UTC754
    openReady = nextReady;
cf23dbf4e77catagen2026-10-23 06:36 UTC755
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC756
973f8fbdaf80atagen2026-09-28 09:10 UTC757
  function scrollToBottom(): void {
1b586ca05859atagen2026-10-25 02:37 UTC758
    if (timelineViewport?.element === timelineEl) timelineViewport.scrollToBottom();
1b586ca05859atagen2026-10-25 02:37 UTC759
    else if (timelineEl) timelineEl.scrollTop = timelineEl.scrollHeight;
973f8fbdaf80atagen2026-09-28 09:10 UTC760
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC761
705b1e1062c2atagen2026-10-23 09:05 UTC762
  function noteUserScroll(): void {
1b586ca05859atagen2026-10-25 02:37 UTC763
    timelineViewport?.releaseScroll();
9f996e377406atagen2026-10-25 03:32 UTC764
    if ($selectedRoomId && repairJumps[$selectedRoomId]) {
9f996e377406atagen2026-10-25 03:32 UTC765
      const next = { ...repairJumps };
9f996e377406atagen2026-10-25 03:32 UTC766
      delete next[$selectedRoomId];
9f996e377406atagen2026-10-25 03:32 UTC767
      repairJumps = next;
9f996e377406atagen2026-10-25 03:32 UTC768
    }
705b1e1062c2atagen2026-10-23 09:05 UTC769
  }
705b1e1062c2atagen2026-10-23 09:05 UTC770
2021154f9e16atagen2026-10-25 02:37 UTC771
  function syncComposer(node: HTMLTextAreaElement) {
2021154f9e16atagen2026-10-25 02:37 UTC772
    const sync = () => {
2021154f9e16atagen2026-10-25 02:37 UTC773
      if (!marksEl) return;
2021154f9e16atagen2026-10-25 02:37 UTC774
      marksEl.style.width = `${node.clientWidth}px`;
2021154f9e16atagen2026-10-25 02:37 UTC775
      marksEl.scrollTop = node.scrollTop;
2021154f9e16atagen2026-10-25 02:37 UTC776
      marksEl.scrollLeft = node.scrollLeft;
2021154f9e16atagen2026-10-25 02:37 UTC777
    };
2021154f9e16atagen2026-10-25 02:37 UTC778
    const observer = new ResizeObserver(sync);
2021154f9e16atagen2026-10-25 02:37 UTC779
    observer.observe(node);
2021154f9e16atagen2026-10-25 02:37 UTC780
    node.addEventListener('scroll', sync);
2021154f9e16atagen2026-10-25 02:37 UTC781
    return { destroy: () => {
2021154f9e16atagen2026-10-25 02:37 UTC782
      observer.disconnect();
2021154f9e16atagen2026-10-25 02:37 UTC783
      node.removeEventListener('scroll', sync);
2021154f9e16atagen2026-10-25 02:37 UTC784
    } };
2021154f9e16atagen2026-10-25 02:37 UTC785
  }
2021154f9e16atagen2026-10-25 02:37 UTC786
705b1e1062c2atagen2026-10-23 09:05 UTC787
  function onTimelineKey(e: KeyboardEvent): void {
705b1e1062c2atagen2026-10-23 09:05 UTC788
    if (['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End', ' '].includes(e.key)) noteUserScroll();
705b1e1062c2atagen2026-10-23 09:05 UTC789
  }
705b1e1062c2atagen2026-10-23 09:05 UTC790
973f8fbdaf80atagen2026-09-28 09:10 UTC791
  function onTimelineScroll(): void {
973f8fbdaf80atagen2026-09-28 09:10 UTC792
    if (!timelineEl) return;
1b586ca05859atagen2026-10-25 02:37 UTC793
    if (timelineViewport?.consumeScroll()) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC794
    const gap = timelineEl.scrollHeight - timelineEl.scrollTop - timelineEl.clientHeight;
1b586ca05859atagen2026-10-25 02:37 UTC795
    stickToBottom = gap < 2;
1b586ca05859atagen2026-10-25 02:37 UTC796
    timelineViewport?.capture();
11cc2db16d17atagen2026-10-24 12:36 UTC797
    if (timelineEl.scrollTop < 80 && !hasStart && !paginateBusy) void paginate();
705b1e1062c2atagen2026-10-23 09:05 UTC798
  }
705b1e1062c2atagen2026-10-23 09:05 UTC799
705b1e1062c2atagen2026-10-23 09:05 UTC800
  function pinTimeline(node: HTMLElement) {
1b586ca05859atagen2026-10-25 02:37 UTC801
    const viewport = new TimelineViewport(node.parentElement!, $selectedRoomId);
1b586ca05859atagen2026-10-25 02:37 UTC802
    timelineViewport = viewport;
705b1e1062c2atagen2026-10-23 09:05 UTC803
    const observer = new ResizeObserver(() => {
1b586ca05859atagen2026-10-25 02:37 UTC804
      if (timelineViewport !== viewport || viewport.roomId !== $selectedRoomId) return;
1b586ca05859atagen2026-10-25 02:37 UTC805
      if (stickToBottom) viewport.scrollToBottom(true);
1b586ca05859atagen2026-10-25 02:37 UTC806
      else viewport.restore();
705b1e1062c2atagen2026-10-23 09:05 UTC807
    });
705b1e1062c2atagen2026-10-23 09:05 UTC808
    observer.observe(node);
705b1e1062c2atagen2026-10-23 09:05 UTC809
    if (node.parentElement) observer.observe(node.parentElement);
1b586ca05859atagen2026-10-25 02:37 UTC810
    return { destroy: () => {
1b586ca05859atagen2026-10-25 02:37 UTC811
      observer.disconnect();
1b586ca05859atagen2026-10-25 02:37 UTC812
      viewport.releaseScroll();
1b586ca05859atagen2026-10-25 02:37 UTC813
      if (timelineViewport === viewport) timelineViewport = null;
1b586ca05859atagen2026-10-25 02:37 UTC814
    } };
973f8fbdaf80atagen2026-09-28 09:10 UTC815
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC816
973f8fbdaf80atagen2026-09-28 09:10 UTC817
  $: void trackTimeline($selectedRoomId, items);
973f8fbdaf80atagen2026-09-28 09:10 UTC818
  async function trackTimeline(roomId: string | null, list: TimelineItem[]): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC819
    if (!roomId || list.length === 0) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC820
    if (roomId !== $selectedRoomId) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC821
    await tick();
1b586ca05859atagen2026-10-25 02:37 UTC822
    if (roomId !== $selectedRoomId || timelineViewport?.roomId !== roomId) return;
1b586ca05859atagen2026-10-25 02:37 UTC823
    if (stickToBottom) timelineViewport.scrollToBottom(true);
1b586ca05859atagen2026-10-25 02:37 UTC824
    else timelineViewport.restore();
973f8fbdaf80atagen2026-09-28 09:10 UTC825
    queueReadReceipt();
973f8fbdaf80atagen2026-09-28 09:10 UTC826
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC827
973f8fbdaf80atagen2026-09-28 09:10 UTC828
  function queueReadReceipt(): void {
973f8fbdaf80atagen2026-09-28 09:10 UTC829
    if (readTimer !== null) window.clearTimeout(readTimer);
973f8fbdaf80atagen2026-09-28 09:10 UTC830
    readTimer = window.setTimeout(() => {
973f8fbdaf80atagen2026-09-28 09:10 UTC831
      readTimer = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC832
      void sendReadReceipt();
973f8fbdaf80atagen2026-09-28 09:10 UTC833
    }, 800);
973f8fbdaf80atagen2026-09-28 09:10 UTC834
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC835
973f8fbdaf80atagen2026-09-28 09:10 UTC836
  async function sendReadReceipt(): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC837
    const roomId = $selectedRoomId;
d8624c214c04atagen2026-10-24 08:24 UTC838
    if (!roomId || roomId === peeking) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC839
    const list = $timelines[roomId] ?? [];
973f8fbdaf80atagen2026-09-28 09:10 UTC840
    for (let i = list.length - 1; i >= 0; i -= 1) {
973f8fbdaf80atagen2026-09-28 09:10 UTC841
      const entry = list[i];
973f8fbdaf80atagen2026-09-28 09:10 UTC842
      if (entry.kind === 'event' && entry.event.event_id) {
973f8fbdaf80atagen2026-09-28 09:10 UTC843
        const key = `${roomId}:${entry.event.event_id}`;
973f8fbdaf80atagen2026-09-28 09:10 UTC844
        if (key === lastReadKey) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC845
        lastReadKey = key;
973f8fbdaf80atagen2026-09-28 09:10 UTC846
        try {
973f8fbdaf80atagen2026-09-28 09:10 UTC847
          await markRead(roomId, entry.event.event_id);
973f8fbdaf80atagen2026-09-28 09:10 UTC848
        } catch {
973f8fbdaf80atagen2026-09-28 09:10 UTC849
          return;
973f8fbdaf80atagen2026-09-28 09:10 UTC850
        }
973f8fbdaf80atagen2026-09-28 09:10 UTC851
        return;
973f8fbdaf80atagen2026-09-28 09:10 UTC852
      }
973f8fbdaf80atagen2026-09-28 09:10 UTC853
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC854
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC855
973f8fbdaf80atagen2026-09-28 09:10 UTC856
  function send(): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC857
    if (editing) {
cf23dbf4e77catagen2026-10-23 06:36 UTC858
      submitEdit();
cf23dbf4e77catagen2026-10-23 06:36 UTC859
      return;
cf23dbf4e77catagen2026-10-23 06:36 UTC860
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC861
    const roomId = $selectedRoomId;
973f8fbdaf80atagen2026-09-28 09:10 UTC862
    const body = composer.trim();
cf23dbf4e77catagen2026-10-23 06:36 UTC863
    const attachments = roomId ? (staged[roomId] ?? []) : [];
cf23dbf4e77catagen2026-10-23 06:36 UTC864
    if (!roomId || (!body && attachments.length === 0)) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC865
    if (!openReady[roomId]) {
973f8fbdaf80atagen2026-09-28 09:10 UTC866
      pushBanner('Still opening this room — sending is disabled until the room is ready.');
973f8fbdaf80atagen2026-09-28 09:10 UTC867
      return;
973f8fbdaf80atagen2026-09-28 09:10 UTC868
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC869
    if (attachments.length > 0 && uploadBusy) return;
6c8fd192fb8catagen2026-10-24 08:20 UTC870
    const command = parseCommand(body);
e4c64c36f105atagen2026-10-24 07:09 UTC871
    if (command && !isKnownCommand(command.name)) {
e4c64c36f105atagen2026-10-24 07:09 UTC872
      pushBanner(`Unknown command /${command.name}`);
e4c64c36f105atagen2026-10-24 07:09 UTC873
      return;
e4c64c36f105atagen2026-10-24 07:09 UTC874
    }
6c8fd192fb8catagen2026-10-24 08:20 UTC875
    if (command && attachments.length > 0) {
6c8fd192fb8catagen2026-10-24 08:20 UTC876
      if (command.name !== 'roomavatar' && command.name !== 'globalavatar') {
6c8fd192fb8catagen2026-10-24 08:20 UTC877
        pushBanner(`/${command.name} doesn't take attachments`);
6c8fd192fb8catagen2026-10-24 08:20 UTC878
        return;
6c8fd192fb8catagen2026-10-24 08:20 UTC879
      }
6c8fd192fb8catagen2026-10-24 08:20 UTC880
      if (command.args || attachments.length !== 1 || !attachments[0].file.type.startsWith('image/')) {
6c8fd192fb8catagen2026-10-24 08:20 UTC881
        pushBanner(`/${command.name} takes a single attached image`);
6c8fd192fb8catagen2026-10-24 08:20 UTC882
        return;
6c8fd192fb8catagen2026-10-24 08:20 UTC883
      }
6c8fd192fb8catagen2026-10-24 08:20 UTC884
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC885
    composer = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC886
    if (roomId in drafts) delete drafts[roomId];
973f8fbdaf80atagen2026-09-28 09:10 UTC887
    stickToBottom = true;
cf23dbf4e77catagen2026-10-23 06:36 UTC888
    const reply = replyingTo;
cf23dbf4e77catagen2026-10-23 06:36 UTC889
    replyingTo = null;
e4c64c36f105atagen2026-10-24 07:09 UTC890
    const text = unescapeCommand(body);
e4c64c36f105atagen2026-10-24 07:09 UTC891
    const mentions = resolveMentions(text, pickedMentions[roomId] ?? []);
cf23dbf4e77catagen2026-10-23 06:36 UTC892
    pickedMentions = { ...pickedMentions, [roomId]: [] };
cf23dbf4e77catagen2026-10-23 06:36 UTC893
    mentionQuery = null;
e4c64c36f105atagen2026-10-24 07:09 UTC894
    if (command) {
6c8fd192fb8catagen2026-10-24 08:20 UTC895
      const image = attachments[0] ?? null;
6c8fd192fb8catagen2026-10-24 08:20 UTC896
      if (image) {
6c8fd192fb8catagen2026-10-24 08:20 UTC897
        const { [roomId]: _used, ...rest } = staged;
6c8fd192fb8catagen2026-10-24 08:20 UTC898
        staged = rest;
6c8fd192fb8catagen2026-10-24 08:20 UTC899
      }
6c8fd192fb8catagen2026-10-24 08:20 UTC900
      void execute(roomId, command, reply, mentions, image?.file ?? null).finally(() => {
6c8fd192fb8catagen2026-10-24 08:20 UTC901
        if (image?.previewUrl) URL.revokeObjectURL(image.previewUrl);
6c8fd192fb8catagen2026-10-24 08:20 UTC902
      });
e4c64c36f105atagen2026-10-24 07:09 UTC903
    } else if (attachments.length === 0) {
e822c659890fatagen2026-10-25 02:37 UTC904
      queueSend(roomId, text, reply, mentions, resolveEmotes(text, roomEmotes));
cf23dbf4e77catagen2026-10-23 06:36 UTC905
    } else {
cf23dbf4e77catagen2026-10-23 06:36 UTC906
      const { [roomId]: _sent, ...rest } = staged;
cf23dbf4e77catagen2026-10-23 06:36 UTC907
      staged = rest;
e4c64c36f105atagen2026-10-24 07:09 UTC908
      void sendAttachments(roomId, text, reply, mentions, attachments);
cf23dbf4e77catagen2026-10-23 06:36 UTC909
    }
d8624c214c04atagen2026-10-24 08:24 UTC910
    if (peeking === roomId) stopPeeking();
cf23dbf4e77catagen2026-10-23 06:36 UTC911
    composerEl?.focus();
cf23dbf4e77catagen2026-10-23 06:36 UTC912
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC913
e4c64c36f105atagen2026-10-24 07:09 UTC914
  function lastOwnEventId(): string | null {
e4c64c36f105atagen2026-10-24 07:09 UTC915
    for (let i = items.length - 1; i >= 0; i -= 1) {
e4c64c36f105atagen2026-10-24 07:09 UTC916
      const entry = items[i];
e4c64c36f105atagen2026-10-24 07:09 UTC917
      if (entry.kind === 'event' && entry.event.own && entry.event.event_id && entry.event.content.kind !== 'Redacted') {
e4c64c36f105atagen2026-10-24 07:09 UTC918
        return entry.event.event_id;
e4c64c36f105atagen2026-10-24 07:09 UTC919
      }
e4c64c36f105atagen2026-10-24 07:09 UTC920
    }
e4c64c36f105atagen2026-10-24 07:09 UTC921
    return null;
e4c64c36f105atagen2026-10-24 07:09 UTC922
  }
e4c64c36f105atagen2026-10-24 07:09 UTC923
6c8fd192fb8catagen2026-10-24 08:20 UTC924
  async function execute(
6c8fd192fb8catagen2026-10-24 08:20 UTC925
    roomId: string,
6c8fd192fb8catagen2026-10-24 08:20 UTC926
    command: ParsedCommand,
6c8fd192fb8catagen2026-10-24 08:20 UTC927
    reply: ReplyReference | null,
6c8fd192fb8catagen2026-10-24 08:20 UTC928
    mentions: Mention[],
6c8fd192fb8catagen2026-10-24 08:20 UTC929
    image: File | null
6c8fd192fb8catagen2026-10-24 08:20 UTC930
  ): Promise<void> {
e4c64c36f105atagen2026-10-24 07:09 UTC931
    const { name, args } = command;
e4c64c36f105atagen2026-10-24 07:09 UTC932
    const target = () => {
e4c64c36f105atagen2026-10-24 07:09 UTC933
      const found = splitTarget(args, Object.values(people));
e4c64c36f105atagen2026-10-24 07:09 UTC934
      if ('error' in found) throw new Error(found.error);
e4c64c36f105atagen2026-10-24 07:09 UTC935
      return found;
e4c64c36f105atagen2026-10-24 07:09 UTC936
    };
e4c64c36f105atagen2026-10-24 07:09 UTC937
    const required = (what: string) => {
e4c64c36f105atagen2026-10-24 07:09 UTC938
      if (!args) throw new Error(`/${name} needs ${what}`);
e4c64c36f105atagen2026-10-24 07:09 UTC939
      return args;
e4c64c36f105atagen2026-10-24 07:09 UTC940
    };
e4c64c36f105atagen2026-10-24 07:09 UTC941
    try {
e4c64c36f105atagen2026-10-24 07:09 UTC942
      switch (name) {
e4c64c36f105atagen2026-10-24 07:09 UTC943
        case 'me':
05a48e9e7942atagen2026-10-24 09:32 UTC944
        case 'notice': {
05a48e9e7942atagen2026-10-24 09:32 UTC945
          const said = required('something to say');
e822c659890fatagen2026-10-25 02:37 UTC946
          await sendMessage(roomId, said, null, mentions, name === 'me' ? 'emote' : 'notice', resolveEmotes(said, roomEmotes));
e4c64c36f105atagen2026-10-24 07:09 UTC947
          break;
05a48e9e7942atagen2026-10-24 09:32 UTC948
        }
e4c64c36f105atagen2026-10-24 07:09 UTC949
        case 'msg': {
e4c64c36f105atagen2026-10-24 07:09 UTC950
          const { user_id, rest } = target();
e4c64c36f105atagen2026-10-24 07:09 UTC951
          const res = (await runCommand({ op: 'direct', user_id })) as { room_id: string };
e4c64c36f105atagen2026-10-24 07:09 UTC952
          await refreshRooms();
e4c64c36f105atagen2026-10-24 07:09 UTC953
          await selectRoom(res.room_id);
e822c659890fatagen2026-10-25 02:37 UTC954
          if (rest) queueSend(res.room_id, rest);
e4c64c36f105atagen2026-10-24 07:09 UTC955
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC956
        }
e4c64c36f105atagen2026-10-24 07:09 UTC957
        case 'join':
e4c64c36f105atagen2026-10-24 07:09 UTC958
          await join(required('a room id or alias'));
e4c64c36f105atagen2026-10-24 07:09 UTC959
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC960
        case 'leave':
e4c64c36f105atagen2026-10-24 07:09 UTC961
          await leave();
e4c64c36f105atagen2026-10-24 07:09 UTC962
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC963
        case 'invite':
e4c64c36f105atagen2026-10-24 07:09 UTC964
          await runCommand({ op: 'invite', room_id: roomId, user_id: target().user_id });
e4c64c36f105atagen2026-10-24 07:09 UTC965
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC966
        case 'disinvite':
e4c64c36f105atagen2026-10-24 07:09 UTC967
        case 'kick':
e4c64c36f105atagen2026-10-24 07:09 UTC968
        case 'ban':
e4c64c36f105atagen2026-10-24 07:09 UTC969
        case 'unban': {
e4c64c36f105atagen2026-10-24 07:09 UTC970
          const { user_id, rest } = target();
e4c64c36f105atagen2026-10-24 07:09 UTC971
          const op = name === 'disinvite' ? 'kick' : name;
e4c64c36f105atagen2026-10-24 07:09 UTC972
          await runCommand({ op, room_id: roomId, user_id, reason: rest || null });
e4c64c36f105atagen2026-10-24 07:09 UTC973
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC974
        }
e4c64c36f105atagen2026-10-24 07:09 UTC975
        case 'powerlevel': {
e4c64c36f105atagen2026-10-24 07:09 UTC976
          const { user_id, rest } = target();
e4c64c36f105atagen2026-10-24 07:09 UTC977
          const level = Number(rest);
e4c64c36f105atagen2026-10-24 07:09 UTC978
          if (!rest || !Number.isInteger(level)) throw new Error('/powerlevel needs a whole number after the name');
e4c64c36f105atagen2026-10-24 07:09 UTC979
          await runCommand({ op: 'set_power_level', room_id: roomId, user_id, level });
e4c64c36f105atagen2026-10-24 07:09 UTC980
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC981
        }
7cca1d5628d1atagen2026-10-24 07:36 UTC982
        case 'mute':
7cca1d5628d1atagen2026-10-24 07:36 UTC983
        case 'unmute':
7cca1d5628d1atagen2026-10-24 07:36 UTC984
          await runCommand({ op: 'mute', room_id: roomId, user_id: target().user_id, muted: name === 'mute' });
7cca1d5628d1atagen2026-10-24 07:36 UTC985
          break;
7cca1d5628d1atagen2026-10-24 07:36 UTC986
        case 'ignore':
7cca1d5628d1atagen2026-10-24 07:36 UTC987
        case 'unignore':
7cca1d5628d1atagen2026-10-24 07:36 UTC988
          await runCommand({ op: name, user_id: target().user_id });
7cca1d5628d1atagen2026-10-24 07:36 UTC989
          break;
7cca1d5628d1atagen2026-10-24 07:36 UTC990
        case 'roomnick':
7cca1d5628d1atagen2026-10-24 07:36 UTC991
          await runCommand({ op: 'set_room_display_name', room_id: roomId, name: args || null });
7cca1d5628d1atagen2026-10-24 07:36 UTC992
          break;
7cca1d5628d1atagen2026-10-24 07:36 UTC993
        case 'roomavatar':
6c8fd192fb8catagen2026-10-24 08:20 UTC994
          if (image) {
6c8fd192fb8catagen2026-10-24 08:20 UTC995
            await uploadRoomAvatar(roomId, image);
6c8fd192fb8catagen2026-10-24 08:20 UTC996
          } else if (args && !args.startsWith('mxc://')) {
6c8fd192fb8catagen2026-10-24 08:20 UTC997
            throw new Error('/roomavatar takes an mxc:// link, an attached image, or nothing to drop the override');
6c8fd192fb8catagen2026-10-24 08:20 UTC998
          } else {
6c8fd192fb8catagen2026-10-24 08:20 UTC999
            await runCommand({ op: 'set_room_avatar', room_id: roomId, mxc: args || null });
6c8fd192fb8catagen2026-10-24 08:20 UTC1000
          }
7cca1d5628d1atagen2026-10-24 07:36 UTC1001
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC1002
        case 'delete': {
e4c64c36f105atagen2026-10-24 07:09 UTC1003
          const eventId = reply?.event_id ?? lastOwnEventId();
e4c64c36f105atagen2026-10-24 07:09 UTC1004
          if (!eventId) throw new Error('Nothing of yours to delete here');
e4c64c36f105atagen2026-10-24 07:09 UTC1005
          await runCommand({ op: 'redact', room_id: roomId, event_id: eventId, reason: args || null });
e4c64c36f105atagen2026-10-24 07:09 UTC1006
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC1007
        }
e4c64c36f105atagen2026-10-24 07:09 UTC1008
        case 'globalnick':
e4c64c36f105atagen2026-10-24 07:09 UTC1009
          await runCommand({ op: 'set_display_name', name: required('a name') });
e4c64c36f105atagen2026-10-24 07:09 UTC1010
          await loadProfile();
e4c64c36f105atagen2026-10-24 07:09 UTC1011
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC1012
        case 'globalavatar':
6c8fd192fb8catagen2026-10-24 08:20 UTC1013
          if (image) {
6c8fd192fb8catagen2026-10-24 08:20 UTC1014
            await uploadAvatar(image);
6c8fd192fb8catagen2026-10-24 08:20 UTC1015
            await loadProfile();
6c8fd192fb8catagen2026-10-24 08:20 UTC1016
          } else if (!args) {
e4c64c36f105atagen2026-10-24 07:09 UTC1017
            avatarInput?.click();
e4c64c36f105atagen2026-10-24 07:09 UTC1018
          } else if (args.startsWith('mxc://')) {
e4c64c36f105atagen2026-10-24 07:09 UTC1019
            await runCommand({ op: 'set_avatar', mxc: args });
e4c64c36f105atagen2026-10-24 07:09 UTC1020
            await loadProfile();
e4c64c36f105atagen2026-10-24 07:09 UTC1021
          } else {
e4c64c36f105atagen2026-10-24 07:09 UTC1022
            throw new Error('/globalavatar takes an mxc:// link, or nothing to pick a file');
e4c64c36f105atagen2026-10-24 07:09 UTC1023
          }
e4c64c36f105atagen2026-10-24 07:09 UTC1024
          break;
e4c64c36f105atagen2026-10-24 07:09 UTC1025
      }
e4c64c36f105atagen2026-10-24 07:09 UTC1026
    } catch (e) {
e4c64c36f105atagen2026-10-24 07:09 UTC1027
      pushBanner(e instanceof Error ? e.message : `/${name} failed`);
e4c64c36f105atagen2026-10-24 07:09 UTC1028
    }
e4c64c36f105atagen2026-10-24 07:09 UTC1029
  }
e4c64c36f105atagen2026-10-24 07:09 UTC1030
e4c64c36f105atagen2026-10-24 07:09 UTC1031
  async function onAvatarChosen(): Promise<void> {
e4c64c36f105atagen2026-10-24 07:09 UTC1032
    const file = avatarInput?.files?.[0];
e4c64c36f105atagen2026-10-24 07:09 UTC1033
    if (avatarInput) avatarInput.value = '';
e4c64c36f105atagen2026-10-24 07:09 UTC1034
    if (!file) return;
e4c64c36f105atagen2026-10-24 07:09 UTC1035
    try {
5e9271c9b8f1atagen2026-10-24 07:45 UTC1036
      await uploadAvatar(file);
5e9271c9b8f1atagen2026-10-24 07:45 UTC1037
      await loadProfile();
e4c64c36f105atagen2026-10-24 07:09 UTC1038
    } catch (e) {
e4c64c36f105atagen2026-10-24 07:09 UTC1039
      pushBanner(e instanceof Error ? e.message : 'Avatar upload failed');
e4c64c36f105atagen2026-10-24 07:09 UTC1040
    }
e4c64c36f105atagen2026-10-24 07:09 UTC1041
  }
e4c64c36f105atagen2026-10-24 07:09 UTC1042
cf23dbf4e77catagen2026-10-23 06:36 UTC1043
  async function sendAttachments(
cf23dbf4e77catagen2026-10-23 06:36 UTC1044
    roomId: string,
cf23dbf4e77catagen2026-10-23 06:36 UTC1045
    body: string,
cf23dbf4e77catagen2026-10-23 06:36 UTC1046
    reply: ReplyReference | null,
cf23dbf4e77catagen2026-10-23 06:36 UTC1047
    mentions: Mention[],
cf23dbf4e77catagen2026-10-23 06:36 UTC1048
    attachments: StagedAttachment[]
cf23dbf4e77catagen2026-10-23 06:36 UTC1049
  ): Promise<void> {
cf23dbf4e77catagen2026-10-23 06:36 UTC1050
    let first = true;
cf23dbf4e77catagen2026-10-23 06:36 UTC1051
    uploadBusy = true;
cf23dbf4e77catagen2026-10-23 06:36 UTC1052
    try {
cf23dbf4e77catagen2026-10-23 06:36 UTC1053
      for (const attachment of attachments) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1054
        uploadName = attachment.file.name || 'attachment';
cf23dbf4e77catagen2026-10-23 06:36 UTC1055
        try {
e822c659890fatagen2026-10-25 02:37 UTC1056
          if (first) await uploadAttachment(roomId, attachment.file, body || null, reply?.event_id ?? null, mentions, resolveEmotes(body, roomEmotes));
cf23dbf4e77catagen2026-10-23 06:36 UTC1057
          else await uploadAttachment(roomId, attachment.file);
cf23dbf4e77catagen2026-10-23 06:36 UTC1058
          first = false;
cf23dbf4e77catagen2026-10-23 06:36 UTC1059
        } catch (e) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1060
          pushBanner(e instanceof Error ? e.message : 'Upload failed');
cf23dbf4e77catagen2026-10-23 06:36 UTC1061
        }
cf23dbf4e77catagen2026-10-23 06:36 UTC1062
        if (attachment.previewUrl) URL.revokeObjectURL(attachment.previewUrl);
cf23dbf4e77catagen2026-10-23 06:36 UTC1063
      }
cf23dbf4e77catagen2026-10-23 06:36 UTC1064
    } finally {
cf23dbf4e77catagen2026-10-23 06:36 UTC1065
      uploadBusy = false;
cf23dbf4e77catagen2026-10-23 06:36 UTC1066
      uploadName = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC1067
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC1068
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1069
cf23dbf4e77catagen2026-10-23 06:36 UTC1070
  function stageFiles(files: File[]): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1071
    const roomId = $selectedRoomId;
cf23dbf4e77catagen2026-10-23 06:36 UTC1072
    if (!roomId || !openReady[roomId]) return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1073
    const accepted: StagedAttachment[] = [];
cf23dbf4e77catagen2026-10-23 06:36 UTC1074
    for (const file of files) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1075
      if (file.size === 0 || file.size > 20 * 1024 * 1024) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1076
        pushBanner(`${file.name || 'File'} must be between 1 byte and 20 MiB.`);
cf23dbf4e77catagen2026-10-23 06:36 UTC1077
        continue;
cf23dbf4e77catagen2026-10-23 06:36 UTC1078
      }
cf23dbf4e77catagen2026-10-23 06:36 UTC1079
      const previewUrl = file.type.startsWith('image/') ? URL.createObjectURL(file) : null;
cf23dbf4e77catagen2026-10-23 06:36 UTC1080
      accepted.push({ id: nextStagedId++, file, previewUrl });
cf23dbf4e77catagen2026-10-23 06:36 UTC1081
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC1082
    if (accepted.length === 0) return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1083
    staged = { ...staged, [roomId]: [...(staged[roomId] ?? []), ...accepted] };
cf23dbf4e77catagen2026-10-23 06:36 UTC1084
    composerEl?.focus();
cf23dbf4e77catagen2026-10-23 06:36 UTC1085
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1086
cf23dbf4e77catagen2026-10-23 06:36 UTC1087
  function unstage(roomId: string, id: number): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1088
    const list = staged[roomId] ?? [];
cf23dbf4e77catagen2026-10-23 06:36 UTC1089
    const removed = list.find((a) => a.id === id);
cf23dbf4e77catagen2026-10-23 06:36 UTC1090
    if (removed?.previewUrl) URL.revokeObjectURL(removed.previewUrl);
cf23dbf4e77catagen2026-10-23 06:36 UTC1091
    staged = { ...staged, [roomId]: list.filter((a) => a.id !== id) };
cf23dbf4e77catagen2026-10-23 06:36 UTC1092
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1093
cf23dbf4e77catagen2026-10-23 06:36 UTC1094
  function clearAllStaged(): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1095
    for (const list of Object.values(staged)) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1096
      for (const attachment of list) if (attachment.previewUrl) URL.revokeObjectURL(attachment.previewUrl);
cf23dbf4e77catagen2026-10-23 06:36 UTC1097
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC1098
    staged = {};
cf23dbf4e77catagen2026-10-23 06:36 UTC1099
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1100
cf23dbf4e77catagen2026-10-23 06:36 UTC1101
  function startEdit(eventId: string, body: string): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1102
    const roomId = $selectedRoomId;
cf23dbf4e77catagen2026-10-23 06:36 UTC1103
    if (!roomId) return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1104
    const stash = editing ? editing.stash : composer;
cf23dbf4e77catagen2026-10-23 06:36 UTC1105
    editing = { roomId, eventId, original: body, stash };
cf23dbf4e77catagen2026-10-23 06:36 UTC1106
    const entry = items.find((i) => i.kind === 'event' && i.event.event_id === eventId);
cf23dbf4e77catagen2026-10-23 06:36 UTC1107
    if (entry?.kind === 'event' && entry.event.content.kind === 'Message') {
cf23dbf4e77catagen2026-10-23 06:36 UTC1108
      const existing = mentionsFromHtml(entry.event.content.message.formatted_body);
cf23dbf4e77catagen2026-10-23 06:36 UTC1109
      pickedMentions = { ...pickedMentions, [roomId]: [...(pickedMentions[roomId] ?? []), ...existing] };
cf23dbf4e77catagen2026-10-23 06:36 UTC1110
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC1111
    composer = body;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1112
    replyingTo = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC1113
    composerEl?.focus();
973f8fbdaf80atagen2026-09-28 09:10 UTC1114
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1115
cf23dbf4e77catagen2026-10-23 06:36 UTC1116
  function cancelEdit(): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1117
    if (!editing) return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1118
    composer = editing.stash;
cf23dbf4e77catagen2026-10-23 06:36 UTC1119
    editing = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC1120
    composerEl?.focus();
cf23dbf4e77catagen2026-10-23 06:36 UTC1121
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1122
cf23dbf4e77catagen2026-10-23 06:36 UTC1123
  function submitEdit(): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1124
    if (!editing) return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1125
    const { roomId, eventId, original } = editing;
cf23dbf4e77catagen2026-10-23 06:36 UTC1126
    const body = composer.trim();
cf23dbf4e77catagen2026-10-23 06:36 UTC1127
    cancelEdit();
cf23dbf4e77catagen2026-10-23 06:36 UTC1128
    if (!body || body === original.trim()) return;
e822c659890fatagen2026-10-25 02:37 UTC1129
    editMessage(roomId, eventId, body, resolveMentions(body, pickedMentions[roomId] ?? []), resolveEmotes(body, roomEmotes)).catch((e) => pushBanner(e instanceof Error ? e.message : 'Edit failed'));
cf23dbf4e77catagen2026-10-23 06:36 UTC1130
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1131
cf23dbf4e77catagen2026-10-23 06:36 UTC1132
  function editLastOwn(): boolean {
cf23dbf4e77catagen2026-10-23 06:36 UTC1133
    for (let i = items.length - 1; i >= 0; i -= 1) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1134
      const entry = items[i];
cf23dbf4e77catagen2026-10-23 06:36 UTC1135
      if (entry.kind !== 'event' || !entry.event.own) continue;
cf23dbf4e77catagen2026-10-23 06:36 UTC1136
      const ev = entry.event;
cf23dbf4e77catagen2026-10-23 06:36 UTC1137
      if (!ev.editable || !ev.event_id || ev.content.kind !== 'Message' || ev.content.message.kind !== 'Text') return false;
cf23dbf4e77catagen2026-10-23 06:36 UTC1138
      startEdit(ev.event_id, ev.content.message.body);
cf23dbf4e77catagen2026-10-23 06:36 UTC1139
      return true;
cf23dbf4e77catagen2026-10-23 06:36 UTC1140
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC1141
    return false;
cf23dbf4e77catagen2026-10-23 06:36 UTC1142
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1143
df3c0f2b3da4atagen2026-10-22 13:07 UTC1144
  function startReply(target: ReplyReference): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1145
    if (editing) cancelEdit();
df3c0f2b3da4atagen2026-10-22 13:07 UTC1146
    replyingTo = target;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1147
    composerEl?.focus();
df3c0f2b3da4atagen2026-10-22 13:07 UTC1148
  }
df3c0f2b3da4atagen2026-10-22 13:07 UTC1149
05a48e9e7942atagen2026-10-24 09:32 UTC1150
  let pinnedOpenFor: string | null = null;
9f996e377406atagen2026-10-25 03:32 UTC1151
  let pinnedCloseVersion = 0;
05a48e9e7942atagen2026-10-24 09:32 UTC1152
  let pinsExpanded = false;
7efc4c6d41abatagen2026-10-24 11:40 UTC1153
  let pinPreview: TimelineEvent | null = null;
7efc4c6d41abatagen2026-10-24 11:40 UTC1154
  let pinJumpBusy = false;
9f996e377406atagen2026-10-25 03:32 UTC1155
  $: syncPinned(selectedRoom?.room_id ?? null, (selectedRoom?.pinned_events.length ?? 0) > 0, $selectedRoomId ? $pinnedTimelineVersions[$selectedRoomId] ?? 0 : 0, currentRepairActive);
9f996e377406atagen2026-10-25 03:32 UTC1156
  function syncPinned(roomId: string | null, hasPins: boolean, version: number, repairing: boolean): void {
05a48e9e7942atagen2026-10-24 09:32 UTC1157
    const want = hasPins ? roomId : null;
9f996e377406atagen2026-10-25 03:32 UTC1158
    if (want === pinnedOpenFor && version === pinnedCloseVersion) return;
9f996e377406atagen2026-10-25 03:32 UTC1159
    if (want && repairing) return;
05a48e9e7942atagen2026-10-24 09:32 UTC1160
    if (pinnedOpenFor) runCommand({ op: 'close_pinned', room_id: pinnedOpenFor }).catch(() => undefined);
05a48e9e7942atagen2026-10-24 09:32 UTC1161
    pinnedOpenFor = want;
9f996e377406atagen2026-10-25 03:32 UTC1162
    pinnedCloseVersion = version;
05a48e9e7942atagen2026-10-24 09:32 UTC1163
    pinsExpanded = false;
05a48e9e7942atagen2026-10-24 09:32 UTC1164
    if (want) runCommand({ op: 'open_pinned', room_id: want }).catch(() => undefined);
05a48e9e7942atagen2026-10-24 09:32 UTC1165
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1166
05a48e9e7942atagen2026-10-24 09:32 UTC1167
  $: pins = pinnedList(selectedRoom, $pinnedTimelines);
05a48e9e7942atagen2026-10-24 09:32 UTC1168
  function pinnedList(room: RoomSummary | null, all: Record<string, TimelineItem[]>): TimelineEvent[] {
05a48e9e7942atagen2026-10-24 09:32 UTC1169
    if (!room || !room.pinned_events.length) return [];
05a48e9e7942atagen2026-10-24 09:32 UTC1170
    const order = new Map(room.pinned_events.map((id, i) => [id, i]));
05a48e9e7942atagen2026-10-24 09:32 UTC1171
    return (all[room.room_id] ?? [])
05a48e9e7942atagen2026-10-24 09:32 UTC1172
      .flatMap((item) => (item.kind === 'event' && item.event.event_id && order.has(item.event.event_id) ? [item.event] : []))
05a48e9e7942atagen2026-10-24 09:32 UTC1173
      .sort((a, b) => (order.get(b.event_id!) ?? 0) - (order.get(a.event_id!) ?? 0));
05a48e9e7942atagen2026-10-24 09:32 UTC1174
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1175
05a48e9e7942atagen2026-10-24 09:32 UTC1176
  function setPinned(eventId: string, pinned: boolean): void {
05a48e9e7942atagen2026-10-24 09:32 UTC1177
    const roomId = $selectedRoomId;
05a48e9e7942atagen2026-10-24 09:32 UTC1178
    if (!roomId) return;
05a48e9e7942atagen2026-10-24 09:32 UTC1179
    runCommand({ op: 'set_pinned', room_id: roomId, event_id: eventId, pinned }).catch((e) =>
05a48e9e7942atagen2026-10-24 09:32 UTC1180
      pushBanner(e instanceof Error ? e.message : 'Could not change the pin')
05a48e9e7942atagen2026-10-24 09:32 UTC1181
    );
05a48e9e7942atagen2026-10-24 09:32 UTC1182
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1183
7efc4c6d41abatagen2026-10-24 11:40 UTC1184
  async function jumpToPin(eventId: string): Promise<void> {
7efc4c6d41abatagen2026-10-24 11:40 UTC1185
    const roomId = $selectedRoomId;
7efc4c6d41abatagen2026-10-24 11:40 UTC1186
    if (!roomId || !eventId || pinJumpBusy) return;
05a48e9e7942atagen2026-10-24 09:32 UTC1187
    pinsExpanded = false;
7efc4c6d41abatagen2026-10-24 11:40 UTC1188
    pinPreview = pins.find((event) => event.event_id === eventId) ?? null;
7efc4c6d41abatagen2026-10-24 11:40 UTC1189
    pinJumpBusy = true;
7efc4c6d41abatagen2026-10-24 11:40 UTC1190
    try {
7efc4c6d41abatagen2026-10-24 11:40 UTC1191
      for (let attempt = 0; attempt < 24; attempt += 1) {
7efc4c6d41abatagen2026-10-24 11:40 UTC1192
        if (($timelines[roomId] ?? []).some((item) => item.kind === 'event' && item.event.event_id === eventId)) {
7efc4c6d41abatagen2026-10-24 11:40 UTC1193
          pinPreview = null;
7efc4c6d41abatagen2026-10-24 11:40 UTC1194
          await tick();
7efc4c6d41abatagen2026-10-24 11:40 UTC1195
          jumpTo(eventId);
7efc4c6d41abatagen2026-10-24 11:40 UTC1196
          return;
7efc4c6d41abatagen2026-10-24 11:40 UTC1197
        }
7efc4c6d41abatagen2026-10-24 11:40 UTC1198
        await paginateRoom(roomId);
7efc4c6d41abatagen2026-10-24 11:40 UTC1199
        await new Promise((resolve) => window.setTimeout(resolve, 180));
7efc4c6d41abatagen2026-10-24 11:40 UTC1200
      }
7efc4c6d41abatagen2026-10-24 11:40 UTC1201
      pushBanner('Could not load that pinned message');
7efc4c6d41abatagen2026-10-24 11:40 UTC1202
    } catch (e) {
7efc4c6d41abatagen2026-10-24 11:40 UTC1203
      pushBanner(e instanceof Error ? e.message : 'Could not load that pinned message');
7efc4c6d41abatagen2026-10-24 11:40 UTC1204
    } finally {
7efc4c6d41abatagen2026-10-24 11:40 UTC1205
      pinJumpBusy = false;
7efc4c6d41abatagen2026-10-24 11:40 UTC1206
    }
05a48e9e7942atagen2026-10-24 09:32 UTC1207
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1208
df3c0f2b3da4atagen2026-10-22 13:07 UTC1209
  function jumpTo(eventId: string): void {
df3c0f2b3da4atagen2026-10-22 13:07 UTC1210
    const el = timelineEl?.querySelector<HTMLElement>(`[data-event="${CSS.escape(eventId)}"]`);
df3c0f2b3da4atagen2026-10-22 13:07 UTC1211
    if (!el) {
df3c0f2b3da4atagen2026-10-22 13:07 UTC1212
      pushBanner('The original message is not loaded. Scroll up to load older messages.');
df3c0f2b3da4atagen2026-10-22 13:07 UTC1213
      return;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1214
    }
df3c0f2b3da4atagen2026-10-22 13:07 UTC1215
    stickToBottom = false;
1b586ca05859atagen2026-10-25 02:37 UTC1216
    timelineViewport?.releaseScroll();
df3c0f2b3da4atagen2026-10-22 13:07 UTC1217
    el.scrollIntoView({ block: 'center', behavior: 'smooth' });
df3c0f2b3da4atagen2026-10-22 13:07 UTC1218
    el.classList.remove('flash');
df3c0f2b3da4atagen2026-10-22 13:07 UTC1219
    void el.offsetWidth;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1220
    el.classList.add('flash');
df3c0f2b3da4atagen2026-10-22 13:07 UTC1221
  }
df3c0f2b3da4atagen2026-10-22 13:07 UTC1222
973f8fbdaf80atagen2026-09-28 09:10 UTC1223
  let typedText = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC1224
  let typedRoom: string | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC1225
  $: trackTypingInput(composer, $selectedRoomId, openReady);
973f8fbdaf80atagen2026-09-28 09:10 UTC1226
  function trackTypingInput(text: string, roomId: string | null, ready: Record<string, boolean>): void {
973f8fbdaf80atagen2026-09-28 09:10 UTC1227
    const edited = roomId === typedRoom && text !== typedText;
973f8fbdaf80atagen2026-09-28 09:10 UTC1228
    typedText = text;
973f8fbdaf80atagen2026-09-28 09:10 UTC1229
    typedRoom = roomId;
973f8fbdaf80atagen2026-09-28 09:10 UTC1230
    if (!roomId || !ready[roomId] || !text.trim()) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1231
      stopTyping();
d8624c214c04atagen2026-10-24 08:24 UTC1232
    } else if (edited && roomId !== peeking) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1233
      notifyTyping(roomId);
973f8fbdaf80atagen2026-09-28 09:10 UTC1234
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1235
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1236
973f8fbdaf80atagen2026-09-28 09:10 UTC1237
  $: void trackPending($selectedRoomId, pendingItems);
973f8fbdaf80atagen2026-09-28 09:10 UTC1238
  async function trackPending(roomId: string | null, list: PendingMessage[]): Promise<void> {
1b586ca05859atagen2026-10-25 02:37 UTC1239
    if (!roomId) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1240
    if (roomId !== $selectedRoomId) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1241
    await tick();
1b586ca05859atagen2026-10-25 02:37 UTC1242
    if (roomId !== $selectedRoomId || timelineViewport?.roomId !== roomId) return;
1b586ca05859atagen2026-10-25 02:37 UTC1243
    if (stickToBottom) timelineViewport.scrollToBottom(true);
1b586ca05859atagen2026-10-25 02:37 UTC1244
    else timelineViewport.restore();
973f8fbdaf80atagen2026-09-28 09:10 UTC1245
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1246
05a48e9e7942atagen2026-10-24 09:32 UTC1247
  let commandQuery: string | null = null;
05a48e9e7942atagen2026-10-24 09:32 UTC1248
  let commandIndex = 0;
05a48e9e7942atagen2026-10-24 09:32 UTC1249
  $: commandCandidates = commandQuery === null ? [] : matchCommands(commandQuery);
05a48e9e7942atagen2026-10-24 09:32 UTC1250
  $: if (commandIndex >= commandCandidates.length) commandIndex = 0;
05a48e9e7942atagen2026-10-24 09:32 UTC1251
05a48e9e7942atagen2026-10-24 09:32 UTC1252
  async function pickCommand(name: CommandName): Promise<void> {
05a48e9e7942atagen2026-10-24 09:32 UTC1253
    if (!composerEl) return;
05a48e9e7942atagen2026-10-24 09:32 UTC1254
    const caret = composerEl.selectionStart ?? composer.length;
05a48e9e7942atagen2026-10-24 09:32 UTC1255
    const rest = composer.slice(caret).replace(/^\S*/, '');
05a48e9e7942atagen2026-10-24 09:32 UTC1256
    composer = `/${name}${rest.startsWith(' ') ? rest : ` ${rest}`}`;
05a48e9e7942atagen2026-10-24 09:32 UTC1257
    commandQuery = null;
05a48e9e7942atagen2026-10-24 09:32 UTC1258
    await tick();
05a48e9e7942atagen2026-10-24 09:32 UTC1259
    const at = name.length + 2;
05a48e9e7942atagen2026-10-24 09:32 UTC1260
    composerEl.focus();
05a48e9e7942atagen2026-10-24 09:32 UTC1261
    composerEl.setSelectionRange(at, at);
05a48e9e7942atagen2026-10-24 09:32 UTC1262
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1263
05a48e9e7942atagen2026-10-24 09:32 UTC1264
  let emoteQuery: EmoteQuery | null = null;
05a48e9e7942atagen2026-10-24 09:32 UTC1265
  let emoteIndex = 0;
05a48e9e7942atagen2026-10-24 09:32 UTC1266
  let emojiList: EmojiEntry[] = [];
05a48e9e7942atagen2026-10-24 09:32 UTC1267
  $: emoteCandidates = emoteQuery ? rankEmotes(emoteQuery.query, roomEmotes, emojiList) : [];
05a48e9e7942atagen2026-10-24 09:32 UTC1268
  $: if (emoteIndex >= emoteCandidates.length) emoteIndex = 0;
05a48e9e7942atagen2026-10-24 09:32 UTC1269
05a48e9e7942atagen2026-10-24 09:32 UTC1270
  function ensureEmoji(): void {
05a48e9e7942atagen2026-10-24 09:32 UTC1271
    if (emojiList.length) return;
05a48e9e7942atagen2026-10-24 09:32 UTC1272
    loadEmoji()
05a48e9e7942atagen2026-10-24 09:32 UTC1273
      .then((groups) => (emojiList = groups.flatMap((g) => g.emojis)))
05a48e9e7942atagen2026-10-24 09:32 UTC1274
      .catch(() => undefined);
05a48e9e7942atagen2026-10-24 09:32 UTC1275
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1276
05a48e9e7942atagen2026-10-24 09:32 UTC1277
  async function onComposerInput(): Promise<void> {
05a48e9e7942atagen2026-10-24 09:32 UTC1278
    if (composerEl && composer.includes(':')) {
05a48e9e7942atagen2026-10-24 09:32 UTC1279
      ensureEmoji();
05a48e9e7942atagen2026-10-24 09:32 UTC1280
      const done = completeShortcode(composerEl.value, composerEl.selectionStart ?? composerEl.value.length, emojiList);
05a48e9e7942atagen2026-10-24 09:32 UTC1281
      if (done) {
05a48e9e7942atagen2026-10-24 09:32 UTC1282
        composer = done.text;
05a48e9e7942atagen2026-10-24 09:32 UTC1283
        await tick();
05a48e9e7942atagen2026-10-24 09:32 UTC1284
        composerEl.setSelectionRange(done.caret, done.caret);
05a48e9e7942atagen2026-10-24 09:32 UTC1285
      }
05a48e9e7942atagen2026-10-24 09:32 UTC1286
    }
05a48e9e7942atagen2026-10-24 09:32 UTC1287
    updateMentionQuery();
05a48e9e7942atagen2026-10-24 09:32 UTC1288
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1289
05a48e9e7942atagen2026-10-24 09:32 UTC1290
  async function pickEmote(candidate: EmoteCandidate): Promise<void> {
05a48e9e7942atagen2026-10-24 09:32 UTC1291
    if (!emoteQuery || !composerEl) return;
05a48e9e7942atagen2026-10-24 09:32 UTC1292
    const caret = composerEl.selectionStart ?? composer.length;
05a48e9e7942atagen2026-10-24 09:32 UTC1293
    const inserted = candidate.kind === 'emoji' ? candidate.emoji : `:${candidate.shortcode}: `;
05a48e9e7942atagen2026-10-24 09:32 UTC1294
    composer = composer.slice(0, emoteQuery.start) + inserted + composer.slice(caret);
05a48e9e7942atagen2026-10-24 09:32 UTC1295
    const at = emoteQuery.start + inserted.length;
05a48e9e7942atagen2026-10-24 09:32 UTC1296
    emoteQuery = null;
05a48e9e7942atagen2026-10-24 09:32 UTC1297
    await tick();
05a48e9e7942atagen2026-10-24 09:32 UTC1298
    composerEl.focus();
05a48e9e7942atagen2026-10-24 09:32 UTC1299
    composerEl.setSelectionRange(at, at);
05a48e9e7942atagen2026-10-24 09:32 UTC1300
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1301
cf23dbf4e77catagen2026-10-23 06:36 UTC1302
  function updateMentionQuery(): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1303
    const roomId = $selectedRoomId;
05a48e9e7942atagen2026-10-24 09:32 UTC1304
    const nextEmote = composerEl ? emoteQueryAt(composerEl.value, composerEl.selectionStart ?? composerEl.value.length) : null;
05a48e9e7942atagen2026-10-24 09:32 UTC1305
    if (nextEmote?.start !== emoteQuery?.start) emoteIndex = 0;
05a48e9e7942atagen2026-10-24 09:32 UTC1306
    emoteQuery = nextEmote;
05a48e9e7942atagen2026-10-24 09:32 UTC1307
    const nextCommand = composerEl ? commandQueryAt(composerEl.value, composerEl.selectionStart ?? composerEl.value.length) : null;
05a48e9e7942atagen2026-10-24 09:32 UTC1308
    if (nextCommand !== commandQuery) commandIndex = 0;
05a48e9e7942atagen2026-10-24 09:32 UTC1309
    commandQuery = nextCommand;
cf23dbf4e77catagen2026-10-23 06:36 UTC1310
    const next = composerEl && roomId ? mentionQueryAt(composerEl.value, composerEl.selectionStart ?? composerEl.value.length) : null;
cf23dbf4e77catagen2026-10-23 06:36 UTC1311
    if (next && !mentionQuery && roomId && !$membersByRoom[roomId]) void loadMembers(roomId);
cf23dbf4e77catagen2026-10-23 06:36 UTC1312
    if (next?.start !== mentionQuery?.start) mentionIndex = 0;
cf23dbf4e77catagen2026-10-23 06:36 UTC1313
    mentionQuery = next;
cf23dbf4e77catagen2026-10-23 06:36 UTC1314
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1315
cf23dbf4e77catagen2026-10-23 06:36 UTC1316
  async function pickMention(person: Person): Promise<void> {
cf23dbf4e77catagen2026-10-23 06:36 UTC1317
    const roomId = $selectedRoomId;
cf23dbf4e77catagen2026-10-23 06:36 UTC1318
    if (!mentionQuery || !roomId || !composerEl) return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1319
    const caret = composerEl.selectionStart ?? composer.length;
cf23dbf4e77catagen2026-10-23 06:36 UTC1320
    const inserted = `${person.name} `;
cf23dbf4e77catagen2026-10-23 06:36 UTC1321
    composer = composer.slice(0, mentionQuery.start) + inserted + composer.slice(caret);
cf23dbf4e77catagen2026-10-23 06:36 UTC1322
    const at = mentionQuery.start + inserted.length;
cf23dbf4e77catagen2026-10-23 06:36 UTC1323
    pickedMentions = {
cf23dbf4e77catagen2026-10-23 06:36 UTC1324
      ...pickedMentions,
cf23dbf4e77catagen2026-10-23 06:36 UTC1325
      [roomId]: [...(pickedMentions[roomId] ?? []), { user_id: person.user_id, text: person.name }]
cf23dbf4e77catagen2026-10-23 06:36 UTC1326
    };
cf23dbf4e77catagen2026-10-23 06:36 UTC1327
    mentionQuery = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC1328
    await tick();
cf23dbf4e77catagen2026-10-23 06:36 UTC1329
    composerEl.focus();
cf23dbf4e77catagen2026-10-23 06:36 UTC1330
    composerEl.setSelectionRange(at, at);
cf23dbf4e77catagen2026-10-23 06:36 UTC1331
  }
cf23dbf4e77catagen2026-10-23 06:36 UTC1332
973f8fbdaf80atagen2026-09-28 09:10 UTC1333
  function onComposerKey(ev: KeyboardEvent): void {
2021154f9e16atagen2026-10-25 02:37 UTC1334
    if (ev.isComposing || composerComposing) return;
05a48e9e7942atagen2026-10-24 09:32 UTC1335
    if (emoteQuery && emoteCandidates.length > 0) {
05a48e9e7942atagen2026-10-24 09:32 UTC1336
      if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp') {
05a48e9e7942atagen2026-10-24 09:32 UTC1337
        ev.preventDefault();
05a48e9e7942atagen2026-10-24 09:32 UTC1338
        const step = ev.key === 'ArrowDown' ? 1 : -1;
05a48e9e7942atagen2026-10-24 09:32 UTC1339
        emoteIndex = (emoteIndex + step + emoteCandidates.length) % emoteCandidates.length;
05a48e9e7942atagen2026-10-24 09:32 UTC1340
        return;
05a48e9e7942atagen2026-10-24 09:32 UTC1341
      }
05a48e9e7942atagen2026-10-24 09:32 UTC1342
      if ((ev.key === 'Enter' && !ev.shiftKey) || ev.key === 'Tab') {
05a48e9e7942atagen2026-10-24 09:32 UTC1343
        ev.preventDefault();
05a48e9e7942atagen2026-10-24 09:32 UTC1344
        void pickEmote(emoteCandidates[emoteIndex]);
05a48e9e7942atagen2026-10-24 09:32 UTC1345
        return;
05a48e9e7942atagen2026-10-24 09:32 UTC1346
      }
05a48e9e7942atagen2026-10-24 09:32 UTC1347
      if (ev.key === 'Escape') {
05a48e9e7942atagen2026-10-24 09:32 UTC1348
        ev.stopPropagation();
05a48e9e7942atagen2026-10-24 09:32 UTC1349
        emoteQuery = null;
05a48e9e7942atagen2026-10-24 09:32 UTC1350
        return;
05a48e9e7942atagen2026-10-24 09:32 UTC1351
      }
05a48e9e7942atagen2026-10-24 09:32 UTC1352
    }
05a48e9e7942atagen2026-10-24 09:32 UTC1353
    if (commandQuery !== null && commandCandidates.length > 0) {
05a48e9e7942atagen2026-10-24 09:32 UTC1354
      if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp') {
05a48e9e7942atagen2026-10-24 09:32 UTC1355
        ev.preventDefault();
05a48e9e7942atagen2026-10-24 09:32 UTC1356
        const step = ev.key === 'ArrowDown' ? 1 : -1;
05a48e9e7942atagen2026-10-24 09:32 UTC1357
        commandIndex = (commandIndex + step + commandCandidates.length) % commandCandidates.length;
05a48e9e7942atagen2026-10-24 09:32 UTC1358
        return;
05a48e9e7942atagen2026-10-24 09:32 UTC1359
      }
05a48e9e7942atagen2026-10-24 09:32 UTC1360
      const exact = commandCandidates.length === 1 && commandCandidates[0] === commandQuery;
05a48e9e7942atagen2026-10-24 09:32 UTC1361
      if (ev.key === 'Tab' || (ev.key === 'Enter' && !ev.shiftKey && !exact)) {
05a48e9e7942atagen2026-10-24 09:32 UTC1362
        ev.preventDefault();
05a48e9e7942atagen2026-10-24 09:32 UTC1363
        void pickCommand(commandCandidates[commandIndex]);
05a48e9e7942atagen2026-10-24 09:32 UTC1364
        return;
05a48e9e7942atagen2026-10-24 09:32 UTC1365
      }
05a48e9e7942atagen2026-10-24 09:32 UTC1366
      if (ev.key === 'Escape') {
05a48e9e7942atagen2026-10-24 09:32 UTC1367
        ev.stopPropagation();
05a48e9e7942atagen2026-10-24 09:32 UTC1368
        commandQuery = null;
05a48e9e7942atagen2026-10-24 09:32 UTC1369
        return;
05a48e9e7942atagen2026-10-24 09:32 UTC1370
      }
05a48e9e7942atagen2026-10-24 09:32 UTC1371
    }
cf23dbf4e77catagen2026-10-23 06:36 UTC1372
    if (mentionQuery && mentionCandidates.length > 0) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1373
      if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp') {
cf23dbf4e77catagen2026-10-23 06:36 UTC1374
        ev.preventDefault();
cf23dbf4e77catagen2026-10-23 06:36 UTC1375
        const step = ev.key === 'ArrowDown' ? 1 : -1;
cf23dbf4e77catagen2026-10-23 06:36 UTC1376
        mentionIndex = (mentionIndex + step + mentionCandidates.length) % mentionCandidates.length;
cf23dbf4e77catagen2026-10-23 06:36 UTC1377
        return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1378
      }
cf23dbf4e77catagen2026-10-23 06:36 UTC1379
      if ((ev.key === 'Enter' && !ev.shiftKey) || ev.key === 'Tab') {
cf23dbf4e77catagen2026-10-23 06:36 UTC1380
        ev.preventDefault();
cf23dbf4e77catagen2026-10-23 06:36 UTC1381
        void pickMention(mentionCandidates[mentionIndex]);
cf23dbf4e77catagen2026-10-23 06:36 UTC1382
        return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1383
      }
cf23dbf4e77catagen2026-10-23 06:36 UTC1384
      if (ev.key === 'Escape') {
cf23dbf4e77catagen2026-10-23 06:36 UTC1385
        ev.stopPropagation();
cf23dbf4e77catagen2026-10-23 06:36 UTC1386
        mentionQuery = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC1387
        return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1388
      }
cf23dbf4e77catagen2026-10-23 06:36 UTC1389
    }
6d6a4c34bdc1atagen2026-10-24 06:51 UTC1390
    if (ev.key === 'Enter' && !ev.shiftKey && !insideOpenFence(composer, composerEl?.selectionStart ?? composer.length)) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1391
      ev.preventDefault();
973f8fbdaf80atagen2026-09-28 09:10 UTC1392
      send();
cf23dbf4e77catagen2026-10-23 06:36 UTC1393
    } else if (ev.key === 'Escape' && editing) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1394
      ev.stopPropagation();
cf23dbf4e77catagen2026-10-23 06:36 UTC1395
      cancelEdit();
df3c0f2b3da4atagen2026-10-22 13:07 UTC1396
    } else if (ev.key === 'Escape' && replyingTo) {
df3c0f2b3da4atagen2026-10-22 13:07 UTC1397
      ev.stopPropagation();
df3c0f2b3da4atagen2026-10-22 13:07 UTC1398
      replyingTo = null;
cf23dbf4e77catagen2026-10-23 06:36 UTC1399
    } else if (ev.key === 'ArrowUp' && !composer && !editing && editLastOwn()) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1400
      ev.preventDefault();
973f8fbdaf80atagen2026-09-28 09:10 UTC1401
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1402
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1403
cf23dbf4e77catagen2026-10-23 06:36 UTC1404
  function pickFiles(): void {
973f8fbdaf80atagen2026-09-28 09:10 UTC1405
    const roomId = $selectedRoomId;
cf23dbf4e77catagen2026-10-23 06:36 UTC1406
    if (!roomId || !openReady[roomId]) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1407
    fileInput?.click();
973f8fbdaf80atagen2026-09-28 09:10 UTC1408
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1409
cf23dbf4e77catagen2026-10-23 06:36 UTC1410
  function onFileChosen(): void {
cf23dbf4e77catagen2026-10-23 06:36 UTC1411
    stageFiles(Array.from(fileInput?.files ?? []));
df3c0f2b3da4atagen2026-10-22 13:07 UTC1412
    if (fileInput) fileInput.value = '';
df3c0f2b3da4atagen2026-10-22 13:07 UTC1413
  }
df3c0f2b3da4atagen2026-10-22 13:07 UTC1414
df3c0f2b3da4atagen2026-10-22 13:07 UTC1415
  function onComposerPaste(ev: ClipboardEvent): void {
df3c0f2b3da4atagen2026-10-22 13:07 UTC1416
    const data = ev.clipboardData;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1417
    // Office apps put a rendered image next to the copied text, so only take the image when there is no plain text.
df3c0f2b3da4atagen2026-10-22 13:07 UTC1418
    if (!data || data.types.includes('text/plain')) return;
cf23dbf4e77catagen2026-10-23 06:36 UTC1419
    const images = Array.from(data.files).filter((f) => f.type.startsWith('image/'));
cf23dbf4e77catagen2026-10-23 06:36 UTC1420
    if (images.length === 0) return;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1421
    ev.preventDefault();
cf23dbf4e77catagen2026-10-23 06:36 UTC1422
    stageFiles(images);
df3c0f2b3da4atagen2026-10-22 13:07 UTC1423
  }
df3c0f2b3da4atagen2026-10-22 13:07 UTC1424
ecb8598b38afatagen2026-10-22 09:19 UTC1425
  async function react(eventId: string, key: string, shortcode?: string): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC1426
    const roomId = $selectedRoomId;
973f8fbdaf80atagen2026-09-28 09:10 UTC1427
    if (!roomId || !eventId || reacting) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1428
    reacting = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC1429
    try {
ecb8598b38afatagen2026-10-22 09:19 UTC1430
      await reactToMessage(roomId, eventId, key, shortcode);
973f8fbdaf80atagen2026-09-28 09:10 UTC1431
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1432
      pushBanner(e instanceof Error ? e.message : 'Reaction failed');
973f8fbdaf80atagen2026-09-28 09:10 UTC1433
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC1434
      reacting = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC1435
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1436
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1437
ecb8598b38afatagen2026-10-22 09:19 UTC1438
  function previewLoader(roomId: string): (url: string) => void {
ecb8598b38afatagen2026-10-22 09:19 UTC1439
    return (url) => requestLinkPreview(roomId, url);
ecb8598b38afatagen2026-10-22 09:19 UTC1440
  }
ecb8598b38afatagen2026-10-22 09:19 UTC1441
ecb8598b38afatagen2026-10-22 09:19 UTC1442
  async function changeEncryptedPreviews(enabled: boolean): Promise<void> {
ecb8598b38afatagen2026-10-22 09:19 UTC1443
    try {
ecb8598b38afatagen2026-10-22 09:19 UTC1444
      await saveUrlPreviewSettings({ encrypted_rooms: enabled });
ecb8598b38afatagen2026-10-22 09:19 UTC1445
    } catch (e) {
ecb8598b38afatagen2026-10-22 09:19 UTC1446
      pushBanner(e instanceof Error ? e.message : 'Could not save link preview setting');
ecb8598b38afatagen2026-10-22 09:19 UTC1447
    }
ecb8598b38afatagen2026-10-22 09:19 UTC1448
  }
ecb8598b38afatagen2026-10-22 09:19 UTC1449
544a170ead2catagen2026-10-20 11:47 UTC1450
  async function changeQuickReactions(list: QuickReaction[]): Promise<void> {
544a170ead2catagen2026-10-20 11:47 UTC1451
    try {
544a170ead2catagen2026-10-20 11:47 UTC1452
      await saveQuickReactions(list);
544a170ead2catagen2026-10-20 11:47 UTC1453
    } catch (e) {
544a170ead2catagen2026-10-20 11:47 UTC1454
      pushBanner(e instanceof Error ? e.message : 'Could not save quick reactions');
544a170ead2catagen2026-10-20 11:47 UTC1455
    }
544a170ead2catagen2026-10-20 11:47 UTC1456
  }
544a170ead2catagen2026-10-20 11:47 UTC1457
973f8fbdaf80atagen2026-09-28 09:10 UTC1458
  async function paginate(): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC1459
    const roomId = $selectedRoomId;
9f996e377406atagen2026-10-25 03:32 UTC1460
    if (!roomId || paginateBusy || currentRepairActive) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1461
    paginateBusy = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC1462
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC1463
      await paginateRoom(roomId);
973f8fbdaf80atagen2026-09-28 09:10 UTC1464
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1465
      pushBanner(e instanceof Error ? e.message : 'Loading older messages failed');
973f8fbdaf80atagen2026-09-28 09:10 UTC1466
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC1467
      paginateBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC1468
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1469
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1470
973f8fbdaf80atagen2026-09-28 09:10 UTC1471
  async function loadMembers(roomId: string): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC1472
    if (membersFor === roomId && $membersLoading) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1473
    membersFor = roomId;
973f8fbdaf80atagen2026-09-28 09:10 UTC1474
    membersLoading.set(true);
973f8fbdaf80atagen2026-09-28 09:10 UTC1475
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC1476
      const res = await getMembers(roomId);
973f8fbdaf80atagen2026-09-28 09:10 UTC1477
      membersByRoom.update((all) => ({ ...all, [roomId]: res.members }));
973f8fbdaf80atagen2026-09-28 09:10 UTC1478
      avatarByUser = { ...avatarByUser, ...avatarMap(res.members) };
973f8fbdaf80atagen2026-09-28 09:10 UTC1479
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1480
      pushBanner(e instanceof Error ? e.message : 'Could not load members');
973f8fbdaf80atagen2026-09-28 09:10 UTC1481
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC1482
      if (membersFor === roomId) membersLoading.set(false);
973f8fbdaf80atagen2026-09-28 09:10 UTC1483
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1484
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1485
973f8fbdaf80atagen2026-09-28 09:10 UTC1486
  function avatarMap(list: MemberSummary[]): Record<string, string | null> {
973f8fbdaf80atagen2026-09-28 09:10 UTC1487
    const next: Record<string, string | null> = {};
973f8fbdaf80atagen2026-09-28 09:10 UTC1488
    for (const member of list) next[member.user_id] = member.avatar;
973f8fbdaf80atagen2026-09-28 09:10 UTC1489
    return next;
973f8fbdaf80atagen2026-09-28 09:10 UTC1490
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1491
df3c0f2b3da4atagen2026-10-22 13:07 UTC1492
  function peopleIn(list: TimelineItem[], roster: MemberSummary[]): Record<string, Person> {
df3c0f2b3da4atagen2026-10-22 13:07 UTC1493
    const out: Record<string, Person> = {};
df3c0f2b3da4atagen2026-10-22 13:07 UTC1494
    for (const item of list) {
df3c0f2b3da4atagen2026-10-22 13:07 UTC1495
      if (item.kind !== 'event') continue;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1496
      const s = item.event.sender;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1497
      out[s.user_id] = { user_id: s.user_id, name: senderLabel(s), avatar: s.avatar };
df3c0f2b3da4atagen2026-10-22 13:07 UTC1498
    }
df3c0f2b3da4atagen2026-10-22 13:07 UTC1499
    for (const m of roster) out[m.user_id] = { user_id: m.user_id, name: m.name, avatar: m.avatar };
df3c0f2b3da4atagen2026-10-22 13:07 UTC1500
    return out;
df3c0f2b3da4atagen2026-10-22 13:07 UTC1501
  }
df3c0f2b3da4atagen2026-10-22 13:07 UTC1502
973f8fbdaf80atagen2026-09-28 09:10 UTC1503
  function senderAvatarFor(userId: string): string | null {
973f8fbdaf80atagen2026-09-28 09:10 UTC1504
    return avatarByUser[userId] ?? null;
973f8fbdaf80atagen2026-09-28 09:10 UTC1505
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1506
973f8fbdaf80atagen2026-09-28 09:10 UTC1507
  function toggleMembers(): void {
973f8fbdaf80atagen2026-09-28 09:10 UTC1508
    membersOpen = !membersOpen;
dfd1feaae855atagen2026-10-24 10:54 UTC1509
    if (membersOpen && $selectedRoomId) {
dfd1feaae855atagen2026-10-24 10:54 UTC1510
      void loadMembers($selectedRoomId);
dfd1feaae855atagen2026-10-24 10:54 UTC1511
      void loadLevels($selectedRoomId);
dfd1feaae855atagen2026-10-24 10:54 UTC1512
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1513
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1514
973f8fbdaf80atagen2026-09-28 09:10 UTC1515
  async function join(target: string): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC1516
    const room = target.trim();
973f8fbdaf80atagen2026-09-28 09:10 UTC1517
    if (!room || joinBusy) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1518
    joinBusy = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC1519
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC1520
      const res = await joinRoom(room);
973f8fbdaf80atagen2026-09-28 09:10 UTC1521
      joinTarget = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC1522
      dialog = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC1523
      await refreshRooms();
973f8fbdaf80atagen2026-09-28 09:10 UTC1524
      await selectRoom(res.room_id);
973f8fbdaf80atagen2026-09-28 09:10 UTC1525
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1526
      pushBanner(e instanceof Error ? e.message : 'Join failed');
973f8fbdaf80atagen2026-09-28 09:10 UTC1527
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC1528
      joinBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC1529
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1530
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1531
973f8fbdaf80atagen2026-09-28 09:10 UTC1532
  async function create(): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC1533
    const name = createName.trim();
973f8fbdaf80atagen2026-09-28 09:10 UTC1534
    if (!name || createBusy) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1535
    createBusy = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC1536
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC1537
      const res = await createRoom(name, createTopic.trim() || undefined);
973f8fbdaf80atagen2026-09-28 09:10 UTC1538
      createName = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC1539
      createTopic = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC1540
      dialog = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC1541
      await refreshRooms();
973f8fbdaf80atagen2026-09-28 09:10 UTC1542
      await selectRoom(res.room_id);
973f8fbdaf80atagen2026-09-28 09:10 UTC1543
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1544
      pushBanner(e instanceof Error ? e.message : 'Create room failed');
973f8fbdaf80atagen2026-09-28 09:10 UTC1545
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC1546
      createBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC1547
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1548
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1549
d8624c214c04atagen2026-10-24 08:24 UTC1550
  async function leave(roomId: string | null = $selectedRoomId): Promise<void> {
973f8fbdaf80atagen2026-09-28 09:10 UTC1551
    if (!roomId || leaveBusy) return;
973f8fbdaf80atagen2026-09-28 09:10 UTC1552
    leaveBusy = true;
973f8fbdaf80atagen2026-09-28 09:10 UTC1553
    stopTyping();
973f8fbdaf80atagen2026-09-28 09:10 UTC1554
    try {
973f8fbdaf80atagen2026-09-28 09:10 UTC1555
      await leaveRoom(roomId);
973f8fbdaf80atagen2026-09-28 09:10 UTC1556
      if ($selectedRoomId === roomId) selectedRoomId.set(null);
cf23dbf4e77catagen2026-10-23 06:36 UTC1557
      if (warmRooms.includes(roomId)) {
cf23dbf4e77catagen2026-10-23 06:36 UTC1558
        forgetOpenRoom(roomId);
cf23dbf4e77catagen2026-10-23 06:36 UTC1559
        closeRoom(roomId).catch(() => undefined);
cf23dbf4e77catagen2026-10-23 06:36 UTC1560
      }
973f8fbdaf80atagen2026-09-28 09:10 UTC1561
      await refreshRooms();
973f8fbdaf80atagen2026-09-28 09:10 UTC1562
    } catch (e) {
973f8fbdaf80atagen2026-09-28 09:10 UTC1563
      pushBanner(e instanceof Error ? e.message : 'Leave failed');
973f8fbdaf80atagen2026-09-28 09:10 UTC1564
    } finally {
973f8fbdaf80atagen2026-09-28 09:10 UTC1565
      leaveBusy = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC1566
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1567
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1568
973f8fbdaf80atagen2026-09-28 09:10 UTC1569
  function connectionClass(state: string): string {
973f8fbdaf80atagen2026-09-28 09:10 UTC1570
    if (state === 'online') return 'dot-online';
973f8fbdaf80atagen2026-09-28 09:10 UTC1571
    if (state === 'connecting' || state === 'reconnecting') return 'dot-busy';
973f8fbdaf80atagen2026-09-28 09:10 UTC1572
    return 'dot-off';
973f8fbdaf80atagen2026-09-28 09:10 UTC1573
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1574
7cca1d5628d1atagen2026-10-24 07:36 UTC1575
  let dragSpaceId: string | null = null;
7cca1d5628d1atagen2026-10-24 07:36 UTC1576
  let dropTarget: { id: string; after: boolean } | null = null;
05a48e9e7942atagen2026-10-24 09:32 UTC1577
  let menu: { items: MenuItem[]; x: number; y: number; above?: boolean } | null = null;
d8624c214c04atagen2026-10-24 08:24 UTC1578
  let userCard: { userId: string; x: number; y: number; confirm: 'kick' | 'ban' | null } | null = null;
d8624c214c04atagen2026-10-24 08:24 UTC1579
  let levelsByRoom: Record<string, PowerLevels | null> = {};
d8624c214c04atagen2026-10-24 08:24 UTC1580
  let peeking: string | null = null;
d8624c214c04atagen2026-10-24 08:24 UTC1581
d8624c214c04atagen2026-10-24 08:24 UTC1582
  $: roomLevels = $selectedRoomId ? (levelsByRoom[$selectedRoomId] ?? null) : null;
d8624c214c04atagen2026-10-24 08:24 UTC1583
d8624c214c04atagen2026-10-24 08:24 UTC1584
  function personFor(userId: string): Person {
d8624c214c04atagen2026-10-24 08:24 UTC1585
    return people[userId] ?? { user_id: userId, name: userId, avatar: avatarByUser[userId] ?? null };
d8624c214c04atagen2026-10-24 08:24 UTC1586
  }
d8624c214c04atagen2026-10-24 08:24 UTC1587
d8624c214c04atagen2026-10-24 08:24 UTC1588
  function memberFor(userId: string): MemberSummary | null {
d8624c214c04atagen2026-10-24 08:24 UTC1589
    return members.find((m) => m.user_id === userId) ?? null;
d8624c214c04atagen2026-10-24 08:24 UTC1590
  }
d8624c214c04atagen2026-10-24 08:24 UTC1591
d8624c214c04atagen2026-10-24 08:24 UTC1592
  async function loadLevels(roomId: string): Promise<void> {
d8624c214c04atagen2026-10-24 08:24 UTC1593
    try {
d8624c214c04atagen2026-10-24 08:24 UTC1594
      const levels = parsePowerLevels(await runCommand({ op: 'power_levels', room_id: roomId }));
d8624c214c04atagen2026-10-24 08:24 UTC1595
      levelsByRoom = { ...levelsByRoom, [roomId]: levels };
d8624c214c04atagen2026-10-24 08:24 UTC1596
    } catch {
d8624c214c04atagen2026-10-24 08:24 UTC1597
      levelsByRoom = { ...levelsByRoom, [roomId]: levelsByRoom[roomId] ?? null };
d8624c214c04atagen2026-10-24 08:24 UTC1598
    }
d8624c214c04atagen2026-10-24 08:24 UTC1599
  }
d8624c214c04atagen2026-10-24 08:24 UTC1600
d8624c214c04atagen2026-10-24 08:24 UTC1601
  async function openUser(userId: string, x: number, y: number, asMenu: boolean): Promise<void> {
d8624c214c04atagen2026-10-24 08:24 UTC1602
    const roomId = $selectedRoomId;
d8624c214c04atagen2026-10-24 08:24 UTC1603
    if (roomId && !(roomId in levelsByRoom)) await loadLevels(roomId);
d8624c214c04atagen2026-10-24 08:24 UTC1604
    else if (roomId) void loadLevels(roomId);
d8624c214c04atagen2026-10-24 08:24 UTC1605
    if (asMenu) menu = { items: userMenuItems(userId, x, y), x, y };
d8624c214c04atagen2026-10-24 08:24 UTC1606
    else userCard = { userId, x, y, confirm: null };
d8624c214c04atagen2026-10-24 08:24 UTC1607
  }
d8624c214c04atagen2026-10-24 08:24 UTC1608
d8624c214c04atagen2026-10-24 08:24 UTC1609
  function copyText(text: string): void {
d8624c214c04atagen2026-10-24 08:24 UTC1610
    navigator.clipboard.writeText(text).catch(() => pushBanner('Could not copy to the clipboard'));
d8624c214c04atagen2026-10-24 08:24 UTC1611
  }
d8624c214c04atagen2026-10-24 08:24 UTC1612
d8624c214c04atagen2026-10-24 08:24 UTC1613
  function userMenuItems(userId: string, x: number, y: number): MenuItem[] {
d8624c214c04atagen2026-10-24 08:24 UTC1614
    const own = userId === $sessionUser;
d8624c214c04atagen2026-10-24 08:24 UTC1615
    const member = memberFor(userId);
d8624c214c04atagen2026-10-24 08:24 UTC1616
    const items: MenuItem[] = [];
d8624c214c04atagen2026-10-24 08:24 UTC1617
    if (!own) items.push({ label: 'Message', action: () => void userAction(userId, { kind: 'message' }) });
d8624c214c04atagen2026-10-24 08:24 UTC1618
    items.push({ label: 'Mention', action: () => void userAction(userId, { kind: 'mention' }) });
d8624c214c04atagen2026-10-24 08:24 UTC1619
    items.push({ label: 'Copy user ID', action: () => copyText(userId) });
05a48e9e7942atagen2026-10-24 09:32 UTC1620
    const firstModeration = items.length;
d8624c214c04atagen2026-10-24 08:24 UTC1621
    if (roomLevels && $sessionUser) {
d8624c214c04atagen2026-10-24 08:24 UTC1622
      const can = allowed(roomLevels, $sessionUser, userId);
d8624c214c04atagen2026-10-24 08:24 UTC1623
      const banned = member?.membership === 'Ban';
d8624c214c04atagen2026-10-24 08:24 UTC1624
      if (can.setLevel && !own) {
d8624c214c04atagen2026-10-24 08:24 UTC1625
        const muted = isMuted(roomLevels, userId);
d8624c214c04atagen2026-10-24 08:24 UTC1626
        items.push({ label: muted ? 'Unmute' : 'Mute', action: () => void userAction(userId, { kind: muted ? 'unmute' : 'mute' }) });
d8624c214c04atagen2026-10-24 08:24 UTC1627
      }
d8624c214c04atagen2026-10-24 08:24 UTC1628
      if (can.kick && !banned) items.push({ label: 'Kick…', danger: true, action: () => (userCard = { userId, x, y, confirm: 'kick' }) });
d8624c214c04atagen2026-10-24 08:24 UTC1629
      if (can.ban && banned) items.push({ label: 'Unban', action: () => void userAction(userId, { kind: 'unban' }) });
d8624c214c04atagen2026-10-24 08:24 UTC1630
      if (can.ban && !banned) items.push({ label: 'Ban…', danger: true, action: () => (userCard = { userId, x, y, confirm: 'ban' }) });
d8624c214c04atagen2026-10-24 08:24 UTC1631
      if (can.setLevel) items.push({ label: 'Power level…', action: () => (userCard = { userId, x, y, confirm: null }) });
d8624c214c04atagen2026-10-24 08:24 UTC1632
    }
05a48e9e7942atagen2026-10-24 09:32 UTC1633
    if (items[firstModeration]) items[firstModeration] = { ...items[firstModeration], divider: true };
d8624c214c04atagen2026-10-24 08:24 UTC1634
    if (!own) {
d8624c214c04atagen2026-10-24 08:24 UTC1635
      const kind = member?.ignored ? 'unignore' : 'ignore';
05a48e9e7942atagen2026-10-24 09:32 UTC1636
      items.push({ label: member?.ignored ? 'Unignore' : 'Ignore', divider: true, action: () => void userAction(userId, { kind }) });
d8624c214c04atagen2026-10-24 08:24 UTC1637
    }
d8624c214c04atagen2026-10-24 08:24 UTC1638
    return items;
d8624c214c04atagen2026-10-24 08:24 UTC1639
  }
d8624c214c04atagen2026-10-24 08:24 UTC1640
d8624c214c04atagen2026-10-24 08:24 UTC1641
  async function insertMention(person: Person): Promise<void> {
d8624c214c04atagen2026-10-24 08:24 UTC1642
    const roomId = $selectedRoomId;
d8624c214c04atagen2026-10-24 08:24 UTC1643
    if (!roomId) return;
d8624c214c04atagen2026-10-24 08:24 UTC1644
    const lead = composer && !/\s$/.test(composer) ? ' ' : '';
d8624c214c04atagen2026-10-24 08:24 UTC1645
    composer = `${composer}${lead}${person.name} `;
d8624c214c04atagen2026-10-24 08:24 UTC1646
    pickedMentions = {
d8624c214c04atagen2026-10-24 08:24 UTC1647
      ...pickedMentions,
d8624c214c04atagen2026-10-24 08:24 UTC1648
      [roomId]: [...(pickedMentions[roomId] ?? []), { user_id: person.user_id, text: person.name }]
d8624c214c04atagen2026-10-24 08:24 UTC1649
    };
d8624c214c04atagen2026-10-24 08:24 UTC1650
    await tick();
d8624c214c04atagen2026-10-24 08:24 UTC1651
    composerEl?.focus();
d8624c214c04atagen2026-10-24 08:24 UTC1652
    composerEl?.setSelectionRange(composer.length, composer.length);
d8624c214c04atagen2026-10-24 08:24 UTC1653
  }
d8624c214c04atagen2026-10-24 08:24 UTC1654
d8624c214c04atagen2026-10-24 08:24 UTC1655
  async function userAction(userId: string, action: UserAction): Promise<void> {
d8624c214c04atagen2026-10-24 08:24 UTC1656
    const roomId = $selectedRoomId;
d8624c214c04atagen2026-10-24 08:24 UTC1657
    try {
d8624c214c04atagen2026-10-24 08:24 UTC1658
      switch (action.kind) {
d8624c214c04atagen2026-10-24 08:24 UTC1659
        case 'message': {
d8624c214c04atagen2026-10-24 08:24 UTC1660
          const res = (await runCommand({ op: 'direct', user_id: userId })) as { room_id: string };
d8624c214c04atagen2026-10-24 08:24 UTC1661
          await refreshRooms();
d8624c214c04atagen2026-10-24 08:24 UTC1662
          await selectRoom(res.room_id);
d8624c214c04atagen2026-10-24 08:24 UTC1663
          return;
d8624c214c04atagen2026-10-24 08:24 UTC1664
        }
d8624c214c04atagen2026-10-24 08:24 UTC1665
        case 'mention':
d8624c214c04atagen2026-10-24 08:24 UTC1666
          await insertMention(personFor(userId));
d8624c214c04atagen2026-10-24 08:24 UTC1667
          return;
d8624c214c04atagen2026-10-24 08:24 UTC1668
        case 'ignore':
d8624c214c04atagen2026-10-24 08:24 UTC1669
        case 'unignore':
d8624c214c04atagen2026-10-24 08:24 UTC1670
          await runCommand({ op: action.kind, user_id: userId });
d8624c214c04atagen2026-10-24 08:24 UTC1671
          if (roomId) void loadMembers(roomId);
d8624c214c04atagen2026-10-24 08:24 UTC1672
          return;
d8624c214c04atagen2026-10-24 08:24 UTC1673
      }
d8624c214c04atagen2026-10-24 08:24 UTC1674
      if (!roomId) return;
d8624c214c04atagen2026-10-24 08:24 UTC1675
      switch (action.kind) {
d8624c214c04atagen2026-10-24 08:24 UTC1676
        case 'kick':
d8624c214c04atagen2026-10-24 08:24 UTC1677
        case 'ban':
d8624c214c04atagen2026-10-24 08:24 UTC1678
          await runCommand({ op: action.kind, room_id: roomId, user_id: userId, reason: action.reason });
d8624c214c04atagen2026-10-24 08:24 UTC1679
          break;
d8624c214c04atagen2026-10-24 08:24 UTC1680
        case 'unban':
d8624c214c04atagen2026-10-24 08:24 UTC1681
          await runCommand({ op: 'unban', room_id: roomId, user_id: userId, reason: null });
d8624c214c04atagen2026-10-24 08:24 UTC1682
          break;
d8624c214c04atagen2026-10-24 08:24 UTC1683
        case 'mute':
d8624c214c04atagen2026-10-24 08:24 UTC1684
        case 'unmute':
d8624c214c04atagen2026-10-24 08:24 UTC1685
          await runCommand({ op: 'mute', room_id: roomId, user_id: userId, muted: action.kind === 'mute' });
d8624c214c04atagen2026-10-24 08:24 UTC1686
          break;
d8624c214c04atagen2026-10-24 08:24 UTC1687
        case 'power':
d8624c214c04atagen2026-10-24 08:24 UTC1688
          await runCommand({ op: 'set_power_level', room_id: roomId, user_id: userId, level: action.level });
d8624c214c04atagen2026-10-24 08:24 UTC1689
          break;
d8624c214c04atagen2026-10-24 08:24 UTC1690
      }
d8624c214c04atagen2026-10-24 08:24 UTC1691
      void loadLevels(roomId);
d8624c214c04atagen2026-10-24 08:24 UTC1692
      void loadMembers(roomId);
d8624c214c04atagen2026-10-24 08:24 UTC1693
    } catch (e) {
d8624c214c04atagen2026-10-24 08:24 UTC1694
      pushBanner(e instanceof Error ? e.message : 'That action failed');
d8624c214c04atagen2026-10-24 08:24 UTC1695
    }
d8624c214c04atagen2026-10-24 08:24 UTC1696
  }
d8624c214c04atagen2026-10-24 08:24 UTC1697
d8624c214c04atagen2026-10-24 08:24 UTC1698
  function roomMenuItems(room: RoomSummary): MenuItem[] {
d8624c214c04atagen2026-10-24 08:24 UTC1699
    const items: MenuItem[] = room.space
d8624c214c04atagen2026-10-24 08:24 UTC1700
      ? [{ label: 'Open', action: () => void selectSpace(room.room_id) }]
d8624c214c04atagen2026-10-24 08:24 UTC1701
      : [
d8624c214c04atagen2026-10-24 08:24 UTC1702
          { label: 'Open', action: () => void selectRoom(room.room_id) },
d8624c214c04atagen2026-10-24 08:24 UTC1703
          { label: 'Peek', action: () => void selectRoom(room.room_id, true) }
d8624c214c04atagen2026-10-24 08:24 UTC1704
        ];
d8624c214c04atagen2026-10-24 08:24 UTC1705
    items.push({ label: room.favourite ? 'Unpin' : room.space ? 'Pin to top' : 'Pin', action: () => void togglePin(room) });
d8624c214c04atagen2026-10-24 08:24 UTC1706
    items.push({ label: 'Copy link', action: () => copyText(`https://matrix.to/#/${room.canonical_alias ?? room.room_id}`) });
d8624c214c04atagen2026-10-24 08:24 UTC1707
    items.push({ label: 'Copy room ID', action: () => copyText(room.room_id) });
9f996e377406atagen2026-10-25 03:32 UTC1708
    if (!room.space && room.membership === 'Joined') {
9f996e377406atagen2026-10-25 03:32 UTC1709
      items.push({ label: 'Repair message history', action: () => void showHistoryRepair(room.room_id) });
9f996e377406atagen2026-10-25 03:32 UTC1710
    }
05a48e9e7942atagen2026-10-24 09:32 UTC1711
    if (room.membership === 'Joined') items.push({ label: 'Leave', danger: true, divider: true, action: () => void leave(room.room_id) });
d8624c214c04atagen2026-10-24 08:24 UTC1712
    return items;
d8624c214c04atagen2026-10-24 08:24 UTC1713
  }
d8624c214c04atagen2026-10-24 08:24 UTC1714
d8624c214c04atagen2026-10-24 08:24 UTC1715
  function openRoomMenu(ev: MouseEvent, room: RoomSummary): void {
d8624c214c04atagen2026-10-24 08:24 UTC1716
    menu = { items: roomMenuItems(room), x: ev.clientX, y: ev.clientY };
d8624c214c04atagen2026-10-24 08:24 UTC1717
  }
d8624c214c04atagen2026-10-24 08:24 UTC1718
d095131eec0eatagen2026-10-24 08:39 UTC1719
  function roomName(roomId: string): string {
d095131eec0eatagen2026-10-24 08:39 UTC1720
    return $rooms.find((r) => r.room_id === roomId)?.name ?? roomId;
d095131eec0eatagen2026-10-24 08:39 UTC1721
  }
d095131eec0eatagen2026-10-24 08:39 UTC1722
d095131eec0eatagen2026-10-24 08:39 UTC1723
  async function sendSticker(roomId: string, pack: ImagePack, image: PackImage): Promise<void> {
d095131eec0eatagen2026-10-24 08:39 UTC1724
    stickersOpen = false;
d095131eec0eatagen2026-10-24 08:39 UTC1725
    stickToBottom = true;
d095131eec0eatagen2026-10-24 08:39 UTC1726
    try {
d095131eec0eatagen2026-10-24 08:39 UTC1727
      await runCommand({ op: 'send_sticker', room_id: roomId, pack_id: pack.id, shortcode: image.shortcode });
d095131eec0eatagen2026-10-24 08:39 UTC1728
      if (peeking === roomId) stopPeeking();
d095131eec0eatagen2026-10-24 08:39 UTC1729
    } catch (e) {
d095131eec0eatagen2026-10-24 08:39 UTC1730
      pushBanner(e instanceof Error ? e.message : 'Could not send the sticker');
d095131eec0eatagen2026-10-24 08:39 UTC1731
    }
d095131eec0eatagen2026-10-24 08:39 UTC1732
  }
d095131eec0eatagen2026-10-24 08:39 UTC1733
d095131eec0eatagen2026-10-24 08:39 UTC1734
  async function runClone(request: CommandRequest, failure: string): Promise<void> {
d095131eec0eatagen2026-10-24 08:39 UTC1735
    try {
d095131eec0eatagen2026-10-24 08:39 UTC1736
      const res = (await runCommand(request)) as { skipped?: string[] } | undefined;
d095131eec0eatagen2026-10-24 08:39 UTC1737
      if (res?.skipped?.length) pushBanner(`Couldn't copy ${res.skipped.map((s) => `:${s}:`).join(', ')}`);
d095131eec0eatagen2026-10-24 08:39 UTC1738
    } catch (e) {
d095131eec0eatagen2026-10-24 08:39 UTC1739
      pushBanner(e instanceof Error ? e.message : failure);
d095131eec0eatagen2026-10-24 08:39 UTC1740
    }
d095131eec0eatagen2026-10-24 08:39 UTC1741
  }
d095131eec0eatagen2026-10-24 08:39 UTC1742
d095131eec0eatagen2026-10-24 08:39 UTC1743
  function openCloneImageMenu(pack: ImagePack, image: PackImage, x: number, y: number): void {
d095131eec0eatagen2026-10-24 08:39 UTC1744
    const items = editableChoices($imagePacks, roomName)
d095131eec0eatagen2026-10-24 08:39 UTC1745
      .filter((c) => c.pack?.id !== pack.id)
d095131eec0eatagen2026-10-24 08:39 UTC1746
      .map((choice) => ({
d095131eec0eatagen2026-10-24 08:39 UTC1747
        label: `Clone to ${choice.label}`,
d095131eec0eatagen2026-10-24 08:39 UTC1748
        action: () =>
d095131eec0eatagen2026-10-24 08:39 UTC1749
          void runClone({ op: 'clone_pack_image', from_pack: pack.id, shortcode: image.shortcode, to: choice.target }, 'Could not clone the sticker')
d095131eec0eatagen2026-10-24 08:39 UTC1750
      }));
d095131eec0eatagen2026-10-24 08:39 UTC1751
    menu = { items, x, y };
d095131eec0eatagen2026-10-24 08:39 UTC1752
  }
d095131eec0eatagen2026-10-24 08:39 UTC1753
d095131eec0eatagen2026-10-24 08:39 UTC1754
  function openClonePackMenu(pack: ImagePack, x: number, y: number): void {
d095131eec0eatagen2026-10-24 08:39 UTC1755
    const packRooms = $rooms.filter((r) => r.can_edit_packs && r.membership === 'Joined');
d095131eec0eatagen2026-10-24 08:39 UTC1756
    const items = clonePackDestinations(pack, packRooms, roomName).map((d) => ({
d095131eec0eatagen2026-10-24 08:39 UTC1757
      label: d.label,
d095131eec0eatagen2026-10-24 08:39 UTC1758
      action: () => void runClone({ op: 'clone_pack', from_pack: pack.id, to: d.target, display_name: d.display_name }, 'Could not clone the pack')
d095131eec0eatagen2026-10-24 08:39 UTC1759
    }));
d095131eec0eatagen2026-10-24 08:39 UTC1760
    menu = { items, x, y };
d095131eec0eatagen2026-10-24 08:39 UTC1761
  }
d095131eec0eatagen2026-10-24 08:39 UTC1762
d095131eec0eatagen2026-10-24 08:39 UTC1763
  function openCloneStickerMenu(eventId: string, body: string, x: number, y: number): void {
d095131eec0eatagen2026-10-24 08:39 UTC1764
    const roomId = $selectedRoomId;
d095131eec0eatagen2026-10-24 08:39 UTC1765
    if (!roomId) return;
d095131eec0eatagen2026-10-24 08:39 UTC1766
    const items = editableChoices($imagePacks, roomName).map((choice) => ({
d095131eec0eatagen2026-10-24 08:39 UTC1767
      label: `Clone to ${choice.label}`,
d095131eec0eatagen2026-10-24 08:39 UTC1768
      action: () => {
d095131eec0eatagen2026-10-24 08:39 UTC1769
        const taken = new Set(choice.pack?.images.map((i) => i.shortcode) ?? []);
d095131eec0eatagen2026-10-24 08:39 UTC1770
        void runClone(
d095131eec0eatagen2026-10-24 08:39 UTC1771
          { op: 'clone_sticker', room_id: roomId, event_id: eventId, to: choice.target, shortcode: shortcodeFor(body || 'sticker', taken) },
d095131eec0eatagen2026-10-24 08:39 UTC1772
          'Could not clone the sticker'
d095131eec0eatagen2026-10-24 08:39 UTC1773
        );
d095131eec0eatagen2026-10-24 08:39 UTC1774
      }
d095131eec0eatagen2026-10-24 08:39 UTC1775
    }));
d095131eec0eatagen2026-10-24 08:39 UTC1776
    menu = { items, x, y };
d095131eec0eatagen2026-10-24 08:39 UTC1777
  }
d095131eec0eatagen2026-10-24 08:39 UTC1778
0380cd8c765catagen2026-10-24 09:08 UTC1779
  async function openMessageMenu(event: TimelineEvent, x: number, y: number): Promise<void> {
0380cd8c765catagen2026-10-24 09:08 UTC1780
    const roomId = $selectedRoomId;
0380cd8c765catagen2026-10-24 09:08 UTC1781
    const eventId = event.event_id;
0380cd8c765catagen2026-10-24 09:08 UTC1782
    if (!roomId || !eventId) return;
0380cd8c765catagen2026-10-24 09:08 UTC1783
    if (!(roomId in levelsByRoom)) await loadLevels(roomId);
0380cd8c765catagen2026-10-24 09:08 UTC1784
    const joined = selectedRoom?.membership === 'Joined';
0380cd8c765catagen2026-10-24 09:08 UTC1785
    const content = event.content;
0380cd8c765catagen2026-10-24 09:08 UTC1786
    const items: MenuItem[] = [];
0380cd8c765catagen2026-10-24 09:08 UTC1787
    if (joined) {
0380cd8c765catagen2026-10-24 09:08 UTC1788
      items.push({
0380cd8c765catagen2026-10-24 09:08 UTC1789
        label: 'Reply',
0380cd8c765catagen2026-10-24 09:08 UTC1790
        action: () =>
0380cd8c765catagen2026-10-24 09:08 UTC1791
          startReply({
0380cd8c765catagen2026-10-24 09:08 UTC1792
            event_id: eventId,
0380cd8c765catagen2026-10-24 09:08 UTC1793
            details: { kind: 'Ready', sender: event.sender, content, timestamp_ms: event.timestamp_ms }
0380cd8c765catagen2026-10-24 09:08 UTC1794
          })
0380cd8c765catagen2026-10-24 09:08 UTC1795
      });
0380cd8c765catagen2026-10-24 09:08 UTC1796
    }
0380cd8c765catagen2026-10-24 09:08 UTC1797
    if (joined && event.own && event.editable && content.kind === 'Message' && content.message.kind === 'Text') {
0380cd8c765catagen2026-10-24 09:08 UTC1798
      const body = content.message.body;
0380cd8c765catagen2026-10-24 09:08 UTC1799
      items.push({ label: 'Edit', action: () => startEdit(eventId, body) });
0380cd8c765catagen2026-10-24 09:08 UTC1800
    }
0380cd8c765catagen2026-10-24 09:08 UTC1801
    if (content.kind === 'Message' && content.message.body) {
0380cd8c765catagen2026-10-24 09:08 UTC1802
      const body = content.message.body;
0380cd8c765catagen2026-10-24 09:08 UTC1803
      items.push({ label: 'Copy text', action: () => copyText(body) });
0380cd8c765catagen2026-10-24 09:08 UTC1804
    }
0380cd8c765catagen2026-10-24 09:08 UTC1805
    items.push({ label: 'Copy link', action: () => copyText(`https://matrix.to/#/${roomId}/${eventId}`) });
05a48e9e7942atagen2026-10-24 09:32 UTC1806
    if (joined && selectedRoom?.can_pin && content.kind !== 'Redacted') {
05a48e9e7942atagen2026-10-24 09:32 UTC1807
      const pinned = selectedRoom.pinned_events.includes(eventId);
05a48e9e7942atagen2026-10-24 09:32 UTC1808
      items.push({ label: pinned ? 'Unpin' : 'Pin', action: () => setPinned(eventId, !pinned) });
05a48e9e7942atagen2026-10-24 09:32 UTC1809
    }
0380cd8c765catagen2026-10-24 09:08 UTC1810
    if (content.kind === 'Sticker') {
0380cd8c765catagen2026-10-24 09:08 UTC1811
      const body = content.body;
0380cd8c765catagen2026-10-24 09:08 UTC1812
      items.push({ label: 'Clone sticker…', action: () => openCloneStickerMenu(eventId, body, x, y) });
0380cd8c765catagen2026-10-24 09:08 UTC1813
    }
0380cd8c765catagen2026-10-24 09:08 UTC1814
    const me = $sessionUser;
0380cd8c765catagen2026-10-24 09:08 UTC1815
    if (joined && me && roomLevels && canRedact(roomLevels, me, event.sender.user_id) && content.kind !== 'Redacted') {
0380cd8c765catagen2026-10-24 09:08 UTC1816
      items.push({
0380cd8c765catagen2026-10-24 09:08 UTC1817
        label: 'Delete message…',
0380cd8c765catagen2026-10-24 09:08 UTC1818
        danger: true,
0380cd8c765catagen2026-10-24 09:08 UTC1819
        action: () =>
0380cd8c765catagen2026-10-24 09:08 UTC1820
          (menu = {
0380cd8c765catagen2026-10-24 09:08 UTC1821
            x,
0380cd8c765catagen2026-10-24 09:08 UTC1822
            y,
0380cd8c765catagen2026-10-24 09:08 UTC1823
            items: [
0380cd8c765catagen2026-10-24 09:08 UTC1824
              { label: 'Delete', danger: true, action: () => void runClone({ op: 'redact', room_id: roomId, event_id: eventId, reason: null }, 'Could not delete the message') },
0380cd8c765catagen2026-10-24 09:08 UTC1825
              { label: 'Cancel', action: () => undefined }
0380cd8c765catagen2026-10-24 09:08 UTC1826
            ]
0380cd8c765catagen2026-10-24 09:08 UTC1827
          })
0380cd8c765catagen2026-10-24 09:08 UTC1828
      });
0380cd8c765catagen2026-10-24 09:08 UTC1829
    }
05a48e9e7942atagen2026-10-24 09:32 UTC1830
    if (!event.own) {
05a48e9e7942atagen2026-10-24 09:32 UTC1831
      const person = userMenuItems(event.sender.user_id, x, y);
05a48e9e7942atagen2026-10-24 09:32 UTC1832
      if (person[0]) person[0] = { ...person[0], divider: true };
05a48e9e7942atagen2026-10-24 09:32 UTC1833
      items.push(...person);
05a48e9e7942atagen2026-10-24 09:32 UTC1834
    }
0380cd8c765catagen2026-10-24 09:08 UTC1835
    menu = { items, x, y };
0380cd8c765catagen2026-10-24 09:08 UTC1836
  }
0380cd8c765catagen2026-10-24 09:08 UTC1837
05a48e9e7942atagen2026-10-24 09:32 UTC1838
  function openAccountMenu(ev: MouseEvent): void {
05a48e9e7942atagen2026-10-24 09:32 UTC1839
    const rect = (ev.currentTarget as HTMLElement).getBoundingClientRect();
05a48e9e7942atagen2026-10-24 09:32 UTC1840
    menu = {
05a48e9e7942atagen2026-10-24 09:32 UTC1841
      x: rect.left,
05a48e9e7942atagen2026-10-24 09:32 UTC1842
      y: rect.top - 6,
05a48e9e7942atagen2026-10-24 09:32 UTC1843
      above: true,
05a48e9e7942atagen2026-10-24 09:32 UTC1844
      items: [
05a48e9e7942atagen2026-10-24 09:32 UTC1845
        { label: 'Security', action: () => (dialog = 'security') },
05a48e9e7942atagen2026-10-24 09:32 UTC1846
        { label: 'Settings', action: () => (dialog = 'settings') },
05a48e9e7942atagen2026-10-24 09:32 UTC1847
        { label: 'Sticker and emoji packs', action: () => (dialog = 'packs') },
05a48e9e7942atagen2026-10-24 09:32 UTC1848
        { label: 'Log out', danger: true, divider: true, action: () => void doLogout() }
05a48e9e7942atagen2026-10-24 09:32 UTC1849
      ]
05a48e9e7942atagen2026-10-24 09:32 UTC1850
    };
05a48e9e7942atagen2026-10-24 09:32 UTC1851
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1852
05a48e9e7942atagen2026-10-24 09:32 UTC1853
  let resizing = false;
05a48e9e7942atagen2026-10-24 09:32 UTC1854
05a48e9e7942atagen2026-10-24 09:32 UTC1855
  function startResize(ev: PointerEvent, pane: 'side' | 'members'): void {
05a48e9e7942atagen2026-10-24 09:32 UTC1856
    if (ev.button !== 0) return;
05a48e9e7942atagen2026-10-24 09:32 UTC1857
    ev.preventDefault();
05a48e9e7942atagen2026-10-24 09:32 UTC1858
    const handle = ev.currentTarget as HTMLElement;
05a48e9e7942atagen2026-10-24 09:32 UTC1859
    handle.setPointerCapture(ev.pointerId);
05a48e9e7942atagen2026-10-24 09:32 UTC1860
    const store = pane === 'side' ? sideWidth : membersWidth;
05a48e9e7942atagen2026-10-24 09:32 UTC1861
    const range = pane === 'side' ? SIDE_WIDTH : MEMBERS_WIDTH;
05a48e9e7942atagen2026-10-24 09:32 UTC1862
    const startX = ev.clientX;
05a48e9e7942atagen2026-10-24 09:32 UTC1863
    const startWidth = pane === 'side' ? $sideWidth : $membersWidth;
05a48e9e7942atagen2026-10-24 09:32 UTC1864
    resizing = true;
05a48e9e7942atagen2026-10-24 09:32 UTC1865
    const move = (e: PointerEvent) => {
05a48e9e7942atagen2026-10-24 09:32 UTC1866
      const delta = pane === 'side' ? e.clientX - startX : startX - e.clientX;
05a48e9e7942atagen2026-10-24 09:32 UTC1867
      store.set(Math.round(Math.min(range.max, Math.max(range.min, startWidth + delta))));
05a48e9e7942atagen2026-10-24 09:32 UTC1868
    };
05a48e9e7942atagen2026-10-24 09:32 UTC1869
    const end = () => {
05a48e9e7942atagen2026-10-24 09:32 UTC1870
      resizing = false;
05a48e9e7942atagen2026-10-24 09:32 UTC1871
      handle.removeEventListener('pointermove', move);
05a48e9e7942atagen2026-10-24 09:32 UTC1872
      handle.removeEventListener('pointerup', end);
05a48e9e7942atagen2026-10-24 09:32 UTC1873
      handle.removeEventListener('pointercancel', end);
05a48e9e7942atagen2026-10-24 09:32 UTC1874
    };
05a48e9e7942atagen2026-10-24 09:32 UTC1875
    handle.addEventListener('pointermove', move);
05a48e9e7942atagen2026-10-24 09:32 UTC1876
    handle.addEventListener('pointerup', end);
05a48e9e7942atagen2026-10-24 09:32 UTC1877
    handle.addEventListener('pointercancel', end);
05a48e9e7942atagen2026-10-24 09:32 UTC1878
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1879
05a48e9e7942atagen2026-10-24 09:32 UTC1880
  function resetWidth(pane: 'side' | 'members'): void {
05a48e9e7942atagen2026-10-24 09:32 UTC1881
    if (pane === 'side') sideWidth.set(SIDE_WIDTH.default);
05a48e9e7942atagen2026-10-24 09:32 UTC1882
    else membersWidth.set(MEMBERS_WIDTH.default);
05a48e9e7942atagen2026-10-24 09:32 UTC1883
  }
05a48e9e7942atagen2026-10-24 09:32 UTC1884
d8624c214c04atagen2026-10-24 08:24 UTC1885
  function stopPeeking(): void {
d8624c214c04atagen2026-10-24 08:24 UTC1886
    peeking = null;
d8624c214c04atagen2026-10-24 08:24 UTC1887
    queueReadReceipt();
d8624c214c04atagen2026-10-24 08:24 UTC1888
  }
7cca1d5628d1atagen2026-10-24 07:36 UTC1889
7cca1d5628d1atagen2026-10-24 07:36 UTC1890
  async function togglePin(room: RoomSummary): Promise<void> {
7cca1d5628d1atagen2026-10-24 07:36 UTC1891
    try {
7cca1d5628d1atagen2026-10-24 07:36 UTC1892
      await runCommand({ op: 'set_favourite', room_id: room.room_id, favourite: !room.favourite });
7cca1d5628d1atagen2026-10-24 07:36 UTC1893
    } catch (e) {
7cca1d5628d1atagen2026-10-24 07:36 UTC1894
      pushBanner(e instanceof Error ? e.message : 'Could not change the pin');
7cca1d5628d1atagen2026-10-24 07:36 UTC1895
    }
7cca1d5628d1atagen2026-10-24 07:36 UTC1896
  }
7cca1d5628d1atagen2026-10-24 07:36 UTC1897
7cca1d5628d1atagen2026-10-24 07:36 UTC1898
  function startRailDrag(ev: DragEvent, id: string): void {
7cca1d5628d1atagen2026-10-24 07:36 UTC1899
    dragSpaceId = id;
7cca1d5628d1atagen2026-10-24 07:36 UTC1900
    if (ev.dataTransfer) {
7cca1d5628d1atagen2026-10-24 07:36 UTC1901
      ev.dataTransfer.effectAllowed = 'move';
7cca1d5628d1atagen2026-10-24 07:36 UTC1902
      ev.dataTransfer.setData('text/plain', id);
7cca1d5628d1atagen2026-10-24 07:36 UTC1903
    }
7cca1d5628d1atagen2026-10-24 07:36 UTC1904
  }
7cca1d5628d1atagen2026-10-24 07:36 UTC1905
7cca1d5628d1atagen2026-10-24 07:36 UTC1906
  function overRailSpace(ev: DragEvent, space: RoomSummary): void {
7cca1d5628d1atagen2026-10-24 07:36 UTC1907
    const dragged = orderedRail.find((s) => s.room_id === dragSpaceId);
7cca1d5628d1atagen2026-10-24 07:36 UTC1908
    if (!dragged || dragged.room_id === space.room_id || dragged.favourite !== space.favourite) return;
7cca1d5628d1atagen2026-10-24 07:36 UTC1909
    ev.preventDefault();
7cca1d5628d1atagen2026-10-24 07:36 UTC1910
    const rect = (ev.currentTarget as HTMLElement).getBoundingClientRect();
7cca1d5628d1atagen2026-10-24 07:36 UTC1911
    dropTarget = { id: space.room_id, after: ev.clientY > rect.top + rect.height / 2 };
7cca1d5628d1atagen2026-10-24 07:36 UTC1912
  }
7cca1d5628d1atagen2026-10-24 07:36 UTC1913
7cca1d5628d1atagen2026-10-24 07:36 UTC1914
  async function dropRailSpace(): Promise<void> {
7cca1d5628d1atagen2026-10-24 07:36 UTC1915
    const moved = dragSpaceId;
7cca1d5628d1atagen2026-10-24 07:36 UTC1916
    const target = dropTarget;
7cca1d5628d1atagen2026-10-24 07:36 UTC1917
    dragSpaceId = null;
7cca1d5628d1atagen2026-10-24 07:36 UTC1918
    dropTarget = null;
7cca1d5628d1atagen2026-10-24 07:36 UTC1919
    if (!moved || !target) return;
7cca1d5628d1atagen2026-10-24 07:36 UTC1920
    const ids = orderedRail.map((s) => s.room_id);
7cca1d5628d1atagen2026-10-24 07:36 UTC1921
    const before = target.after ? (ids[ids.indexOf(target.id) + 1] ?? null) : target.id;
7cca1d5628d1atagen2026-10-24 07:36 UTC1922
    const order = moveBefore(ids, moved, before === moved ? null : before);
7cca1d5628d1atagen2026-10-24 07:36 UTC1923
    if (order.join() === ids.join()) return;
7cca1d5628d1atagen2026-10-24 07:36 UTC1924
    railOverride = order;
7cca1d5628d1atagen2026-10-24 07:36 UTC1925
    try {
7cca1d5628d1atagen2026-10-24 07:36 UTC1926
      await runCommand({ op: 'reorder_spaces', order });
7cca1d5628d1atagen2026-10-24 07:36 UTC1927
    } catch (e) {
7cca1d5628d1atagen2026-10-24 07:36 UTC1928
      railOverride = null;
7cca1d5628d1atagen2026-10-24 07:36 UTC1929
      pushBanner(e instanceof Error ? e.message : 'Could not reorder spaces');
7cca1d5628d1atagen2026-10-24 07:36 UTC1930
    }
7cca1d5628d1atagen2026-10-24 07:36 UTC1931
  }
7cca1d5628d1atagen2026-10-24 07:36 UTC1932
e15025643a20atagen2026-10-24 06:51 UTC1933
  let roomMenuOpen = false;
e15025643a20atagen2026-10-24 06:51 UTC1934
  let roomMenuEl: HTMLDivElement | null = null;
e15025643a20atagen2026-10-24 06:51 UTC1935
e15025643a20atagen2026-10-24 06:51 UTC1936
  function roomMenuAction(action: () => void): void {
e15025643a20atagen2026-10-24 06:51 UTC1937
    roomMenuOpen = false;
e15025643a20atagen2026-10-24 06:51 UTC1938
    action();
e15025643a20atagen2026-10-24 06:51 UTC1939
  }
e15025643a20atagen2026-10-24 06:51 UTC1940
e15025643a20atagen2026-10-24 06:51 UTC1941
  function closeRoomMenuOutside(ev: PointerEvent): void {
e15025643a20atagen2026-10-24 06:51 UTC1942
    if (roomMenuOpen && !roomMenuEl?.contains(ev.target as Node)) roomMenuOpen = false;
e15025643a20atagen2026-10-24 06:51 UTC1943
  }
e15025643a20atagen2026-10-24 06:51 UTC1944
973f8fbdaf80atagen2026-09-28 09:10 UTC1945
  function onKeydown(ev: KeyboardEvent): void {
973f8fbdaf80atagen2026-09-28 09:10 UTC1946
    if (ev.key === 'Escape') {
e15025643a20atagen2026-10-24 06:51 UTC1947
      if (roomMenuOpen) roomMenuOpen = false;
e15025643a20atagen2026-10-24 06:51 UTC1948
      else if (dialog) dialog = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC1949
      else if (membersOpen && window.innerWidth < 1100) membersOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC1950
      else if (sidebarOpen) sidebarOpen = false;
973f8fbdaf80atagen2026-09-28 09:10 UTC1951
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC1952
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC1953
</script>
973f8fbdaf80atagen2026-09-28 09:10 UTC1954
e15025643a20atagen2026-10-24 06:51 UTC1955
<svelte:window
e15025643a20atagen2026-10-24 06:51 UTC1956
  on:keydown={onKeydown}
e15025643a20atagen2026-10-24 06:51 UTC1957
  on:pointerdown={closeRoomMenuOutside}
e15025643a20atagen2026-10-24 06:51 UTC1958
/>
973f8fbdaf80atagen2026-09-28 09:10 UTC1959
973f8fbdaf80atagen2026-09-28 09:10 UTC1960
{#if !booted}
d4c0d65f690aatagen2026-10-24 12:50 UTC1961
  <div class="splash" role="status" aria-label="Loading Malice" out:fade={{ duration: motionDuration(260) }}>
973f8fbdaf80atagen2026-09-28 09:10 UTC1962
    <div class="splash-mark" aria-hidden="true">M</div>
973f8fbdaf80atagen2026-09-28 09:10 UTC1963
    <p>Loading Malice…</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC1964
  </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC1965
{:else if $blocked}
d4c0d65f690aatagen2026-10-24 12:50 UTC1966
  <div class="splash" role="status" aria-label="Malice is open in another tab" in:fade={{ duration: motionDuration(220) }}>
973f8fbdaf80atagen2026-09-28 09:10 UTC1967
    <div class="splash-mark" aria-hidden="true">M</div>
973f8fbdaf80atagen2026-09-28 09:10 UTC1968
    <p>Malice is open in another tab. Close this tab or use that one instead.</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC1969
  </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC1970
{:else if $sessionUser == null}
973f8fbdaf80atagen2026-09-28 09:10 UTC1971
  <LoginPanel softLogout={$softLogout} on:done={(ev) => afterLogin(ev.detail)} />
973f8fbdaf80atagen2026-09-28 09:10 UTC1972
{:else}
e15025643a20atagen2026-10-24 06:51 UTC1973
  <div
e15025643a20atagen2026-10-24 06:51 UTC1974
    class="app"
d4c0d65f690aatagen2026-10-24 12:50 UTC1975
    in:fade={{ duration: motionDuration(220) }}
7efc4c6d41abatagen2026-10-24 11:40 UTC1976
    class:nav-folded={$navFolded}
e15025643a20atagen2026-10-24 06:51 UTC1977
    class:rail-folded={$railFolded && selectedRoom}
e15025643a20atagen2026-10-24 06:51 UTC1978
    class:members-open={selectedRoom && membersOpen}
05a48e9e7942atagen2026-10-24 09:32 UTC1979
    class:resizing
05a48e9e7942atagen2026-10-24 09:32 UTC1980
    style:--side-open={`${$sideWidth}px`}
05a48e9e7942atagen2026-10-24 09:32 UTC1981
    style:--members-open={`${$membersWidth}px`}
e15025643a20atagen2026-10-24 06:51 UTC1982
    style:--msg-gap={`${$messageSpacing}px`}
e15025643a20atagen2026-10-24 06:51 UTC1983
    style:--msg-line-height={$lineHeight}
e15025643a20atagen2026-10-24 06:51 UTC1984
  >
1d319c602324atagen2026-10-24 09:14 UTC1985
    <header class="chat-head">
1d319c602324atagen2026-10-24 09:14 UTC1986
      <button
1d319c602324atagen2026-10-24 09:14 UTC1987
        type="button"
1d319c602324atagen2026-10-24 09:14 UTC1988
        class="icon-btn only-mobile"
1d319c602324atagen2026-10-24 09:14 UTC1989
        aria-label="Open room list"
1d319c602324atagen2026-10-24 09:14 UTC1990
        on:click={() => (sidebarOpen = true)}
1d319c602324atagen2026-10-24 09:14 UTC1991
      >
1d319c602324atagen2026-10-24 09:14 UTC1992
        <span aria-hidden="true">☰</span>
1d319c602324atagen2026-10-24 09:14 UTC1993
      </button>
1d319c602324atagen2026-10-24 09:14 UTC1994
      <button
1d319c602324atagen2026-10-24 09:14 UTC1995
        type="button"
1d319c602324atagen2026-10-24 09:14 UTC1996
        class="icon-btn only-desktop pane-toggle"
1d319c602324atagen2026-10-24 09:14 UTC1997
        aria-pressed={!$railFolded}
1d319c602324atagen2026-10-24 09:14 UTC1998
        aria-label={$railFolded ? 'Show spaces' : 'Hide spaces'}
1d319c602324atagen2026-10-24 09:14 UTC1999
        title={$railFolded ? 'Show spaces' : 'Hide spaces'}
1d319c602324atagen2026-10-24 09:14 UTC2000
        on:click={() => railFolded.update((v) => !v)}
1d319c602324atagen2026-10-24 09:14 UTC2001
      >
1d319c602324atagen2026-10-24 09:14 UTC2002
        <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true">
1d319c602324atagen2026-10-24 09:14 UTC2003
          <rect x="3" y="4" width="18" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="2" />
1d319c602324atagen2026-10-24 09:14 UTC2004
          <circle cx="7" cy="9" r="1.4" fill="currentColor" />
1d319c602324atagen2026-10-24 09:14 UTC2005
          <circle cx="7" cy="13" r="1.4" fill="currentColor" />
1d319c602324atagen2026-10-24 09:14 UTC2006
          <circle cx="7" cy="17" r="1.4" fill="currentColor" />
1d319c602324atagen2026-10-24 09:14 UTC2007
        </svg>
1d319c602324atagen2026-10-24 09:14 UTC2008
      </button>
1d319c602324atagen2026-10-24 09:14 UTC2009
      <button
1d319c602324atagen2026-10-24 09:14 UTC2010
        type="button"
1d319c602324atagen2026-10-24 09:14 UTC2011
        class="icon-btn only-desktop pane-toggle"
1d319c602324atagen2026-10-24 09:14 UTC2012
        aria-pressed={!$navFolded}
1d319c602324atagen2026-10-24 09:14 UTC2013
        aria-label={$navFolded ? 'Show channels' : 'Hide channels'}
1d319c602324atagen2026-10-24 09:14 UTC2014
        title={$navFolded ? 'Show channels' : 'Hide channels'}
dfd1feaae855atagen2026-10-24 10:54 UTC2015
        on:click={toggleChannelsPane}
1d319c602324atagen2026-10-24 09:14 UTC2016
      >
1d319c602324atagen2026-10-24 09:14 UTC2017
        <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true">
1d319c602324atagen2026-10-24 09:14 UTC2018
          <rect x="3" y="4" width="18" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="2" />
1d319c602324atagen2026-10-24 09:14 UTC2019
          <path d="M10 4v16" stroke="currentColor" stroke-width="2" />
1d319c602324atagen2026-10-24 09:14 UTC2020
        </svg>
1d319c602324atagen2026-10-24 09:14 UTC2021
      </button>
1d319c602324atagen2026-10-24 09:14 UTC2022
      {#if selectedRoom}
1d319c602324atagen2026-10-24 09:14 UTC2023
      <div class="head-title">
1d319c602324atagen2026-10-24 09:14 UTC2024
        <div class="head-room">
f604ef6df0c4atagen2026-10-24 10:08 UTC2025
          <MxcAvatar mxc={selectedRoom.avatar} label={selectedRoom.name} size={36} shape="rounded" />
1d319c602324atagen2026-10-24 09:14 UTC2026
          <div class="head-room-text">
445bf199a9cfatagen2026-10-25 02:56 UTC2027
            <h1><EmojiText text={selectedRoom.name} /></h1>
1d319c602324atagen2026-10-24 09:14 UTC2028
            <div class="head-meta">
1d319c602324atagen2026-10-24 09:14 UTC2029
              {#if selectedRoom.space}
1d319c602324atagen2026-10-24 09:14 UTC2030
                <span class="pill">space</span>
1d319c602324atagen2026-10-24 09:14 UTC2031
              {/if}
1d319c602324atagen2026-10-24 09:14 UTC2032
              {#if selectedRoom.encrypted}
445bf199a9cfatagen2026-10-25 02:56 UTC2033
                <span class="pill" title="End-to-end encrypted"><EmojiText text="🔒 encrypted" /></span>
1d319c602324atagen2026-10-24 09:14 UTC2034
              {/if}
1d319c602324atagen2026-10-24 09:14 UTC2035
              {#if selectedRoom.direct}
1d319c602324atagen2026-10-24 09:14 UTC2036
                <span class="pill">direct</span>
1d319c602324atagen2026-10-24 09:14 UTC2037
              {/if}
f604ef6df0c4atagen2026-10-24 10:08 UTC2038
              {#if $connection !== 'online'}
f604ef6df0c4atagen2026-10-24 10:08 UTC2039
                <span class="conn" title={`Sync state: ${$connection}`}>
f604ef6df0c4atagen2026-10-24 10:08 UTC2040
                  <span class="dot {connectionClass($connection)}" aria-hidden="true"></span>
f604ef6df0c4atagen2026-10-24 10:08 UTC2041
                  {$connection}
f604ef6df0c4atagen2026-10-24 10:08 UTC2042
                </span>
f604ef6df0c4atagen2026-10-24 10:08 UTC2043
              {/if}
1d319c602324atagen2026-10-24 09:14 UTC2044
            </div>
1d319c602324atagen2026-10-24 09:14 UTC2045
          </div>
1d319c602324atagen2026-10-24 09:14 UTC2046
        </div>
1d319c602324atagen2026-10-24 09:14 UTC2047
      </div>
1d319c602324atagen2026-10-24 09:14 UTC2048
      {:else}
1d319c602324atagen2026-10-24 09:14 UTC2049
      <div class="head-title">
1d319c602324atagen2026-10-24 09:14 UTC2050
        <div class="head-room">
1d319c602324atagen2026-10-24 09:14 UTC2051
          {#if selectedSpace}
1d319c602324atagen2026-10-24 09:14 UTC2052
            <MxcAvatar mxc={selectedSpace.avatar} label={selectedSpace.name} size={36} shape="rounded" />
1d319c602324atagen2026-10-24 09:14 UTC2053
          {/if}
1d319c602324atagen2026-10-24 09:14 UTC2054
          <div class="head-room-text">
668ab5c30531atagen2026-10-25 03:13 UTC2055
            <h1><EmojiText text={mentionsOpen ? 'Mentions' : selectedSpace?.name ?? 'Home'} /></h1>
1d319c602324atagen2026-10-24 09:14 UTC2056
          </div>
1d319c602324atagen2026-10-24 09:14 UTC2057
        </div>
1d319c602324atagen2026-10-24 09:14 UTC2058
      </div>
1d319c602324atagen2026-10-24 09:14 UTC2059
      {/if}
1d319c602324atagen2026-10-24 09:14 UTC2060
      <div class="head-actions">
1d319c602324atagen2026-10-24 09:14 UTC2061
        {#if selectedRoom}
1d319c602324atagen2026-10-24 09:14 UTC2062
        {#if peeking === selectedRoom.room_id}
1d319c602324atagen2026-10-24 09:14 UTC2063
          <button type="button" class="icon-btn" aria-pressed="true" aria-label="Stop peeking" title="Stop peeking" on:click={stopPeeking}>
1d319c602324atagen2026-10-24 09:14 UTC2064
            <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true">
1d319c602324atagen2026-10-24 09:14 UTC2065
              <path d="M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6S2 12 2 12z" fill="none" stroke="currentColor" stroke-width="2" />
1d319c602324atagen2026-10-24 09:14 UTC2066
              <circle cx="12" cy="12" r="3" fill="currentColor" />
1d319c602324atagen2026-10-24 09:14 UTC2067
            </svg>
1d319c602324atagen2026-10-24 09:14 UTC2068
          </button>
1d319c602324atagen2026-10-24 09:14 UTC2069
        {/if}
1d319c602324atagen2026-10-24 09:14 UTC2070
        {#if selectedRoom.membership !== 'Joined'}
1d319c602324atagen2026-10-24 09:14 UTC2071
          <button
1d319c602324atagen2026-10-24 09:14 UTC2072
            type="button"
1d319c602324atagen2026-10-24 09:14 UTC2073
            class="primary-btn"
1d319c602324atagen2026-10-24 09:14 UTC2074
            disabled={joinBusy}
1d319c602324atagen2026-10-24 09:14 UTC2075
            on:click={() => void join(selectedRoom.room_id)}
1d319c602324atagen2026-10-24 09:14 UTC2076
          >
1d319c602324atagen2026-10-24 09:14 UTC2077
            {joinBusy ? 'Joining…' : 'Join'}
1d319c602324atagen2026-10-24 09:14 UTC2078
          </button>
1d319c602324atagen2026-10-24 09:14 UTC2079
        {/if}
1d319c602324atagen2026-10-24 09:14 UTC2080
        <button
1d319c602324atagen2026-10-24 09:14 UTC2081
          type="button"
1d319c602324atagen2026-10-24 09:14 UTC2082
          class="icon-btn"
1d319c602324atagen2026-10-24 09:14 UTC2083
          aria-pressed={membersOpen}
1d319c602324atagen2026-10-24 09:14 UTC2084
          aria-label={membersOpen ? 'Hide members' : 'Show members'}
1d319c602324atagen2026-10-24 09:14 UTC2085
          title="Members"
1d319c602324atagen2026-10-24 09:14 UTC2086
          on:click={toggleMembers}
1d319c602324atagen2026-10-24 09:14 UTC2087
        >
1d319c602324atagen2026-10-24 09:14 UTC2088
          <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true">
1d319c602324atagen2026-10-24 09:14 UTC2089
            <circle cx="12" cy="8" r="4" fill="none" stroke="currentColor" stroke-width="2" />
1d319c602324atagen2026-10-24 09:14 UTC2090
            <path d="M4 20c0-4 3.6-6 8-6s8 2 8 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
1d319c602324atagen2026-10-24 09:14 UTC2091
          </svg>
1d319c602324atagen2026-10-24 09:14 UTC2092
        </button>
1d319c602324atagen2026-10-24 09:14 UTC2093
        <div class="room-menu-wrap" bind:this={roomMenuEl}>
1d319c602324atagen2026-10-24 09:14 UTC2094
          <button
1d319c602324atagen2026-10-24 09:14 UTC2095
            type="button"
1d319c602324atagen2026-10-24 09:14 UTC2096
            class="icon-btn"
1d319c602324atagen2026-10-24 09:14 UTC2097
            aria-haspopup="menu"
1d319c602324atagen2026-10-24 09:14 UTC2098
            aria-expanded={roomMenuOpen}
1d319c602324atagen2026-10-24 09:14 UTC2099
            aria-label="Room options"
1d319c602324atagen2026-10-24 09:14 UTC2100
            title="Room options"
1d319c602324atagen2026-10-24 09:14 UTC2101
            on:click={() => (roomMenuOpen = !roomMenuOpen)}
1d319c602324atagen2026-10-24 09:14 UTC2102
          >
1d319c602324atagen2026-10-24 09:14 UTC2103
            <span aria-hidden="true">⋯</span>
1d319c602324atagen2026-10-24 09:14 UTC2104
          </button>
1d319c602324atagen2026-10-24 09:14 UTC2105
          {#if roomMenuOpen}
1d319c602324atagen2026-10-24 09:14 UTC2106
            <div class="room-menu" role="menu">
1d319c602324atagen2026-10-24 09:14 UTC2107
              {#if selectedRoom.membership === 'Joined'}
9f996e377406atagen2026-10-25 03:32 UTC2108
                <button type="button" role="menuitem" on:click={() => roomMenuAction(() => void showHistoryRepair(selectedRoom.room_id))}>
9f996e377406atagen2026-10-25 03:32 UTC2109
                  Repair message history
9f996e377406atagen2026-10-25 03:32 UTC2110
                </button>
1d319c602324atagen2026-10-24 09:14 UTC2111
                <button
1d319c602324atagen2026-10-24 09:14 UTC2112
                  type="button"
1d319c602324atagen2026-10-24 09:14 UTC2113
                  role="menuitem"
1d319c602324atagen2026-10-24 09:14 UTC2114
                  class="danger"
1d319c602324atagen2026-10-24 09:14 UTC2115
                  disabled={leaveBusy}
1d319c602324atagen2026-10-24 09:14 UTC2116
                  on:click={() => roomMenuAction(() => void leave())}
1d319c602324atagen2026-10-24 09:14 UTC2117
                >
1d319c602324atagen2026-10-24 09:14 UTC2118
                  {leaveBusy ? 'Leaving…' : 'Leave room'}
1d319c602324atagen2026-10-24 09:14 UTC2119
                </button>
1d319c602324atagen2026-10-24 09:14 UTC2120
              {/if}
1d319c602324atagen2026-10-24 09:14 UTC2121
            </div>
1d319c602324atagen2026-10-24 09:14 UTC2122
          {/if}
1d319c602324atagen2026-10-24 09:14 UTC2123
        </div>
1d319c602324atagen2026-10-24 09:14 UTC2124
        {/if}
1d319c602324atagen2026-10-24 09:14 UTC2125
      </div>
1d319c602324atagen2026-10-24 09:14 UTC2126
    </header>
1d319c602324atagen2026-10-24 09:14 UTC2127
973f8fbdaf80atagen2026-09-28 09:10 UTC2128
    <nav class="rail" aria-label="Servers and spaces">
973f8fbdaf80atagen2026-09-28 09:10 UTC2129
      <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2130
        type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2131
        class="rail-btn"
973f8fbdaf80atagen2026-09-28 09:10 UTC2132
        class:active={selectedSpaceId === null}
973f8fbdaf80atagen2026-09-28 09:10 UTC2133
        title="Home — all channels"
973f8fbdaf80atagen2026-09-28 09:10 UTC2134
        aria-label="Home — all channels"
973f8fbdaf80atagen2026-09-28 09:10 UTC2135
        aria-pressed={selectedSpaceId === null}
973f8fbdaf80atagen2026-09-28 09:10 UTC2136
        on:click={() => void selectHome()}
973f8fbdaf80atagen2026-09-28 09:10 UTC2137
      >
05a48e9e7942atagen2026-10-24 09:32 UTC2138
        <svg viewBox="0 0 24 24" width="19" height="19" aria-hidden="true"><path d="M4 11l8-7 8 7v8a1 1 0 0 1-1 1h-4v-6H9v6H5a1 1 0 0 1-1-1z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" /></svg>
973f8fbdaf80atagen2026-09-28 09:10 UTC2139
      </button>
7cca1d5628d1atagen2026-10-24 07:36 UTC2140
      {#each [pinnedRail, otherRail] as group}
7cca1d5628d1atagen2026-10-24 07:36 UTC2141
        {#if group.length > 0}
7cca1d5628d1atagen2026-10-24 07:36 UTC2142
          <div class="rail-sep" aria-hidden="true"></div>
7cca1d5628d1atagen2026-10-24 07:36 UTC2143
        {/if}
7cca1d5628d1atagen2026-10-24 07:36 UTC2144
        {#each group as space (space.room_id)}
7cca1d5628d1atagen2026-10-24 07:36 UTC2145
          <button
7cca1d5628d1atagen2026-10-24 07:36 UTC2146
            type="button"
7cca1d5628d1atagen2026-10-24 07:36 UTC2147
            class="rail-btn rail-space"
7cca1d5628d1atagen2026-10-24 07:36 UTC2148
            class:active={railSelected === space.room_id}
7cca1d5628d1atagen2026-10-24 07:36 UTC2149
            class:drop-before={dropTarget?.id === space.room_id && !dropTarget.after}
7cca1d5628d1atagen2026-10-24 07:36 UTC2150
            class:drop-after={dropTarget?.id === space.room_id && dropTarget.after}
7cca1d5628d1atagen2026-10-24 07:36 UTC2151
            class:pinned={space.favourite}
7cca1d5628d1atagen2026-10-24 07:36 UTC2152
            title={space.name}
7cca1d5628d1atagen2026-10-24 07:36 UTC2153
            aria-label={`Show channels in space ${space.name}`}
7cca1d5628d1atagen2026-10-24 07:36 UTC2154
            aria-pressed={selectedSpaceId === space.room_id}
7cca1d5628d1atagen2026-10-24 07:36 UTC2155
            draggable="true"
7cca1d5628d1atagen2026-10-24 07:36 UTC2156
            on:click={() => void selectSpace(space.room_id)}
d8624c214c04atagen2026-10-24 08:24 UTC2157
            on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, space)}
7cca1d5628d1atagen2026-10-24 07:36 UTC2158
            on:dragstart={(ev) => startRailDrag(ev, space.room_id)}
7cca1d5628d1atagen2026-10-24 07:36 UTC2159
            on:dragover={(ev) => overRailSpace(ev, space)}
7cca1d5628d1atagen2026-10-24 07:36 UTC2160
            on:dragleave={() => dropTarget?.id === space.room_id && (dropTarget = null)}
7cca1d5628d1atagen2026-10-24 07:36 UTC2161
            on:drop|preventDefault={() => void dropRailSpace()}
7cca1d5628d1atagen2026-10-24 07:36 UTC2162
            on:dragend={() => ((dragSpaceId = null), (dropTarget = null))}
7cca1d5628d1atagen2026-10-24 07:36 UTC2163
          >
7cca1d5628d1atagen2026-10-24 07:36 UTC2164
            <MxcAvatar mxc={space.avatar} label={space.name} size={44} shape="rounded" />
7cca1d5628d1atagen2026-10-24 07:36 UTC2165
          </button>
7cca1d5628d1atagen2026-10-24 07:36 UTC2166
        {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2167
      {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2168
      <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2169
        type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2170
        class="rail-btn rail-add"
973f8fbdaf80atagen2026-09-28 09:10 UTC2171
        aria-label="Join or create a room"
973f8fbdaf80atagen2026-09-28 09:10 UTC2172
        on:click={() => {
973f8fbdaf80atagen2026-09-28 09:10 UTC2173
          dialog = 'join';
973f8fbdaf80atagen2026-09-28 09:10 UTC2174
        }}
973f8fbdaf80atagen2026-09-28 09:10 UTC2175
      >
05a48e9e7942atagen2026-10-24 09:32 UTC2176
        <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"><path d="M12 5v14M5 12h14" stroke="currentColor" stroke-width="2" stroke-linecap="round" /></svg>
973f8fbdaf80atagen2026-09-28 09:10 UTC2177
      </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2178
    </nav>
973f8fbdaf80atagen2026-09-28 09:10 UTC2179
d8624c214c04atagen2026-10-24 08:24 UTC2180
    {#if menu}
05a48e9e7942atagen2026-10-24 09:32 UTC2181
      <ContextMenu items={menu.items} x={menu.x} y={menu.y} above={menu.above ?? false} onClose={() => (menu = null)} />
d8624c214c04atagen2026-10-24 08:24 UTC2182
    {/if}
d8624c214c04atagen2026-10-24 08:24 UTC2183
    {#if userCard}
d8624c214c04atagen2026-10-24 08:24 UTC2184
      {#key userCard}
d8624c214c04atagen2026-10-24 08:24 UTC2185
        {@const cardUser = userCard.userId}
d8624c214c04atagen2026-10-24 08:24 UTC2186
        <UserCard
d8624c214c04atagen2026-10-24 08:24 UTC2187
          person={personFor(cardUser)}
d8624c214c04atagen2026-10-24 08:24 UTC2188
          member={memberFor(cardUser)}
d8624c214c04atagen2026-10-24 08:24 UTC2189
          levels={roomLevels}
d8624c214c04atagen2026-10-24 08:24 UTC2190
          self={$sessionUser ?? null}
d8624c214c04atagen2026-10-24 08:24 UTC2191
          x={userCard.x}
d8624c214c04atagen2026-10-24 08:24 UTC2192
          y={userCard.y}
d8624c214c04atagen2026-10-24 08:24 UTC2193
          confirm={userCard.confirm}
d8624c214c04atagen2026-10-24 08:24 UTC2194
          onAction={(action) => void userAction(cardUser, action)}
d8624c214c04atagen2026-10-24 08:24 UTC2195
          onClose={() => (userCard = null)}
d8624c214c04atagen2026-10-24 08:24 UTC2196
        />
d8624c214c04atagen2026-10-24 08:24 UTC2197
      {/key}
7cca1d5628d1atagen2026-10-24 07:36 UTC2198
    {/if}
7cca1d5628d1atagen2026-10-24 07:36 UTC2199
c04b1e46303fatagen2026-10-24 12:08 UTC2200
    <aside class="sidebar" class:open={sidebarOpen} aria-label="Rooms">
05a48e9e7942atagen2026-10-24 09:32 UTC2201
      <!-- svelte-ignore a11y_no_static_element_interactions -->
05a48e9e7942atagen2026-10-24 09:32 UTC2202
      <div class="pane-resize right" title="Drag to resize" on:pointerdown={(e) => startResize(e, 'side')} on:dblclick={() => resetWidth('side')}></div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2203
      <div class="side-search">
973f8fbdaf80atagen2026-09-28 09:10 UTC2204
        <label class="visually-hidden" for="room-search">Search rooms</label>
973f8fbdaf80atagen2026-09-28 09:10 UTC2205
        <input
973f8fbdaf80atagen2026-09-28 09:10 UTC2206
          id="room-search"
973f8fbdaf80atagen2026-09-28 09:10 UTC2207
          type="search"
973f8fbdaf80atagen2026-09-28 09:10 UTC2208
          placeholder="Search rooms"
973f8fbdaf80atagen2026-09-28 09:10 UTC2209
          bind:value={search}
973f8fbdaf80atagen2026-09-28 09:10 UTC2210
          autocomplete="off"
973f8fbdaf80atagen2026-09-28 09:10 UTC2211
        />
973f8fbdaf80atagen2026-09-28 09:10 UTC2212
        <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2213
          type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2214
          class="icon-btn"
973f8fbdaf80atagen2026-09-28 09:10 UTC2215
          title="Refresh rooms"
973f8fbdaf80atagen2026-09-28 09:10 UTC2216
          aria-label="Refresh rooms"
973f8fbdaf80atagen2026-09-28 09:10 UTC2217
          disabled={roomsLoading}
973f8fbdaf80atagen2026-09-28 09:10 UTC2218
          on:click={() => void refreshRooms()}
973f8fbdaf80atagen2026-09-28 09:10 UTC2219
        >
973f8fbdaf80atagen2026-09-28 09:10 UTC2220
          <span aria-hidden="true">⟳</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2221
        </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2222
      </div>
d4c0d65f690aatagen2026-10-24 12:50 UTC2223
      {#key selectedSpaceId ?? 'home'}
d4c0d65f690aatagen2026-10-24 12:50 UTC2224
      <div class="side-scroll" in:fly={{ y: 5, duration: motionDuration(180) }} out:fade={{ duration: motionDuration(120) }}>
05a48e9e7942atagen2026-10-24 09:32 UTC2225
        {#if selectedSpace && spaceParents.has(selectedSpace.room_id)}
05a48e9e7942atagen2026-10-24 09:32 UTC2226
          {@const parentId = spaceParents.get(selectedSpace.room_id) ?? ''}
05a48e9e7942atagen2026-10-24 09:32 UTC2227
          <button type="button" class="room-row up-row" on:click={() => void selectSpace(parentId)}>
05a48e9e7942atagen2026-10-24 09:32 UTC2228
            <span aria-hidden="true">↑</span>
445bf199a9cfatagen2026-10-25 02:56 UTC2229
            <span class="room-name"><EmojiText text={$rooms.find((r) => r.room_id === parentId)?.name ?? 'Parent space'} /></span>
05a48e9e7942atagen2026-10-24 09:32 UTC2230
          </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2231
        {/if}
668ab5c30531atagen2026-10-25 03:13 UTC2232
        {#if !selectedSpaceId}
668ab5c30531atagen2026-10-25 03:13 UTC2233
          <ul class="room-list">
668ab5c30531atagen2026-10-25 03:13 UTC2234
            <li>
668ab5c30531atagen2026-10-25 03:13 UTC2235
              <button type="button" class="room-row" class:active={mentionsOpen} on:click={selectMentions}>
668ab5c30531atagen2026-10-25 03:13 UTC2236
                <svg width="26" height="26" viewBox="0 0 26 26" aria-hidden="true"><text x="13" y="19" text-anchor="middle" fill="currentColor" font-size="22">@</text></svg>
668ab5c30531atagen2026-10-25 03:13 UTC2237
                <span class="room-name">Mentions</span>
668ab5c30531atagen2026-10-25 03:13 UTC2238
                {#if $mentionsSnapshot && $mentionsSnapshot.unread_count > 0}
668ab5c30531atagen2026-10-25 03:13 UTC2239
                  <span class="badge mention" aria-label={`${$mentionsSnapshot.unread_count} unread mentions`}>{$mentionsSnapshot.unread_count > 99 ? '99+' : $mentionsSnapshot.unread_count}</span>
668ab5c30531atagen2026-10-25 03:13 UTC2240
                {/if}
668ab5c30531atagen2026-10-25 03:13 UTC2241
              </button>
668ab5c30531atagen2026-10-25 03:13 UTC2242
            </li>
668ab5c30531atagen2026-10-25 03:13 UTC2243
          </ul>
668ab5c30531atagen2026-10-25 03:13 UTC2244
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2245
        {#if roomsLoading && $rooms.length === 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2246
          <p class="side-note">Loading rooms…</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2247
        {:else if $rooms.length === 0}
705b1e1062c2atagen2026-10-23 09:05 UTC2248
          <p class="side-note">No rooms yet</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2249
          <div class="side-cta">
973f8fbdaf80atagen2026-09-28 09:10 UTC2250
            <button type="button" on:click={() => (dialog = 'join')}>Join a room</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2251
            <button type="button" on:click={() => (dialog = 'create')}>Create one</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2252
          </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2253
        {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC2254
          {#if selectedSpaceId && spaceChildrenLoading}
705b1e1062c2atagen2026-10-23 09:05 UTC2255
            <p class="side-note">Loading channels…</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2256
          {:else if selectedSpaceId && spaceChildrenError}
445bf199a9cfatagen2026-10-25 02:56 UTC2257
            <p class="side-note" role="alert"><EmojiText text={spaceChildrenError} /></p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2258
            <div class="side-cta">
973f8fbdaf80atagen2026-09-28 09:10 UTC2259
              <button type="button" on:click={() => selectedSpaceId && void selectSpace(selectedSpaceId)}>Retry</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2260
              <button type="button" on:click={() => void selectHome()}>Back to Home</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2261
            </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2262
          {:else if selectedSpaceId && spaceChildIds && channelRooms.length === 0}
705b1e1062c2atagen2026-10-23 09:05 UTC2263
            <p class="side-note">No channels</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2264
            <div class="side-cta">
973f8fbdaf80atagen2026-09-28 09:10 UTC2265
              <button type="button" on:click={() => void selectHome()}>Back to Home</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2266
            </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2267
          {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC2268
            {#if invites.length > 0 && !selectedSpaceId}
973f8fbdaf80atagen2026-09-28 09:10 UTC2269
              <h2 class="side-h">Invites</h2>
973f8fbdaf80atagen2026-09-28 09:10 UTC2270
              <ul class="room-list">
973f8fbdaf80atagen2026-09-28 09:10 UTC2271
                {#each invites as room (room.room_id)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2272
                  <li>
973f8fbdaf80atagen2026-09-28 09:10 UTC2273
                    <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2274
                      type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2275
                      class="room-row"
973f8fbdaf80atagen2026-09-28 09:10 UTC2276
                      class:active={$selectedRoomId === room.room_id}
973f8fbdaf80atagen2026-09-28 09:10 UTC2277
                      on:click={() => void selectRoom(room.room_id)}
d8624c214c04atagen2026-10-24 08:24 UTC2278
                      on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, room)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2279
                    >
973f8fbdaf80atagen2026-09-28 09:10 UTC2280
                      <MxcAvatar mxc={room.avatar} label={room.name} size={26} shape="rounded" />
445bf199a9cfatagen2026-10-25 02:56 UTC2281
                      <span class="room-name"><EmojiText text={room.name} /></span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2282
                      <span
973f8fbdaf80atagen2026-09-28 09:10 UTC2283
                        class="invite-join"
973f8fbdaf80atagen2026-09-28 09:10 UTC2284
                        role="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2285
                        tabindex="0"
973f8fbdaf80atagen2026-09-28 09:10 UTC2286
                        aria-label={`Join ${room.name}`}
973f8fbdaf80atagen2026-09-28 09:10 UTC2287
                        on:click|stopPropagation={() => void join(room.room_id)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2288
                        on:keydown|stopPropagation={(ev) => {
973f8fbdaf80atagen2026-09-28 09:10 UTC2289
                          if (ev.key === 'Enter' || ev.key === ' ') {
973f8fbdaf80atagen2026-09-28 09:10 UTC2290
                            ev.preventDefault();
973f8fbdaf80atagen2026-09-28 09:10 UTC2291
                            void join(room.room_id);
973f8fbdaf80atagen2026-09-28 09:10 UTC2292
                          }
973f8fbdaf80atagen2026-09-28 09:10 UTC2293
                        }}
973f8fbdaf80atagen2026-09-28 09:10 UTC2294
                      >
973f8fbdaf80atagen2026-09-28 09:10 UTC2295
                        Join
973f8fbdaf80atagen2026-09-28 09:10 UTC2296
                      </span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2297
                    </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2298
                  </li>
973f8fbdaf80atagen2026-09-28 09:10 UTC2299
                {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2300
              </ul>
973f8fbdaf80atagen2026-09-28 09:10 UTC2301
            {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2302
973f8fbdaf80atagen2026-09-28 09:10 UTC2303
            {#if directRooms.length > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2304
              <h2 class="side-h">Direct messages</h2>
973f8fbdaf80atagen2026-09-28 09:10 UTC2305
              <ul class="room-list">
973f8fbdaf80atagen2026-09-28 09:10 UTC2306
                {#each directRooms as room (room.room_id)}
7cca1d5628d1atagen2026-10-24 07:36 UTC2307
                  <li class="room-item">
973f8fbdaf80atagen2026-09-28 09:10 UTC2308
                    <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2309
                      type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2310
                      class="room-row"
973f8fbdaf80atagen2026-09-28 09:10 UTC2311
                      class:active={$selectedRoomId === room.room_id}
973f8fbdaf80atagen2026-09-28 09:10 UTC2312
                      aria-current={$selectedRoomId === room.room_id ? 'true' : undefined}
973f8fbdaf80atagen2026-09-28 09:10 UTC2313
                      on:click={() => void selectRoom(room.room_id)}
d8624c214c04atagen2026-10-24 08:24 UTC2314
                      on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, room)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2315
                    >
973f8fbdaf80atagen2026-09-28 09:10 UTC2316
                      <MxcAvatar mxc={room.avatar} label={room.name} size={26} />
445bf199a9cfatagen2026-10-25 02:56 UTC2317
                      <span class="room-name"><EmojiText text={room.name} /></span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2318
                      {#if roomUnread(room) > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2319
                        <span
973f8fbdaf80atagen2026-09-28 09:10 UTC2320
                          class="badge"
973f8fbdaf80atagen2026-09-28 09:10 UTC2321
                          class:mention={room.unread_mentions > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2322
                          aria-label={`${roomUnread(room)} unread`}
973f8fbdaf80atagen2026-09-28 09:10 UTC2323
                        >
973f8fbdaf80atagen2026-09-28 09:10 UTC2324
                          {roomUnread(room) > 99 ? '99+' : roomUnread(room)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2325
                        </span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2326
                      {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2327
                    </button>
7cca1d5628d1atagen2026-10-24 07:36 UTC2328
                    <PinButton pinned={room.favourite} label={room.name} onToggle={() => void togglePin(room)} />
973f8fbdaf80atagen2026-09-28 09:10 UTC2329
                  </li>
973f8fbdaf80atagen2026-09-28 09:10 UTC2330
                {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2331
              </ul>
973f8fbdaf80atagen2026-09-28 09:10 UTC2332
            {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2333
973f8fbdaf80atagen2026-09-28 09:10 UTC2334
            {#if groupRooms.length > 0}
705b1e1062c2atagen2026-10-23 09:05 UTC2335
              <h2 class="side-h">{selectedSpace ? 'Channels' : 'Rooms'}</h2>
973f8fbdaf80atagen2026-09-28 09:10 UTC2336
              <ul class="room-list">
973f8fbdaf80atagen2026-09-28 09:10 UTC2337
                {#each groupRooms as room (room.room_id)}
7cca1d5628d1atagen2026-10-24 07:36 UTC2338
                  <li class="room-item">
973f8fbdaf80atagen2026-09-28 09:10 UTC2339
                    <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2340
                      type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2341
                      class="room-row"
973f8fbdaf80atagen2026-09-28 09:10 UTC2342
                      class:active={$selectedRoomId === room.room_id}
973f8fbdaf80atagen2026-09-28 09:10 UTC2343
                      aria-current={$selectedRoomId === room.room_id ? 'true' : undefined}
973f8fbdaf80atagen2026-09-28 09:10 UTC2344
                      on:click={() => void selectRoom(room.room_id)}
d8624c214c04atagen2026-10-24 08:24 UTC2345
                      on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, room)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2346
                    >
973f8fbdaf80atagen2026-09-28 09:10 UTC2347
                      <MxcAvatar mxc={room.avatar} label={room.name} size={26} shape="rounded" />
445bf199a9cfatagen2026-10-25 02:56 UTC2348
                      <span class="room-name"><EmojiText text={room.name} /></span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2349
                      {#if roomUnread(room) > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2350
                        <span
973f8fbdaf80atagen2026-09-28 09:10 UTC2351
                          class="badge"
973f8fbdaf80atagen2026-09-28 09:10 UTC2352
                          class:mention={room.unread_mentions > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2353
                          aria-label={`${roomUnread(room)} unread`}
973f8fbdaf80atagen2026-09-28 09:10 UTC2354
                        >
973f8fbdaf80atagen2026-09-28 09:10 UTC2355
                          {roomUnread(room) > 99 ? '99+' : roomUnread(room)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2356
                        </span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2357
                      {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2358
                    </button>
7cca1d5628d1atagen2026-10-24 07:36 UTC2359
                    <PinButton pinned={room.favourite} label={room.name} onToggle={() => void togglePin(room)} />
973f8fbdaf80atagen2026-09-28 09:10 UTC2360
                  </li>
973f8fbdaf80atagen2026-09-28 09:10 UTC2361
                {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2362
              </ul>
973f8fbdaf80atagen2026-09-28 09:10 UTC2363
            {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2364
cf23dbf4e77catagen2026-10-23 06:36 UTC2365
            {#if spaceList.length > 0}
cf23dbf4e77catagen2026-10-23 06:36 UTC2366
              <h2 class="side-h">{selectedSpace ? 'Subspaces' : 'Spaces'}</h2>
973f8fbdaf80atagen2026-09-28 09:10 UTC2367
              <ul class="room-list">
973f8fbdaf80atagen2026-09-28 09:10 UTC2368
                {#each spaceList as room (room.room_id)}
7cca1d5628d1atagen2026-10-24 07:36 UTC2369
                  <li class="room-item">
973f8fbdaf80atagen2026-09-28 09:10 UTC2370
                    <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2371
                      type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2372
                      class="room-row"
973f8fbdaf80atagen2026-09-28 09:10 UTC2373
                      class:active={selectedSpaceId === room.room_id}
973f8fbdaf80atagen2026-09-28 09:10 UTC2374
                      aria-label={`Show channels in space ${room.name}`}
973f8fbdaf80atagen2026-09-28 09:10 UTC2375
                      on:click={() => void selectSpace(room.room_id)}
d8624c214c04atagen2026-10-24 08:24 UTC2376
                      on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, room)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2377
                    >
973f8fbdaf80atagen2026-09-28 09:10 UTC2378
                      <MxcAvatar mxc={room.avatar} label={room.name} size={26} shape="rounded" />
445bf199a9cfatagen2026-10-25 02:56 UTC2379
                      <span class="room-name"><EmojiText text={room.name} /></span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2380
                    </button>
7cca1d5628d1atagen2026-10-24 07:36 UTC2381
                    <PinButton pinned={room.favourite} label={room.name} onToggle={() => void togglePin(room)} />
973f8fbdaf80atagen2026-09-28 09:10 UTC2382
                  </li>
973f8fbdaf80atagen2026-09-28 09:10 UTC2383
                {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2384
              </ul>
973f8fbdaf80atagen2026-09-28 09:10 UTC2385
            {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2386
973f8fbdaf80atagen2026-09-28 09:10 UTC2387
            {#if query && visibleRooms.length === 0}
445bf199a9cfatagen2026-10-25 02:56 UTC2388
              <p class="side-note">No rooms match “<EmojiText text={search.trim()} />”.</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2389
            {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2390
          {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2391
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2392
      </div>
d4c0d65f690aatagen2026-10-24 12:50 UTC2393
      {/key}
973f8fbdaf80atagen2026-09-28 09:10 UTC2394
05a48e9e7942atagen2026-10-24 09:32 UTC2395
    </aside>
05a48e9e7942atagen2026-10-24 09:32 UTC2396
    <div class="account">
05a48e9e7942atagen2026-10-24 09:32 UTC2397
      <button type="button" class="me-btn" title={$sessionUser} aria-haspopup="menu" on:click={openAccountMenu}>
05a48e9e7942atagen2026-10-24 09:32 UTC2398
        {#if profileMxc}
05a48e9e7942atagen2026-10-24 09:32 UTC2399
          <MxcAvatar mxc={profileMxc} label={profile?.display_name ?? $sessionUser} size={32} />
05a48e9e7942atagen2026-10-24 09:32 UTC2400
        {:else}
05a48e9e7942atagen2026-10-24 09:32 UTC2401
          <span class="me-avatar" aria-hidden="true">{$sessionUser.slice(1, 2).toUpperCase()}</span>
05a48e9e7942atagen2026-10-24 09:32 UTC2402
        {/if}
05a48e9e7942atagen2026-10-24 09:32 UTC2403
        <span class="me-names">
445bf199a9cfatagen2026-10-25 02:56 UTC2404
          <span class="me-name"><EmojiText text={profile?.display_name || $sessionUser} /></span>
05a48e9e7942atagen2026-10-24 09:32 UTC2405
          {#if profile?.display_name && profile.display_name !== $sessionUser}<span class="me-id">{$sessionUser}</span>{/if}
05a48e9e7942atagen2026-10-24 09:32 UTC2406
        </span>
05a48e9e7942atagen2026-10-24 09:32 UTC2407
      </button>
05a48e9e7942atagen2026-10-24 09:32 UTC2408
      <div class="account-actions">
05a48e9e7942atagen2026-10-24 09:32 UTC2409
        <button type="button" class="icon-btn" title="Encryption and verification" aria-label="Encryption and verification" on:click={() => (dialog = 'security')}>
05a48e9e7942atagen2026-10-24 09:32 UTC2410
          <svg viewBox="0 0 24 24" width="17" height="17" aria-hidden="true"><path d="M12 3l8 3v6c0 4.5-3.4 8.2-8 9-4.6-.8-8-4.5-8-9V6z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" /></svg>
973f8fbdaf80atagen2026-09-28 09:10 UTC2411
        </button>
05a48e9e7942atagen2026-10-24 09:32 UTC2412
        <button type="button" class="icon-btn" title="Settings" aria-label="Settings" on:click={() => (dialog = 'settings')}>
05a48e9e7942atagen2026-10-24 09:32 UTC2413
          <svg viewBox="0 0 24 24" width="17" height="17" aria-hidden="true"><circle cx="12" cy="12" r="3" fill="none" stroke="currentColor" stroke-width="1.8" /><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M4.9 19.1L7 17M17 7l2.1-2.1" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" /></svg>
df3c0f2b3da4atagen2026-10-22 13:07 UTC2414
        </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2415
        <button type="button" class="icon-btn" title="Log out" aria-label="Log out" on:click={() => void doLogout()}>
05a48e9e7942atagen2026-10-24 09:32 UTC2416
          <svg viewBox="0 0 24 24" width="17" height="17" aria-hidden="true"><path d="M12 3v8M6.3 6.3a8 8 0 1 0 11.4 0" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" /></svg>
973f8fbdaf80atagen2026-09-28 09:10 UTC2417
        </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2418
      </div>
05a48e9e7942atagen2026-10-24 09:32 UTC2419
    </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2420
    {#if sidebarOpen}
973f8fbdaf80atagen2026-09-28 09:10 UTC2421
      <button type="button" class="scrim" aria-label="Close room list" on:click={() => (sidebarOpen = false)}></button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2422
    {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2423
973f8fbdaf80atagen2026-09-28 09:10 UTC2424
    <main class="chat">
973f8fbdaf80atagen2026-09-28 09:10 UTC2425
        {#if $banners.length > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2426
          <div class="banners" aria-live="polite">
973f8fbdaf80atagen2026-09-28 09:10 UTC2427
            {#each $banners as banner (banner.id)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2428
              <div class="banner" role="alert">
445bf199a9cfatagen2026-10-25 02:56 UTC2429
                <span><EmojiText text={banner.message} /></span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2430
                <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2431
                  type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2432
                  aria-label="Dismiss error"
973f8fbdaf80atagen2026-09-28 09:10 UTC2433
                  on:click={() => dismissBanner(banner.id)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2434
                >
973f8fbdaf80atagen2026-09-28 09:10 UTC2435
                  ✕
973f8fbdaf80atagen2026-09-28 09:10 UTC2436
                </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2437
              </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2438
            {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2439
          </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2440
        {/if}
668ab5c30531atagen2026-10-25 03:13 UTC2441
      {#key mentionsOpen ? 'mentions' : $selectedRoomId ?? 'home'}
824dfd38cdf3atagen2026-10-24 13:43 UTC2442
      <div class="chat-view">
668ab5c30531atagen2026-10-25 03:13 UTC2443
      {#if mentionsOpen && $sessionUser}
668ab5c30531atagen2026-10-25 03:13 UTC2444
        <MentionsInbox self={$sessionUser} onLive={(roomId) => void selectRoom(roomId)} />
668ab5c30531atagen2026-10-25 03:13 UTC2445
      {:else if !selectedRoom}
824dfd38cdf3atagen2026-10-24 13:43 UTC2446
        <div class="empty" in:fade={{ duration: motionDuration(180) }}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2447
          <div class="empty-mark" aria-hidden="true">◈</div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2448
          {#if selectedSpace}
445bf199a9cfatagen2026-10-25 02:56 UTC2449
            <h1><EmojiText text={selectedSpace.name} /></h1>
973f8fbdaf80atagen2026-09-28 09:10 UTC2450
          {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC2451
            <h1>Welcome to Malice</h1>
973f8fbdaf80atagen2026-09-28 09:10 UTC2452
          {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2453
          <div class="empty-cta">
973f8fbdaf80atagen2026-09-28 09:10 UTC2454
            <button type="button" class="primary-btn" on:click={() => (dialog = 'join')}>Join a room</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2455
            <button type="button" class="ghost-btn" on:click={() => (dialog = 'create')}>Create a room</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2456
          </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2457
          <p class="conn-line">
973f8fbdaf80atagen2026-09-28 09:10 UTC2458
            <span class="dot {connectionClass($connection)}" aria-hidden="true"></span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2459
            {$connection}
973f8fbdaf80atagen2026-09-28 09:10 UTC2460
          </p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2461
        </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2462
      {:else}
9f996e377406atagen2026-10-25 03:32 UTC2463
        {#if repairPanels[selectedRoom.room_id] ?? !!currentRepair}
9f996e377406atagen2026-10-25 03:32 UTC2464
          <HistoryRepairPanel
9f996e377406atagen2026-10-25 03:32 UTC2465
            report={currentRepair}
9f996e377406atagen2026-10-25 03:32 UTC2466
            busy={!!repairBusy[selectedRoom.room_id]}
9f996e377406atagen2026-10-25 03:32 UTC2467
            cancelling={!!repairCancelling[selectedRoom.room_id]}
9f996e377406atagen2026-10-25 03:32 UTC2468
            error={repairErrors[selectedRoom.room_id] ?? null}
9f996e377406atagen2026-10-25 03:32 UTC2469
            onStart={(policy) => void runHistoryRepair(selectedRoom.room_id, 'start', policy)}
9f996e377406atagen2026-10-25 03:32 UTC2470
            onCancel={() => void cancelRoomRepair(selectedRoom.room_id)}
9f996e377406atagen2026-10-25 03:32 UTC2471
            onContinue={() => void runHistoryRepair(selectedRoom.room_id, 'continue')}
9f996e377406atagen2026-10-25 03:32 UTC2472
            onRecent={() => void runHistoryRepair(selectedRoom.room_id, 'recent')}
9f996e377406atagen2026-10-25 03:32 UTC2473
            onClose={() => (repairPanels = { ...repairPanels, [selectedRoom.room_id]: false })}
9f996e377406atagen2026-10-25 03:32 UTC2474
          />
9f996e377406atagen2026-10-25 03:32 UTC2475
        {/if}
05a48e9e7942atagen2026-10-24 09:32 UTC2476
        {#if pins.length}
05a48e9e7942atagen2026-10-24 09:32 UTC2477
          <div class="pinned-strip" class:open={pinsExpanded}>
05a48e9e7942atagen2026-10-24 09:32 UTC2478
            <div class="pinned-head">
05a48e9e7942atagen2026-10-24 09:32 UTC2479
              <svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M9 3h6l-1 6 4 4v2h-5v6l-1 1-1-1v-6H6v-2l4-4z" fill="currentColor" /></svg>
05a48e9e7942atagen2026-10-24 09:32 UTC2480
              <button type="button" class="pinned-latest" title="Jump to pinned message" on:click={() => jumpToPin(pins[0].event_id ?? '')}>
445bf199a9cfatagen2026-10-25 02:56 UTC2481
                <strong><EmojiText text={people[pins[0].sender.user_id]?.name ?? senderLabel(pins[0].sender)} /></strong>
445bf199a9cfatagen2026-10-25 02:56 UTC2482
                <span><EmojiText text={contentPreview(pins[0].content)} /></span>
05a48e9e7942atagen2026-10-24 09:32 UTC2483
              </button>
05a48e9e7942atagen2026-10-24 09:32 UTC2484
              {#if pins.length > 1}
05a48e9e7942atagen2026-10-24 09:32 UTC2485
                <button type="button" class="pinned-count" aria-expanded={pinsExpanded} on:click={() => (pinsExpanded = !pinsExpanded)}>
05a48e9e7942atagen2026-10-24 09:32 UTC2486
                  {pins.length} pinned
05a48e9e7942atagen2026-10-24 09:32 UTC2487
                  <svg viewBox="0 0 24 24" width="12" height="12" aria-hidden="true"><path d="m6 9 6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" /></svg>
05a48e9e7942atagen2026-10-24 09:32 UTC2488
                </button>
05a48e9e7942atagen2026-10-24 09:32 UTC2489
              {/if}
05a48e9e7942atagen2026-10-24 09:32 UTC2490
              {#if pinsExpanded && selectedRoom.can_pin}
05a48e9e7942atagen2026-10-24 09:32 UTC2491
                <button type="button" class="icon-btn" aria-label="Unpin" title="Unpin" on:click={() => setPinned(pins[0].event_id ?? '', false)}>
05a48e9e7942atagen2026-10-24 09:32 UTC2492
                  <svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18" stroke="currentColor" stroke-width="2" /></svg>
05a48e9e7942atagen2026-10-24 09:32 UTC2493
                </button>
05a48e9e7942atagen2026-10-24 09:32 UTC2494
              {/if}
05a48e9e7942atagen2026-10-24 09:32 UTC2495
            </div>
05a48e9e7942atagen2026-10-24 09:32 UTC2496
            {#if pinsExpanded}
05a48e9e7942atagen2026-10-24 09:32 UTC2497
              <ul class="pinned-list">
05a48e9e7942atagen2026-10-24 09:32 UTC2498
                {#each pins.slice(1) as pin (pin.event_id)}
05a48e9e7942atagen2026-10-24 09:32 UTC2499
                  <li>
05a48e9e7942atagen2026-10-24 09:32 UTC2500
                    <button type="button" on:click={() => jumpToPin(pin.event_id ?? '')}>
445bf199a9cfatagen2026-10-25 02:56 UTC2501
                      <strong><EmojiText text={people[pin.sender.user_id]?.name ?? senderLabel(pin.sender)} /></strong>
445bf199a9cfatagen2026-10-25 02:56 UTC2502
                      <span><EmojiText text={contentPreview(pin.content)} /></span>
05a48e9e7942atagen2026-10-24 09:32 UTC2503
                    </button>
05a48e9e7942atagen2026-10-24 09:32 UTC2504
                    {#if selectedRoom.can_pin}
05a48e9e7942atagen2026-10-24 09:32 UTC2505
                      <button type="button" class="icon-btn" aria-label="Unpin" title="Unpin" on:click={() => setPinned(pin.event_id ?? '', false)}>
05a48e9e7942atagen2026-10-24 09:32 UTC2506
                        <svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18" stroke="currentColor" stroke-width="2" /></svg>
05a48e9e7942atagen2026-10-24 09:32 UTC2507
                      </button>
05a48e9e7942atagen2026-10-24 09:32 UTC2508
                    {/if}
05a48e9e7942atagen2026-10-24 09:32 UTC2509
                  </li>
05a48e9e7942atagen2026-10-24 09:32 UTC2510
                {/each}
05a48e9e7942atagen2026-10-24 09:32 UTC2511
              </ul>
05a48e9e7942atagen2026-10-24 09:32 UTC2512
            {/if}
05a48e9e7942atagen2026-10-24 09:32 UTC2513
          </div>
05a48e9e7942atagen2026-10-24 09:32 UTC2514
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2515
        {#if recoveryBanner}
973f8fbdaf80atagen2026-09-28 09:10 UTC2516
          <div class="sec-banner warn" role="status">
705b1e1062c2atagen2026-10-23 09:05 UTC2517
            <span>Message history is locked</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2518
            <button type="button" on:click={() => (dialog = 'security')}>Recover</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2519
          </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2520
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2521
        {#if verificationBanner}
973f8fbdaf80atagen2026-09-28 09:10 UTC2522
          <div class="sec-banner" role="status">
973f8fbdaf80atagen2026-09-28 09:10 UTC2523
            {#if verificationBanner.kind === 'Incoming'}
705b1e1062c2atagen2026-10-23 09:05 UTC2524
              <span>A device wants to verify this session</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2525
              <button type="button" on:click={() => (dialog = 'security')}>Review request</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2526
            {:else if verificationBanner.kind === 'Comparison'}
705b1e1062c2atagen2026-10-23 09:05 UTC2527
              <span>Verification codes ready</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2528
              <button type="button" on:click={() => (dialog = 'security')}>Compare codes</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2529
            {:else if verificationBanner.kind === 'Waiting'}
705b1e1062c2atagen2026-10-23 09:05 UTC2530
              <span>Verification started</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2531
              <button type="button" on:click={() => (dialog = 'security')}>Open verification</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2532
            {:else if verificationBanner.kind === 'Failed'}
445bf199a9cfatagen2026-10-25 02:56 UTC2533
              <span>Verification failed: <EmojiText text={verificationBanner.message} /></span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2534
              <button type="button" on:click={() => (dialog = 'security')}>Try again</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2535
            {:else if verificationBanner.kind === 'Cancelled'}
445bf199a9cfatagen2026-10-25 02:56 UTC2536
              <span>Verification cancelled: <EmojiText text={verificationBanner.reason} /></span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2537
              <button type="button" on:click={() => (dialog = 'security')}>Open security</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2538
            {:else}
705b1e1062c2atagen2026-10-23 09:05 UTC2539
              <span>Verification in progress</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2540
              <button type="button" on:click={() => (dialog = 'security')}>Open security</button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2541
            {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2542
          </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2543
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2544
        {#if $selectedRoomId && openFailed[$selectedRoomId]}
445bf199a9cfatagen2026-10-25 02:56 UTC2545
          <p class="conn-banner error" role="alert"><EmojiText text={openFailed[$selectedRoomId]} /></p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2546
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2547
7efc4c6d41abatagen2026-10-24 11:40 UTC2548
        {#if pinPreview}
7efc4c6d41abatagen2026-10-24 11:40 UTC2549
          <div class="pin-preview" role="dialog" aria-label="Pinned message preview">
7efc4c6d41abatagen2026-10-24 11:40 UTC2550
            <div class="pin-preview-head">
445bf199a9cfatagen2026-10-25 02:56 UTC2551
              <strong><EmojiText text={people[pinPreview.sender.user_id]?.name ?? senderLabel(pinPreview.sender)} /></strong>
7efc4c6d41abatagen2026-10-24 11:40 UTC2552
              <button type="button" class="icon-btn" aria-label="Close pinned message preview" on:click={() => (pinPreview = null)}>✕</button>
7efc4c6d41abatagen2026-10-24 11:40 UTC2553
            </div>
445bf199a9cfatagen2026-10-25 02:56 UTC2554
            <p><EmojiText text={contentPreview(pinPreview.content)} /></p>
7efc4c6d41abatagen2026-10-24 11:40 UTC2555
            <button type="button" class="primary-btn" disabled={pinJumpBusy} on:click={() => void jumpToPin(pinPreview?.event_id ?? '')}>
7efc4c6d41abatagen2026-10-24 11:40 UTC2556
              {pinJumpBusy ? 'Loading message…' : 'Jump to message'}
7efc4c6d41abatagen2026-10-24 11:40 UTC2557
            </button>
7efc4c6d41abatagen2026-10-24 11:40 UTC2558
          </div>
7efc4c6d41abatagen2026-10-24 11:40 UTC2559
        {/if}
7efc4c6d41abatagen2026-10-24 11:40 UTC2560
705b1e1062c2atagen2026-10-23 09:05 UTC2561
        <!-- svelte-ignore a11y_no_static_element_interactions -->
705b1e1062c2atagen2026-10-23 09:05 UTC2562
        <div
705b1e1062c2atagen2026-10-23 09:05 UTC2563
          class="timeline"
824dfd38cdf3atagen2026-10-24 13:43 UTC2564
          in:fly={{ y: 6, duration: motionDuration(180) }}
824dfd38cdf3atagen2026-10-24 13:43 UTC2565
          out:fade={{ duration: motionDuration(120) }}
705b1e1062c2atagen2026-10-23 09:05 UTC2566
          bind:this={timelineEl}
705b1e1062c2atagen2026-10-23 09:05 UTC2567
          on:scroll={onTimelineScroll}
705b1e1062c2atagen2026-10-23 09:05 UTC2568
          on:wheel={noteUserScroll}
705b1e1062c2atagen2026-10-23 09:05 UTC2569
          on:touchmove={noteUserScroll}
705b1e1062c2atagen2026-10-23 09:05 UTC2570
          on:keydown={onTimelineKey}
1b586ca05859atagen2026-10-25 02:37 UTC2571
          on:pointerdown={noteUserScroll}
705b1e1062c2atagen2026-10-23 09:05 UTC2572
          aria-label={`Messages in ${selectedRoom.name}`}
705b1e1062c2atagen2026-10-23 09:05 UTC2573
        >
705b1e1062c2atagen2026-10-23 09:05 UTC2574
          <div class="timeline-inner" use:pinTimeline>
705b1e1062c2atagen2026-10-23 09:05 UTC2575
            <div class="timeline-top">
705b1e1062c2atagen2026-10-23 09:05 UTC2576
              {#if hasStart}
705b1e1062c2atagen2026-10-23 09:05 UTC2577
                <p class="start-note">Beginning of history</p>
705b1e1062c2atagen2026-10-23 09:05 UTC2578
              {:else}
9f996e377406atagen2026-10-25 03:32 UTC2579
                <button type="button" class="ghost-btn" disabled={paginateBusy || currentRepairActive} on:click={() => void paginate()}>
705b1e1062c2atagen2026-10-23 09:05 UTC2580
                  {paginateBusy ? 'Loading…' : 'Load older messages'}
705b1e1062c2atagen2026-10-23 09:05 UTC2581
                </button>
705b1e1062c2atagen2026-10-23 09:05 UTC2582
              {/if}
705b1e1062c2atagen2026-10-23 09:05 UTC2583
            </div>
705b1e1062c2atagen2026-10-23 09:05 UTC2584
            {#if grouped.length === 0}
705b1e1062c2atagen2026-10-23 09:05 UTC2585
              <p class="side-note timeline-empty">No messages yet</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2586
            {:else}
705b1e1062c2atagen2026-10-23 09:05 UTC2587
              {#each grouped as g (g.key)}
705b1e1062c2atagen2026-10-23 09:05 UTC2588
                {#if g.item.kind === 'day'}
705b1e1062c2atagen2026-10-23 09:05 UTC2589
                  <div class="day-row"><span>{formatDay(g.item.timestamp_ms)}</span></div>
705b1e1062c2atagen2026-10-23 09:05 UTC2590
                {:else if g.item.kind === 'readMarker'}
705b1e1062c2atagen2026-10-23 09:05 UTC2591
                  <div class="new-row"><span>New</span></div>
705b1e1062c2atagen2026-10-23 09:05 UTC2592
                {:else if g.item.kind === 'start'}
705b1e1062c2atagen2026-10-23 09:05 UTC2593
                  <p class="start-note">Beginning of history</p>
705b1e1062c2atagen2026-10-23 09:05 UTC2594
                {:else if g.item.kind === 'unknown'}
705b1e1062c2atagen2026-10-23 09:05 UTC2595
                  <p class="unknown-note">Unsupported event ({g.item.label})</p>
705b1e1062c2atagen2026-10-23 09:05 UTC2596
                {:else}
705b1e1062c2atagen2026-10-23 09:05 UTC2597
                  <MessageRow
705b1e1062c2atagen2026-10-23 09:05 UTC2598
                    itemId={g.key}
705b1e1062c2atagen2026-10-23 09:05 UTC2599
                    event={g.item.event}
705b1e1062c2atagen2026-10-23 09:05 UTC2600
                    showSender={g.showSender}
787cdbbf0721atagen2026-10-24 06:50 UTC2601
                    senderAvatar={senderAvatarFor(g.item.event.sender.user_id) ?? g.item.event.sender.avatar}
705b1e1062c2atagen2026-10-23 09:05 UTC2602
                    {reacting}
705b1e1062c2atagen2026-10-23 09:05 UTC2603
                    onReact={(eventId, key, shortcode) => void react(eventId, key, shortcode)}
705b1e1062c2atagen2026-10-23 09:05 UTC2604
                    quickReactions={$quickReactions}
705b1e1062c2atagen2026-10-23 09:05 UTC2605
                    packs={roomPacks}
705b1e1062c2atagen2026-10-23 09:05 UTC2606
                    linkPreviews={$linkPreviews}
705b1e1062c2atagen2026-10-23 09:05 UTC2607
                    {loadPreview}
705b1e1062c2atagen2026-10-23 09:05 UTC2608
                    onQuickChange={(list) => void changeQuickReactions(list)}
705b1e1062c2atagen2026-10-23 09:05 UTC2609
                    {people}
705b1e1062c2atagen2026-10-23 09:05 UTC2610
                    self={$sessionUser ?? null}
d8624c214c04atagen2026-10-24 08:24 UTC2611
                    onUser={(userId, x, y, asMenu) => void openUser(userId, x, y, asMenu)}
d095131eec0eatagen2026-10-24 08:39 UTC2612
                    onCloneSticker={openCloneStickerMenu}
0380cd8c765catagen2026-10-24 09:08 UTC2613
                    onMore={(ev, x, y) => void openMessageMenu(ev, x, y)}
705b1e1062c2atagen2026-10-23 09:05 UTC2614
                    onReply={selectedRoom.membership === 'Joined' ? startReply : null}
705b1e1062c2atagen2026-10-23 09:05 UTC2615
                    onJump={jumpTo}
705b1e1062c2atagen2026-10-23 09:05 UTC2616
                    onEdit={selectedRoom.membership === 'Joined' ? startEdit : null}
705b1e1062c2atagen2026-10-23 09:05 UTC2617
                    editing={editing !== null && editing.eventId === g.item.event.event_id}
705b1e1062c2atagen2026-10-23 09:05 UTC2618
                    showSent={g.item.event.item_id === lastSentId && pendingItems.length === 0}
705b1e1062c2atagen2026-10-23 09:05 UTC2619
                  />
705b1e1062c2atagen2026-10-23 09:05 UTC2620
                {/if}
705b1e1062c2atagen2026-10-23 09:05 UTC2621
              {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2622
            {/if}
705b1e1062c2atagen2026-10-23 09:05 UTC2623
            {#each pendingItems as p, i (p.id)}
705b1e1062c2atagen2026-10-23 09:05 UTC2624
              <MessageRow
705b1e1062c2atagen2026-10-23 09:05 UTC2625
                itemId={`pending-${p.id}`}
705b1e1062c2atagen2026-10-23 09:05 UTC2626
                event={pendingToEvent(p)}
705b1e1062c2atagen2026-10-23 09:05 UTC2627
                onJump={jumpTo}
705b1e1062c2atagen2026-10-23 09:05 UTC2628
                showSender={pendingShowSender(i)}
705b1e1062c2atagen2026-10-23 09:05 UTC2629
                senderAvatar={senderAvatarFor($sessionUser ?? '')}
705b1e1062c2atagen2026-10-23 09:05 UTC2630
                {reacting}
705b1e1062c2atagen2026-10-23 09:05 UTC2631
                onReact={(eventId, key, shortcode) => void react(eventId, key, shortcode)}
705b1e1062c2atagen2026-10-23 09:05 UTC2632
                quickReactions={$quickReactions}
705b1e1062c2atagen2026-10-23 09:05 UTC2633
                packs={roomPacks}
705b1e1062c2atagen2026-10-23 09:05 UTC2634
                linkPreviews={$linkPreviews}
705b1e1062c2atagen2026-10-23 09:05 UTC2635
                {loadPreview}
705b1e1062c2atagen2026-10-23 09:05 UTC2636
                onQuickChange={(list) => void changeQuickReactions(list)}
705b1e1062c2atagen2026-10-23 09:05 UTC2637
              />
705b1e1062c2atagen2026-10-23 09:05 UTC2638
              {#if p.status === 'failed'}
705b1e1062c2atagen2026-10-23 09:05 UTC2639
                <div class="pending-actions">
445bf199a9cfatagen2026-10-25 02:56 UTC2640
                  <span class="pending-error" role="alert"><EmojiText text={p.error ?? ''} /></span>
705b1e1062c2atagen2026-10-23 09:05 UTC2641
                  <button type="button" class="ghost-btn" on:click={() => retryPending(p.id)}>Retry</button>
705b1e1062c2atagen2026-10-23 09:05 UTC2642
                  <button type="button" class="ghost-btn danger" on:click={() => discardPending(p.id)}>Discard</button>
705b1e1062c2atagen2026-10-23 09:05 UTC2643
                </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2644
              {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2645
            {/each}
705b1e1062c2atagen2026-10-23 09:05 UTC2646
          </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2647
        </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2648
973f8fbdaf80atagen2026-09-28 09:10 UTC2649
        {#if selectedRoom.membership === 'Joined'}
cf23dbf4e77catagen2026-10-23 06:36 UTC2650
          {#if editing}
cf23dbf4e77catagen2026-10-23 06:36 UTC2651
            <div class="reply-bar" role="status">
cf23dbf4e77catagen2026-10-23 06:36 UTC2652
              <span class="reply-bar-label">
cf23dbf4e77catagen2026-10-23 06:36 UTC2653
                Editing message
445bf199a9cfatagen2026-10-25 02:56 UTC2654
                <span class="reply-bar-text"><EmojiText text={editing.original} /></span>
cf23dbf4e77catagen2026-10-23 06:36 UTC2655
              </span>
cf23dbf4e77catagen2026-10-23 06:36 UTC2656
              <button type="button" class="icon-btn" aria-label="Cancel edit" title="Cancel edit (Esc)" on:click={cancelEdit}>
cf23dbf4e77catagen2026-10-23 06:36 UTC2657
                <span aria-hidden="true">✕</span>
cf23dbf4e77catagen2026-10-23 06:36 UTC2658
              </button>
cf23dbf4e77catagen2026-10-23 06:36 UTC2659
            </div>
cf23dbf4e77catagen2026-10-23 06:36 UTC2660
          {:else if replyingTo && replyingTo.details.kind === 'Ready'}
df3c0f2b3da4atagen2026-10-22 13:07 UTC2661
            <div class="reply-bar" role="status">
df3c0f2b3da4atagen2026-10-22 13:07 UTC2662
              <span class="reply-bar-label">
445bf199a9cfatagen2026-10-25 02:56 UTC2663
                Replying to <strong><EmojiText text={people[replyingTo.details.sender.user_id]?.name ?? senderLabel(replyingTo.details.sender)} /></strong>
445bf199a9cfatagen2026-10-25 02:56 UTC2664
                <span class="reply-bar-text"><EmojiText text={contentPreview(replyingTo.details.content)} /></span>
df3c0f2b3da4atagen2026-10-22 13:07 UTC2665
              </span>
df3c0f2b3da4atagen2026-10-22 13:07 UTC2666
              <button type="button" class="icon-btn" aria-label="Cancel reply" title="Cancel reply (Esc)" on:click={() => (replyingTo = null)}>
df3c0f2b3da4atagen2026-10-22 13:07 UTC2667
                <span aria-hidden="true">✕</span>
df3c0f2b3da4atagen2026-10-22 13:07 UTC2668
              </button>
df3c0f2b3da4atagen2026-10-22 13:07 UTC2669
            </div>
df3c0f2b3da4atagen2026-10-22 13:07 UTC2670
          {/if}
cf23dbf4e77catagen2026-10-23 06:36 UTC2671
          {#if $selectedRoomId && currentStaged.length > 0}
cf23dbf4e77catagen2026-10-23 06:36 UTC2672
            {@const stagedRoom = $selectedRoomId}
cf23dbf4e77catagen2026-10-23 06:36 UTC2673
            <ul class="staged" aria-label="Attachments to send">
cf23dbf4e77catagen2026-10-23 06:36 UTC2674
              {#each currentStaged as attachment (attachment.id)}
cf23dbf4e77catagen2026-10-23 06:36 UTC2675
                <li class="staged-item">
cf23dbf4e77catagen2026-10-23 06:36 UTC2676
                  {#if attachment.previewUrl}
cf23dbf4e77catagen2026-10-23 06:36 UTC2677
                    <img src={attachment.previewUrl} alt={attachment.file.name || 'Pasted image'} />
cf23dbf4e77catagen2026-10-23 06:36 UTC2678
                  {:else}
445bf199a9cfatagen2026-10-25 02:56 UTC2679
                    <span class="staged-name"><EmojiText text={attachment.file.name || 'attachment'} /></span>
cf23dbf4e77catagen2026-10-23 06:36 UTC2680
                  {/if}
cf23dbf4e77catagen2026-10-23 06:36 UTC2681
                  <button
cf23dbf4e77catagen2026-10-23 06:36 UTC2682
                    type="button"
cf23dbf4e77catagen2026-10-23 06:36 UTC2683
                    class="icon-btn staged-remove"
cf23dbf4e77catagen2026-10-23 06:36 UTC2684
                    aria-label={`Remove ${attachment.file.name || 'attachment'}`}
cf23dbf4e77catagen2026-10-23 06:36 UTC2685
                    title="Remove"
cf23dbf4e77catagen2026-10-23 06:36 UTC2686
                    on:click={() => unstage(stagedRoom, attachment.id)}
cf23dbf4e77catagen2026-10-23 06:36 UTC2687
                  >
cf23dbf4e77catagen2026-10-23 06:36 UTC2688
                    <span aria-hidden="true">✕</span>
cf23dbf4e77catagen2026-10-23 06:36 UTC2689
                  </button>
cf23dbf4e77catagen2026-10-23 06:36 UTC2690
                </li>
cf23dbf4e77catagen2026-10-23 06:36 UTC2691
              {/each}
cf23dbf4e77catagen2026-10-23 06:36 UTC2692
            </ul>
cf23dbf4e77catagen2026-10-23 06:36 UTC2693
          {/if}
cf23dbf4e77catagen2026-10-23 06:36 UTC2694
          <form class="composer" class:replying={replyingTo || editing} class:staging={currentStaged.length > 0} on:submit|preventDefault={() => send()}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2695
            <label class="visually-hidden" for="composer">Message {selectedRoom.name}</label>
973f8fbdaf80atagen2026-09-28 09:10 UTC2696
            <input
973f8fbdaf80atagen2026-09-28 09:10 UTC2697
              type="file"
cf23dbf4e77catagen2026-10-23 06:36 UTC2698
              multiple
973f8fbdaf80atagen2026-09-28 09:10 UTC2699
              bind:this={fileInput}
973f8fbdaf80atagen2026-09-28 09:10 UTC2700
              class="visually-hidden"
973f8fbdaf80atagen2026-09-28 09:10 UTC2701
              aria-label="Attach a file"
973f8fbdaf80atagen2026-09-28 09:10 UTC2702
              on:change={() => void onFileChosen()}
973f8fbdaf80atagen2026-09-28 09:10 UTC2703
            />
e4c64c36f105atagen2026-10-24 07:09 UTC2704
            <input
e4c64c36f105atagen2026-10-24 07:09 UTC2705
              type="file"
e4c64c36f105atagen2026-10-24 07:09 UTC2706
              accept="image/*"
e4c64c36f105atagen2026-10-24 07:09 UTC2707
              bind:this={avatarInput}
e4c64c36f105atagen2026-10-24 07:09 UTC2708
              class="visually-hidden"
e4c64c36f105atagen2026-10-24 07:09 UTC2709
              aria-label="Choose a new avatar"
e4c64c36f105atagen2026-10-24 07:09 UTC2710
              on:change={() => void onAvatarChosen()}
e4c64c36f105atagen2026-10-24 07:09 UTC2711
            />
973f8fbdaf80atagen2026-09-28 09:10 UTC2712
            <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2713
              type="button"
05a48e9e7942atagen2026-10-24 09:32 UTC2714
              class="icon-btn"
05a48e9e7942atagen2026-10-24 09:32 UTC2715
              class:busy={uploadBusy}
05a48e9e7942atagen2026-10-24 09:32 UTC2716
              title={uploadBusy ? `Uploading ${uploadName ?? 'file'}…` : 'Attach an image or file'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2717
              aria-label="Attach an image or file"
05a48e9e7942atagen2026-10-24 09:32 UTC2718
              aria-busy={uploadBusy}
cf23dbf4e77catagen2026-10-23 06:36 UTC2719
              disabled={!($selectedRoomId && openReady[$selectedRoomId])}
cf23dbf4e77catagen2026-10-23 06:36 UTC2720
              on:click={pickFiles}
973f8fbdaf80atagen2026-09-28 09:10 UTC2721
            >
05a48e9e7942atagen2026-10-24 09:32 UTC2722
              <svg viewBox="0 0 24 24" width="19" height="19" aria-hidden="true">
05a48e9e7942atagen2026-10-24 09:32 UTC2723
                <path d="M20 11.5l-8.2 8.2a5 5 0 0 1-7-7L13 4.4a3.3 3.3 0 0 1 4.7 4.7l-8.2 8.2a1.7 1.7 0 0 1-2.4-2.4l7.5-7.5" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" />
05a48e9e7942atagen2026-10-24 09:32 UTC2724
              </svg>
973f8fbdaf80atagen2026-09-28 09:10 UTC2725
            </button>
d095131eec0eatagen2026-10-24 08:39 UTC2726
            <button
d095131eec0eatagen2026-10-24 08:39 UTC2727
              type="button"
d095131eec0eatagen2026-10-24 08:39 UTC2728
              class="icon-btn sticker-btn"
d095131eec0eatagen2026-10-24 08:39 UTC2729
              title="Stickers"
d095131eec0eatagen2026-10-24 08:39 UTC2730
              aria-label="Stickers"
d095131eec0eatagen2026-10-24 08:39 UTC2731
              aria-expanded={stickersOpen}
d095131eec0eatagen2026-10-24 08:39 UTC2732
              disabled={!($selectedRoomId && openReady[$selectedRoomId])}
d095131eec0eatagen2026-10-24 08:39 UTC2733
              on:click={() => (stickersOpen = !stickersOpen)}
d095131eec0eatagen2026-10-24 08:39 UTC2734
            >
05a48e9e7942atagen2026-10-24 09:32 UTC2735
              <svg viewBox="0 0 24 24" width="19" height="19" aria-hidden="true">
d095131eec0eatagen2026-10-24 08:39 UTC2736
                <path d="M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v7l-7 7H6a2 2 0 0 1-2-2z" fill="none" stroke="currentColor" stroke-width="1.8" />
d095131eec0eatagen2026-10-24 08:39 UTC2737
                <path d="M13 20v-5a2 2 0 0 1 2-2h5" fill="none" stroke="currentColor" stroke-width="1.8" />
d095131eec0eatagen2026-10-24 08:39 UTC2738
              </svg>
d095131eec0eatagen2026-10-24 08:39 UTC2739
            </button>
d095131eec0eatagen2026-10-24 08:39 UTC2740
            {#if stickersOpen && $selectedRoomId}
d095131eec0eatagen2026-10-24 08:39 UTC2741
              {@const stickerRoom = $selectedRoomId}
d095131eec0eatagen2026-10-24 08:39 UTC2742
              <div class="sticker-pop">
d095131eec0eatagen2026-10-24 08:39 UTC2743
                <StickerPicker
d095131eec0eatagen2026-10-24 08:39 UTC2744
                  packs={roomPacks}
d095131eec0eatagen2026-10-24 08:39 UTC2745
                  {roomName}
d095131eec0eatagen2026-10-24 08:39 UTC2746
                  onSend={(pack, image) => void sendSticker(stickerRoom, pack, image)}
d095131eec0eatagen2026-10-24 08:39 UTC2747
                  onClone={(pack, image, x, y) => openCloneImageMenu(pack, image, x, y)}
d095131eec0eatagen2026-10-24 08:39 UTC2748
                  onClonePack={(pack, x, y) => openClonePackMenu(pack, x, y)}
d095131eec0eatagen2026-10-24 08:39 UTC2749
                  onManage={() => ((stickersOpen = false), (dialog = 'packs'))}
d095131eec0eatagen2026-10-24 08:39 UTC2750
                  onClose={() => (stickersOpen = false)}
d095131eec0eatagen2026-10-24 08:39 UTC2751
                />
d095131eec0eatagen2026-10-24 08:39 UTC2752
              </div>
d095131eec0eatagen2026-10-24 08:39 UTC2753
            {/if}
2021154f9e16atagen2026-10-25 02:37 UTC2754
            <div class="composer-field" class:composing={composerComposing}>
f604ef6df0c4atagen2026-10-24 10:08 UTC2755
              {#if commandQuery !== null && commandCandidates.length > 0}
f604ef6df0c4atagen2026-10-24 10:08 UTC2756
                <ul class="mention-finder" role="listbox" aria-label="Commands">
f604ef6df0c4atagen2026-10-24 10:08 UTC2757
                  {#each commandCandidates as name, i (name)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2758
                    <li
f604ef6df0c4atagen2026-10-24 10:08 UTC2759
                      role="option"
f604ef6df0c4atagen2026-10-24 10:08 UTC2760
                      aria-selected={i === commandIndex}
f604ef6df0c4atagen2026-10-24 10:08 UTC2761
                      class:active={i === commandIndex}
f604ef6df0c4atagen2026-10-24 10:08 UTC2762
                      on:pointerdown|preventDefault={() => void pickCommand(name)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2763
                      on:pointerenter={() => (commandIndex = i)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2764
                    >
f604ef6df0c4atagen2026-10-24 10:08 UTC2765
                      <span class="mention-name">/{name}</span>
f604ef6df0c4atagen2026-10-24 10:08 UTC2766
                      <span class="mention-id">{COMMAND_USAGE[name]}</span>
f604ef6df0c4atagen2026-10-24 10:08 UTC2767
                    </li>
f604ef6df0c4atagen2026-10-24 10:08 UTC2768
                  {/each}
f604ef6df0c4atagen2026-10-24 10:08 UTC2769
                </ul>
f604ef6df0c4atagen2026-10-24 10:08 UTC2770
              {/if}
f604ef6df0c4atagen2026-10-24 10:08 UTC2771
              {#if emoteQuery && emoteCandidates.length > 0}
f604ef6df0c4atagen2026-10-24 10:08 UTC2772
                <ul class="mention-finder" role="listbox" aria-label="Emotes">
f604ef6df0c4atagen2026-10-24 10:08 UTC2773
                  {#each emoteCandidates as candidate, i (candidate.kind + candidate.shortcode)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2774
                    <li
f604ef6df0c4atagen2026-10-24 10:08 UTC2775
                      role="option"
f604ef6df0c4atagen2026-10-24 10:08 UTC2776
                      aria-selected={i === emoteIndex}
f604ef6df0c4atagen2026-10-24 10:08 UTC2777
                      class:active={i === emoteIndex}
f604ef6df0c4atagen2026-10-24 10:08 UTC2778
                      on:pointerdown|preventDefault={() => void pickEmote(candidate)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2779
                      on:pointerenter={() => (emoteIndex = i)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2780
                    >
f604ef6df0c4atagen2026-10-24 10:08 UTC2781
                      {#if candidate.kind === 'custom'}
f604ef6df0c4atagen2026-10-24 10:08 UTC2782
                        <img class="finder-emote" src={mediaUrl(candidate.mxc) ?? ''} alt="" />
f604ef6df0c4atagen2026-10-24 10:08 UTC2783
                      {:else}
f604ef6df0c4atagen2026-10-24 10:08 UTC2784
                        <span class="finder-emote"><EmojiText text={candidate.emoji} /></span>
f604ef6df0c4atagen2026-10-24 10:08 UTC2785
                      {/if}
f604ef6df0c4atagen2026-10-24 10:08 UTC2786
                      <span class="mention-name">:{candidate.shortcode}:</span>
f604ef6df0c4atagen2026-10-24 10:08 UTC2787
                    </li>
f604ef6df0c4atagen2026-10-24 10:08 UTC2788
                  {/each}
f604ef6df0c4atagen2026-10-24 10:08 UTC2789
                </ul>
f604ef6df0c4atagen2026-10-24 10:08 UTC2790
              {/if}
f604ef6df0c4atagen2026-10-24 10:08 UTC2791
              {#if mentionQuery && mentionCandidates.length > 0}
f604ef6df0c4atagen2026-10-24 10:08 UTC2792
                <ul class="mention-finder" role="listbox" aria-label="Mention someone">
f604ef6df0c4atagen2026-10-24 10:08 UTC2793
                  {#each mentionCandidates as person, i (person.user_id)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2794
                    <li
f604ef6df0c4atagen2026-10-24 10:08 UTC2795
                      role="option"
f604ef6df0c4atagen2026-10-24 10:08 UTC2796
                      aria-selected={i === mentionIndex}
f604ef6df0c4atagen2026-10-24 10:08 UTC2797
                      class:active={i === mentionIndex}
f604ef6df0c4atagen2026-10-24 10:08 UTC2798
                      on:pointerdown|preventDefault={() => void pickMention(person)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2799
                      on:pointerenter={() => (mentionIndex = i)}
f604ef6df0c4atagen2026-10-24 10:08 UTC2800
                    >
f604ef6df0c4atagen2026-10-24 10:08 UTC2801
                      <MxcAvatar mxc={person.avatar} label={person.name} size={22} />
445bf199a9cfatagen2026-10-25 02:56 UTC2802
                      <span class="mention-name"><EmojiText text={person.name} /></span>
f604ef6df0c4atagen2026-10-24 10:08 UTC2803
                      <span class="mention-id">{person.user_id}</span>
f604ef6df0c4atagen2026-10-24 10:08 UTC2804
                    </li>
f604ef6df0c4atagen2026-10-24 10:08 UTC2805
                  {/each}
f604ef6df0c4atagen2026-10-24 10:08 UTC2806
                </ul>
f604ef6df0c4atagen2026-10-24 10:08 UTC2807
              {/if}
2021154f9e16atagen2026-10-25 02:37 UTC2808
            <div class="composer-marks" aria-hidden="true" bind:this={marksEl}>{#each composerMarks as part}{#if part.mark}<mark><ComposerText text={part.text} /></mark>{:else}<ComposerText text={part.text} />{/if}{/each}&#8203;</div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2809
            <textarea
973f8fbdaf80atagen2026-09-28 09:10 UTC2810
              id="composer"
973f8fbdaf80atagen2026-09-28 09:10 UTC2811
              bind:this={composerEl}
973f8fbdaf80atagen2026-09-28 09:10 UTC2812
              bind:value={composer}
2021154f9e16atagen2026-10-25 02:37 UTC2813
              use:syncComposer
973f8fbdaf80atagen2026-09-28 09:10 UTC2814
              rows="1"
973f8fbdaf80atagen2026-09-28 09:10 UTC2815
              placeholder={`Message ${selectedRoom.name}`}
973f8fbdaf80atagen2026-09-28 09:10 UTC2816
              aria-label={`Message ${selectedRoom.name}. Enter to send, Shift Enter for a new line.`}
973f8fbdaf80atagen2026-09-28 09:10 UTC2817
              on:keydown={onComposerKey}
05a48e9e7942atagen2026-10-24 09:32 UTC2818
              on:input={() => void onComposerInput()}
2021154f9e16atagen2026-10-25 02:37 UTC2819
              on:compositionstart={() => (composerComposing = true)}
2021154f9e16atagen2026-10-25 02:37 UTC2820
              on:compositionend={() => (composerComposing = false)}
cf23dbf4e77catagen2026-10-23 06:36 UTC2821
              on:click={updateMentionQuery}
05a48e9e7942atagen2026-10-24 09:32 UTC2822
              on:focus={ensureEmoji}
cf23dbf4e77catagen2026-10-23 06:36 UTC2823
              on:keyup={(e) => (e.key.startsWith('Arrow') && e.key !== 'ArrowUp' && e.key !== 'ArrowDown') || e.key === 'Home' || e.key === 'End' ? updateMentionQuery() : undefined}
2021154f9e16atagen2026-10-25 02:37 UTC2824
              on:blur={() => ((mentionQuery = null), (commandQuery = null), (emoteQuery = null), (composerComposing = false))}
df3c0f2b3da4atagen2026-10-22 13:07 UTC2825
              on:paste={onComposerPaste}
973f8fbdaf80atagen2026-09-28 09:10 UTC2826
              disabled={!($selectedRoomId && openReady[$selectedRoomId])}
973f8fbdaf80atagen2026-09-28 09:10 UTC2827
            ></textarea>
05a48e9e7942atagen2026-10-24 09:32 UTC2828
            </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2829
            <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2830
              type="submit"
973f8fbdaf80atagen2026-09-28 09:10 UTC2831
              class="primary-btn"
cf23dbf4e77catagen2026-10-23 06:36 UTC2832
              disabled={(!composer.trim() && currentStaged.length === 0) ||
cf23dbf4e77catagen2026-10-23 06:36 UTC2833
                !($selectedRoomId && openReady[$selectedRoomId]) ||
cf23dbf4e77catagen2026-10-23 06:36 UTC2834
                (currentStaged.length > 0 && uploadBusy)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2835
              title={!($selectedRoomId && openReady[$selectedRoomId]) ? 'Waiting for the room to open' : 'Send message'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2836
            >
973f8fbdaf80atagen2026-09-28 09:10 UTC2837
              Send
973f8fbdaf80atagen2026-09-28 09:10 UTC2838
            </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2839
          </form>
973f8fbdaf80atagen2026-09-28 09:10 UTC2840
        {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC2841
          <div class="join-bar">
973f8fbdaf80atagen2026-09-28 09:10 UTC2842
            <p>You are not a member of this room.</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2843
            <button type="button" class="primary-btn" disabled={joinBusy} on:click={() => void join(selectedRoom.room_id)}>
445bf199a9cfatagen2026-10-25 02:56 UTC2844
              <EmojiText text={joinBusy ? 'Joining…' : `Join ${selectedRoom.name}`} />
973f8fbdaf80atagen2026-09-28 09:10 UTC2845
            </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2846
          </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2847
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2848
      {/if}
d4c0d65f690aatagen2026-10-24 12:50 UTC2849
      </div>
d4c0d65f690aatagen2026-10-24 12:50 UTC2850
      {/key}
973f8fbdaf80atagen2026-09-28 09:10 UTC2851
    </main>
973f8fbdaf80atagen2026-09-28 09:10 UTC2852
e15025643a20atagen2026-10-24 06:51 UTC2853
    {#if selectedRoom}
e15025643a20atagen2026-10-24 06:51 UTC2854
      <aside class="members" aria-hidden={!membersOpen} aria-label={`Members of ${selectedRoom.name}`}>
05a48e9e7942atagen2026-10-24 09:32 UTC2855
        <!-- svelte-ignore a11y_no_static_element_interactions -->
05a48e9e7942atagen2026-10-24 09:32 UTC2856
        <div class="pane-resize left" title="Drag to resize" on:pointerdown={(e) => startResize(e, 'members')} on:dblclick={() => resetWidth('members')}></div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2857
        <div class="members-head">
973f8fbdaf80atagen2026-09-28 09:10 UTC2858
          <h2>Members</h2>
973f8fbdaf80atagen2026-09-28 09:10 UTC2859
          <button type="button" class="icon-btn" aria-label="Close members" on:click={() => (membersOpen = false)}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2860
            <span aria-hidden="true">✕</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2861
          </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2862
        </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2863
        {#if $membersLoading && members.length === 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2864
          <p class="side-note">Loading members…</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2865
        {:else if members.length === 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC2866
          <p class="side-note">No members loaded.</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC2867
          {#if $selectedRoomId}
973f8fbdaf80atagen2026-09-28 09:10 UTC2868
            <button type="button" class="ghost-btn" on:click={() => $selectedRoomId && void loadMembers($selectedRoomId)}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2869
              Retry
973f8fbdaf80atagen2026-09-28 09:10 UTC2870
            </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2871
          {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2872
        {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC2873
          <ul class="member-list">
dfd1feaae855atagen2026-10-24 10:54 UTC2874
            {#each memberGroups as group (group.label)}
dfd1feaae855atagen2026-10-24 10:54 UTC2875
              <li class="member-group">
dfd1feaae855atagen2026-10-24 10:54 UTC2876
                <h3 class="member-group-label">{group.label}<span>{group.members.length}</span></h3>
dfd1feaae855atagen2026-10-24 10:54 UTC2877
                <ul class="member-group-list">
dfd1feaae855atagen2026-10-24 10:54 UTC2878
                  {#each group.members as member (member.user_id)}
dfd1feaae855atagen2026-10-24 10:54 UTC2879
                    <li>
dfd1feaae855atagen2026-10-24 10:54 UTC2880
                      <button
dfd1feaae855atagen2026-10-24 10:54 UTC2881
                        type="button"
dfd1feaae855atagen2026-10-24 10:54 UTC2882
                        class="member"
dfd1feaae855atagen2026-10-24 10:54 UTC2883
                        on:click={(ev) => {
dfd1feaae855atagen2026-10-24 10:54 UTC2884
                          const rect = ev.currentTarget.getBoundingClientRect();
dfd1feaae855atagen2026-10-24 10:54 UTC2885
                          void openUser(member.user_id, rect.left - 308, rect.top, false);
dfd1feaae855atagen2026-10-24 10:54 UTC2886
                        }}
dfd1feaae855atagen2026-10-24 10:54 UTC2887
                        on:contextmenu|preventDefault={(ev) => void openUser(member.user_id, ev.clientX, ev.clientY, true)}
dfd1feaae855atagen2026-10-24 10:54 UTC2888
                      >
dfd1feaae855atagen2026-10-24 10:54 UTC2889
                        <MxcAvatar mxc={member.avatar} label={member.display_name || member.name || member.user_id} seed={member.user_id} size={28} />
dfd1feaae855atagen2026-10-24 10:54 UTC2890
                        <span class="member-names">
445bf199a9cfatagen2026-10-25 02:56 UTC2891
                          <span class="member-name"><EmojiText text={member.display_name || member.name} /></span>
dfd1feaae855atagen2026-10-24 10:54 UTC2892
                          <span class="member-id">{member.user_id}</span>
dfd1feaae855atagen2026-10-24 10:54 UTC2893
                        </span>
dfd1feaae855atagen2026-10-24 10:54 UTC2894
                      </button>
dfd1feaae855atagen2026-10-24 10:54 UTC2895
                    </li>
dfd1feaae855atagen2026-10-24 10:54 UTC2896
                  {/each}
dfd1feaae855atagen2026-10-24 10:54 UTC2897
                </ul>
973f8fbdaf80atagen2026-09-28 09:10 UTC2898
              </li>
973f8fbdaf80atagen2026-09-28 09:10 UTC2899
            {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC2900
          </ul>
973f8fbdaf80atagen2026-09-28 09:10 UTC2901
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2902
      </aside>
973f8fbdaf80atagen2026-09-28 09:10 UTC2903
    {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2904
973f8fbdaf80atagen2026-09-28 09:10 UTC2905
    {#if dialog}
973f8fbdaf80atagen2026-09-28 09:10 UTC2906
      <div class="modal-wrap" role="presentation" on:click|self={() => (dialog = null)}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2907
        {#if dialog === 'security'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2908
          <SecurityPanel
973f8fbdaf80atagen2026-09-28 09:10 UTC2909
            encryptionState={$encryption}
973f8fbdaf80atagen2026-09-28 09:10 UTC2910
            verificationState={$verification}
973f8fbdaf80atagen2026-09-28 09:10 UTC2911
            onAction={() => void loadEncryption()}
ecb8598b38afatagen2026-10-22 09:19 UTC2912
            encryptedPreviews={$urlPreviewSettings.encrypted_rooms}
ecb8598b38afatagen2026-10-22 09:19 UTC2913
            onEncryptedPreviews={(enabled) => void changeEncryptedPreviews(enabled)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2914
            on:close={() => (dialog = null)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2915
          />
df3c0f2b3da4atagen2026-10-22 13:07 UTC2916
        {:else if dialog === 'settings'}
df3c0f2b3da4atagen2026-10-22 13:07 UTC2917
          <SettingsPanel
df3c0f2b3da4atagen2026-10-22 13:07 UTC2918
            quick={$quickReactions}
df3c0f2b3da4atagen2026-10-22 13:07 UTC2919
            packs={roomPacks}
df3c0f2b3da4atagen2026-10-22 13:07 UTC2920
            onQuickChange={(list) => void changeQuickReactions(list)}
df3c0f2b3da4atagen2026-10-22 13:07 UTC2921
            on:close={() => (dialog = null)}
d095131eec0eatagen2026-10-24 08:39 UTC2922
            on:packs={() => (dialog = 'packs')}
df3c0f2b3da4atagen2026-10-22 13:07 UTC2923
          />
d095131eec0eatagen2026-10-24 08:39 UTC2924
        {:else if dialog === 'packs'}
d095131eec0eatagen2026-10-24 08:39 UTC2925
          <PackManager packs={$imagePacks} rooms={$rooms} onError={pushBanner} on:close={() => (dialog = null)} />
973f8fbdaf80atagen2026-09-28 09:10 UTC2926
        {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC2927
          <div class="modal" role="dialog" aria-modal="true" aria-label={dialog === 'join' ? 'Join a room' : 'Create a room'}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2928
            <div class="modal-tabs" role="tablist" aria-label="Room actions">
973f8fbdaf80atagen2026-09-28 09:10 UTC2929
              <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2930
                type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2931
                role="tab"
973f8fbdaf80atagen2026-09-28 09:10 UTC2932
                aria-selected={dialog === 'join'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2933
                class:active={dialog === 'join'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2934
                on:click={() => (dialog = 'join')}
973f8fbdaf80atagen2026-09-28 09:10 UTC2935
              >
973f8fbdaf80atagen2026-09-28 09:10 UTC2936
                Join
973f8fbdaf80atagen2026-09-28 09:10 UTC2937
              </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2938
              <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2939
                type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2940
                role="tab"
973f8fbdaf80atagen2026-09-28 09:10 UTC2941
                aria-selected={dialog === 'create'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2942
                class:active={dialog === 'create'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2943
                on:click={() => (dialog = 'create')}
973f8fbdaf80atagen2026-09-28 09:10 UTC2944
              >
973f8fbdaf80atagen2026-09-28 09:10 UTC2945
                Create
973f8fbdaf80atagen2026-09-28 09:10 UTC2946
              </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2947
              <button
973f8fbdaf80atagen2026-09-28 09:10 UTC2948
                type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC2949
                class="icon-btn modal-x"
973f8fbdaf80atagen2026-09-28 09:10 UTC2950
                aria-label="Close dialog"
973f8fbdaf80atagen2026-09-28 09:10 UTC2951
                on:click={() => (dialog = null)}
973f8fbdaf80atagen2026-09-28 09:10 UTC2952
              >
973f8fbdaf80atagen2026-09-28 09:10 UTC2953
                <span aria-hidden="true">✕</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2954
              </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2955
            </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2956
            {#if dialog === 'join'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2957
              <form on:submit|preventDefault={() => void join(joinTarget)}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2958
                <label class="field">
973f8fbdaf80atagen2026-09-28 09:10 UTC2959
                  <span>Room ID or alias</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2960
                  <input
973f8fbdaf80atagen2026-09-28 09:10 UTC2961
                    type="text"
973f8fbdaf80atagen2026-09-28 09:10 UTC2962
                    placeholder="!room:example.org or #alias:example.org"
973f8fbdaf80atagen2026-09-28 09:10 UTC2963
                    bind:value={joinTarget}
973f8fbdaf80atagen2026-09-28 09:10 UTC2964
                    required
973f8fbdaf80atagen2026-09-28 09:10 UTC2965
                    disabled={joinBusy}
973f8fbdaf80atagen2026-09-28 09:10 UTC2966
                  />
973f8fbdaf80atagen2026-09-28 09:10 UTC2967
                </label>
973f8fbdaf80atagen2026-09-28 09:10 UTC2968
                <button type="submit" class="primary-btn wide" disabled={joinBusy || !joinTarget.trim()}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2969
                  {joinBusy ? 'Joining…' : 'Join room'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2970
                </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2971
              </form>
973f8fbdaf80atagen2026-09-28 09:10 UTC2972
            {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC2973
            <form on:submit|preventDefault={() => void create()}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2974
              <label class="field">
973f8fbdaf80atagen2026-09-28 09:10 UTC2975
                <span>Room name</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2976
                <input
973f8fbdaf80atagen2026-09-28 09:10 UTC2977
                  type="text"
973f8fbdaf80atagen2026-09-28 09:10 UTC2978
                  placeholder="Weekend plans"
973f8fbdaf80atagen2026-09-28 09:10 UTC2979
                  bind:value={createName}
973f8fbdaf80atagen2026-09-28 09:10 UTC2980
                  required
973f8fbdaf80atagen2026-09-28 09:10 UTC2981
                  disabled={createBusy}
973f8fbdaf80atagen2026-09-28 09:10 UTC2982
                />
973f8fbdaf80atagen2026-09-28 09:10 UTC2983
              </label>
973f8fbdaf80atagen2026-09-28 09:10 UTC2984
              <label class="field">
973f8fbdaf80atagen2026-09-28 09:10 UTC2985
                <span>Topic (optional)</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC2986
                <input
973f8fbdaf80atagen2026-09-28 09:10 UTC2987
                  type="text"
973f8fbdaf80atagen2026-09-28 09:10 UTC2988
                  placeholder="What should this room be about?"
973f8fbdaf80atagen2026-09-28 09:10 UTC2989
                  bind:value={createTopic}
973f8fbdaf80atagen2026-09-28 09:10 UTC2990
                  disabled={createBusy}
973f8fbdaf80atagen2026-09-28 09:10 UTC2991
                />
973f8fbdaf80atagen2026-09-28 09:10 UTC2992
              </label>
973f8fbdaf80atagen2026-09-28 09:10 UTC2993
              <button type="submit" class="primary-btn wide" disabled={createBusy || !createName.trim()}>
973f8fbdaf80atagen2026-09-28 09:10 UTC2994
                {createBusy ? 'Creating…' : 'Create room'}
973f8fbdaf80atagen2026-09-28 09:10 UTC2995
              </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC2996
            </form>
973f8fbdaf80atagen2026-09-28 09:10 UTC2997
            {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC2998
          </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC2999
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC3000
      </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC3001
    {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC3002
  </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC3003
{/if}
cf23dbf4e77catagen2026-10-23 06:36 UTC3004
cf23dbf4e77catagen2026-10-23 06:36 UTC3005
<ImageLightbox />