atagen

malice

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