atagen

malice

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