atagen

malice

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