atagen

malice

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

Blame: web/src/App.svelte

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