atagen

malice

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