atagen

malice

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

Blame: web/src/App.svelte

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