atagen

malice

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