atagen

malice

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