atagen

malice

public
Star0
Watch0
988fbf982ada53ef8961e1532f3755112731c232
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git

Blame: web/src/App.svelte

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