atagen

malice

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