atagen

malice

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

Blame: web/src/App.svelte

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