atagen

malice

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