atagen

malice

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