atagen

malice

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