atagen

malice

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