atagen

malice

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

Blame: web/src/App.svelte

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