atagen

malice

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

Blame: web/src/App.svelte

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