atagen

malice

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