atagen

malice

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