atagen

malice

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