atagen

malice

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

Blame: web/src/App.svelte

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