atagen

malice

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

Blame: web/src/App.svelte

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