atagen

malice

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