atagen

malice

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