| 1 | <script lang="ts"> |
| 2 | import { onMount, tick } from 'svelte'; |
| 3 | import { fade, fly } from 'svelte/transition'; |
| 4 | import LoginPanel from './lib/LoginPanel.svelte'; |
| 5 | import MessageRow from './lib/MessageRow.svelte'; |
| 6 | import MentionsInbox from './lib/MentionsInbox.svelte'; |
| 7 | import MxcAvatar from './lib/MxcAvatar.svelte'; |
| 8 | import PinButton from './lib/PinButton.svelte'; |
| 9 | import ThreadPane from './lib/ThreadPane.svelte'; |
| 10 | import Composer from './lib/Composer.svelte'; |
| 11 | import SearchView from './lib/SearchView.svelte'; |
| 12 | import type { ScopeOption } from './lib/search-model'; |
| 13 | import { releaseStaged, stageFiles as stageAttachments, type StagedAttachment, type StickerHandlers } from './lib/staging'; |
| 14 | import RoomThreads from './lib/RoomThreads.svelte'; |
| 15 | import { loadPinnedThreads, openThread, showThread, threadsByRoom } from './lib/threads'; |
| 16 | import { threadMatches } from './lib/thread-index'; |
| 17 | import ContextMenu, { type MenuItem } from './lib/ContextMenu.svelte'; |
| 18 | import PackManager from './lib/PackManager.svelte'; |
| 19 | import PackCloneDialog from './lib/PackCloneDialog.svelte'; |
| 20 | import type { CloneSource } from './lib/pack-clone'; |
| 21 | import { allPacks, findSticker, reactionShortcode } from './lib/packs'; |
| 22 | import { disabledPackImages, loadPackPreferences } from './lib/pack-preferences'; |
| 23 | import { enabledPacks, enabledQuickReactions } from './lib/pack-preferences-model'; |
| 24 | import type { CommandRequest } from './lib/transport'; |
| 25 | import UserCard, { type UserAction } from './lib/UserCard.svelte'; |
| 26 | import { allowed, canRedact, groupMembers, isMuted, parsePowerLevels, type PowerLevels } from './lib/permissions'; |
| 27 | import { moveBefore, pinnedFirst, sortSpaces } from './lib/rail-order'; |
| 28 | import ImageLightbox from './lib/ImageLightbox.svelte'; |
| 29 | import { lightbox } from './lib/lightbox'; |
| 30 | import SecurityPanel from './lib/SecurityPanel.svelte'; |
| 31 | import { |
| 32 | closeRoom, |
| 33 | createRoom, |
| 34 | getEncryption, |
| 35 | getMembers, |
| 36 | getProfile, |
| 37 | getRooms, |
| 38 | getSession, |
| 39 | getSpaceChildren, |
| 40 | fillHistoryGap, |
| 41 | startRecentHistory, |
| 42 | joinRoom, |
| 43 | leaveRoom, |
| 44 | logout, |
| 45 | markRead, |
| 46 | openRoom, |
| 47 | paginateRoom, |
| 48 | reactToMessage, |
| 49 | runCommand, |
| 50 | sendMessage, |
| 51 | uploadAttachment, |
| 52 | uploadAvatar, |
| 53 | uploadRoomAvatar, |
| 54 | editMessage |
| 55 | } from './lib/api'; |
| 56 | import EmojiText from './lib/EmojiText.svelte'; |
| 57 | import { customEmotes, resolveEmotes } from './lib/emotes'; |
| 58 | import { isKnownCommand, parseCommand, splitTarget, unescapeCommand } from './lib/commands'; |
| 59 | import type { ParsedCommand } from './lib/commands'; |
| 60 | import { |
| 61 | banners, |
| 62 | blocked, |
| 63 | connectEvents, |
| 64 | connection, |
| 65 | disconnectEvents, |
| 66 | dismissBanner, |
| 67 | encryption, |
| 68 | membersByRoom, |
| 69 | membersLoading, |
| 70 | mentionsSnapshot, |
| 71 | pushBanner, |
| 72 | imagePacks, |
| 73 | markTimelineOpened, |
| 74 | recentHistory, |
| 75 | resetClientState, |
| 76 | rooms, |
| 77 | selectedRoomId, |
| 78 | sessionUser, |
| 79 | softLogout, |
| 80 | threadTimelines, |
| 81 | timelines, |
| 82 | pinnedTimelines, |
| 83 | pinnedTimelineVersions, |
| 84 | verification |
| 85 | } from './lib/store'; |
| 86 | import { discardPending, pendingByRoom, queueSend, resetPending, retryPending } from './lib/pending'; |
| 87 | import type { PendingMessage } from './lib/pending'; |
| 88 | import { TimelineViewport } from './lib/timeline-viewport'; |
| 89 | import { mentionsFromHtml, resolveMentions } from './lib/mentions'; |
| 90 | import type { Mention } from './lib/mentions'; |
| 91 | import { loadQuickReactions, quickReactions, saveQuickReactions } from './lib/quick-reactions'; |
| 92 | import { loadKeywords } from './lib/keywords'; |
| 93 | import { |
| 94 | linkPreviews, |
| 95 | loadUrlPreviewSettings, |
| 96 | requestLinkPreview, |
| 97 | saveUrlPreviewSettings, |
| 98 | urlPreviewSettings |
| 99 | } from './lib/link-previews'; |
| 100 | import { notifyTyping, stopTyping } from './lib/typing'; |
| 101 | import { formatDay } from './lib/format'; |
| 102 | import { |
| 103 | MEMBERS_WIDTH, |
| 104 | SIDE_WIDTH, |
| 105 | THREAD_WIDTH, |
| 106 | lastSpaceRooms, |
| 107 | lineHeight, |
| 108 | membersWidth, |
| 109 | messageSpacing, |
| 110 | navFolded, |
| 111 | railFolded, |
| 112 | sideWidth, |
| 113 | threadWidth |
| 114 | } from './lib/appearance'; |
| 115 | import SettingsPanel from './lib/SettingsPanel.svelte'; |
| 116 | import { packsForRoom, parseEncryptionState, parseOwnProfile, parseVerificationState, contentPreview, senderLabel } from './lib/types'; |
| 117 | import type { ImagePack, MemberSummary, OwnProfile, PackImage, Person, QuickReaction, ReplyReference, RoomSummary, SendState, TimelineEvent, TimelineItem } from './lib/types'; |
| 118 | |
| 119 | let roomsLoading = false; |
| 120 | let booted = false; |
| 121 | let wasOnline = false; |
| 122 | let search = ''; |
| 123 | let sidebarOpen = false; |
| 124 | let membersOpen = false; |
| 125 | let replyingTo: ReplyReference | null = null; |
| 126 | let dialog: 'join' | 'create' | 'security' | 'settings' | 'packs' | null = null; |
| 127 | let cloneSource: CloneSource | null = null; |
| 128 | let joinTarget = ''; |
| 129 | let joinBusy = false; |
| 130 | let createName = ''; |
| 131 | let createTopic = ''; |
| 132 | let createBusy = false; |
| 133 | let leaveBusy = false; |
| 134 | let paginateBusy = false; |
| 135 | let fillingGaps: Record<string, string> = {}; |
| 136 | let recentRetrying: Record<string, boolean> = {}; |
| 137 | let historyAccount: string | null | undefined; |
| 138 | $: if ($sessionUser !== historyAccount) { |
| 139 | historyAccount = $sessionUser; |
| 140 | fillingGaps = {}; |
| 141 | recentRetrying = {}; |
| 142 | } |
| 143 | let reacting = false; |
| 144 | let composer = ''; |
| 145 | let drafts: Record<string, string> = {}; |
| 146 | let stickToBottom = true; |
| 147 | let timelineEl: HTMLElement | null = null; |
| 148 | let timelineViewport: TimelineViewport | null = null; |
| 149 | let composerRef: Composer | null = null; |
| 150 | let avatarInput: HTMLInputElement | null = null; |
| 151 | let uploadBusy = false; |
| 152 | let uploadName: string | null = null; |
| 153 | let staged: Record<string, StagedAttachment[]> = {}; |
| 154 | let editing: { roomId: string; eventId: string; original: string; stash: string } | null = null; |
| 155 | /** Everyone picked from the finder per room; only those whose name is still in the text get linked on send. */ |
| 156 | let pickedMentions: Record<string, Mention[]> = {}; |
| 157 | const WARM_ROOM_LIMIT = 8; |
| 158 | /** Rooms left open after switching away so coming back is instant, least recently viewed first. */ |
| 159 | let warmRooms: string[] = []; |
| 160 | let openReady: Record<string, boolean> = {}; |
| 161 | let openFailed: Record<string, string> = {}; |
| 162 | let membersFor: string | null = null; |
| 163 | let lastReadKey = ''; |
| 164 | let readTimer: number | null = null; |
| 165 | let profile: OwnProfile | null = null; |
| 166 | let profileMxc: string | null = null; |
| 167 | let selectedSpaceId: string | null = null; |
| 168 | let mentionsOpen = false; |
| 169 | let searchOpen = false; |
| 170 | let searchScopes: ScopeOption[] = [{ label: 'Everywhere', scope: { kind: 'all' } }]; |
| 171 | let spaceChildIds: string[] | null = null; |
| 172 | let spaceChildrenLoading = false; |
| 173 | let spaceChildrenError: string | null = null; |
| 174 | let avatarByUser: Record<string, string | null> = {}; |
| 175 | let restoringRoute = false; |
| 176 | function motionDuration(ms: number): number { |
| 177 | return typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : ms; |
| 178 | } |
| 179 | |
| 180 | // account data is read from the local cache, which is empty on a fresh device until the first sync lands |
| 181 | $: { |
| 182 | const online = $connection === 'online'; |
| 183 | if (online && !wasOnline) { |
| 184 | void loadQuickReactions(); |
| 185 | void loadKeywords(); |
| 186 | void loadPinnedThreads(); |
| 187 | void loadPackPreferences(); |
| 188 | void loadUrlPreviewSettings(); |
| 189 | } |
| 190 | wasOnline = online; |
| 191 | } |
| 192 | $: selectedRoom = $rooms.find((r) => r.room_id === $selectedRoomId) ?? null; |
| 193 | $: recentState = $selectedRoomId ? $recentHistory[$selectedRoomId] : undefined; |
| 194 | $: roomPacks = enabledPacks(packsForRoom($imagePacks, $selectedRoomId, $rooms), $disabledPackImages); |
| 195 | $: roomEmotes = customEmotes(roomPacks); |
| 196 | $: usableQuickReactions = enabledQuickReactions($quickReactions, allPacks($imagePacks), $disabledPackImages); |
| 197 | $: previewsAllowed = selectedRoom !== null && (!selectedRoom.encrypted || $urlPreviewSettings.encrypted_rooms); |
| 198 | $: loadPreview = previewsAllowed && $selectedRoomId ? previewLoader($selectedRoomId) : null; |
| 199 | $: spaceRooms = $rooms.filter((r) => r.space); |
| 200 | $: spaceParents = parentSpaceMap(spaceRooms); |
| 201 | $: railSpaces = spaceRooms.filter((s) => !spaceParents.has(s.room_id)); |
| 202 | let railOverride: string[] | null = null; |
| 203 | $: if (railOverride && sortSpaces(railSpaces, null).map((s) => s.room_id).join() === railOverride.join()) railOverride = null; |
| 204 | $: orderedRail = sortSpaces(railSpaces, railOverride); |
| 205 | $: pinnedRail = orderedRail.filter((s) => s.favourite); |
| 206 | $: otherRail = orderedRail.filter((s) => !s.favourite); |
| 207 | $: railSelected = selectedSpaceId ? topSpaceOf(selectedSpaceId, spaceParents) : null; |
| 208 | $: invites = $rooms.filter((r) => r.membership === 'Invited'); |
| 209 | $: query = search.trim().toLowerCase(); |
| 210 | $: selectedSpace = selectedSpaceId ? ($rooms.find((r) => r.room_id === selectedSpaceId) ?? null) : null; |
| 211 | // While a space's children load (or fail), show no channels rather than the |
| 212 | // full list — listing everything would falsely imply it belongs to the space. |
| 213 | $: baseRooms = selectedSpaceId ? (spaceChildIds ? $rooms.filter((r) => spaceChildIds?.includes(r.room_id)) : []) : $rooms; |
| 214 | $: visibleRooms = query |
| 215 | ? baseRooms.filter( |
| 216 | (r) => |
| 217 | r.name.toLowerCase().includes(query) || |
| 218 | r.room_id.toLowerCase().includes(query) || |
| 219 | ($threadsByRoom[r.room_id] ?? []).some((t) => threadMatches(t, query)) |
| 220 | ) |
| 221 | : baseRooms; |
| 222 | $: directRooms = pinnedFirst(visibleRooms.filter((r) => r.direct && !r.space && r.membership !== 'Invited')); |
| 223 | $: groupRooms = pinnedFirst(visibleRooms.filter((r) => !r.direct && !r.space && r.membership !== 'Invited')); |
| 224 | $: spaceList = pinnedFirst(visibleRooms.filter((r) => r.space && r.membership !== 'Invited')); |
| 225 | $: channelRooms = baseRooms.filter((r) => !r.space && r.membership !== 'Invited'); |
| 226 | $: recoveryBanner = $encryption && ($encryption.recovery === 'Disabled' || $encryption.recovery === 'Incomplete') ? $encryption : null; |
| 227 | $: verificationBanner = $verification && $verification.kind !== 'Done' ? $verification : null; |
| 228 | $: items = $selectedRoomId ? ($timelines[$selectedRoomId] ?? []) : []; |
| 229 | $: currentStaged = $selectedRoomId ? (staged[$selectedRoomId] ?? []) : []; |
| 230 | $: members = $selectedRoomId ? ($membersByRoom[$selectedRoomId] ?? []) : []; |
| 231 | $: memberGroups = groupMembers(members, roomLevels); |
| 232 | $: people = peopleIn(items, members); |
| 233 | $: hasStart = items.some((i) => i.kind === 'start'); |
| 234 | $: grouped = buildGroups(items); |
| 235 | $: lastSentId = lastOwnSent(items); |
| 236 | $: pendingItems = $selectedRoomId ? ($pendingByRoom[$selectedRoomId] ?? []) : []; |
| 237 | $: lastRealOwn = lastSenderIsOwn(items); |
| 238 | |
| 239 | function lastSenderIsOwn(list: TimelineItem[]): boolean { |
| 240 | for (let i = list.length - 1; i >= 0; i -= 1) { |
| 241 | const it = list[i]; |
| 242 | if (it.kind === 'event') return it.event.sender.user_id === $sessionUser; |
| 243 | } |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | function pendingShowSender(index: number): boolean { |
| 248 | return index === 0 ? !lastRealOwn : false; |
| 249 | } |
| 250 | |
| 251 | function pendingToEvent(p: PendingMessage): TimelineEvent { |
| 252 | const state: SendState = p.status === 'failed' ? { kind: 'Failed', will_retry: false } : { kind: 'Sending' }; |
| 253 | return { |
| 254 | item_id: `pending-${p.id}`, |
| 255 | event_id: null, |
| 256 | transaction_id: p.id, |
| 257 | sender: { |
| 258 | user_id: $sessionUser ?? '', |
| 259 | display_name: profile?.display_name ?? null, |
| 260 | avatar: null, |
| 261 | name_ambiguous: false |
| 262 | }, |
| 263 | timestamp_ms: p.createdAt, |
| 264 | own: true, |
| 265 | send_state: state, |
| 266 | content: { |
| 267 | kind: 'Message', |
| 268 | message: { kind: 'Text', body: p.body, geo_uri: null, formatted_body: p.formatted, edited: false, media: null, link_previews: [] } |
| 269 | }, |
| 270 | reply_to: p.replyTo, |
| 271 | thread_root: null, |
| 272 | thread_summary: null, |
| 273 | reactions: [], |
| 274 | read_by: [], |
| 275 | editable: false |
| 276 | }; |
| 277 | } |
| 278 | |
| 279 | interface Group { |
| 280 | key: string; |
| 281 | item: TimelineItem; |
| 282 | showSender: boolean; |
| 283 | } |
| 284 | |
| 285 | function lastOwnSent(list: TimelineItem[]): string | null { |
| 286 | for (let i = list.length - 1; i >= 0; i--) { |
| 287 | const item = list[i]; |
| 288 | if (item.kind === 'event' && item.event.own && item.event.send_state.kind === 'Sent') return item.event.item_id; |
| 289 | } |
| 290 | return null; |
| 291 | } |
| 292 | |
| 293 | function buildGroups(list: TimelineItem[]): Group[] { |
| 294 | const out: Group[] = []; |
| 295 | let prevSender: string | null = null; |
| 296 | let prevTs = 0; |
| 297 | list.forEach((item, index) => { |
| 298 | let showSender = true; |
| 299 | if (item.kind === 'event') { |
| 300 | const e = item.event; |
| 301 | showSender = |
| 302 | prevSender !== e.sender.user_id || Math.abs(e.timestamp_ms - prevTs) > 5 * 60 * 1000; |
| 303 | prevSender = e.sender.user_id; |
| 304 | prevTs = e.timestamp_ms; |
| 305 | out.push({ key: e.item_id || e.event_id || `m-${index}`, item, showSender }); |
| 306 | } else { |
| 307 | prevSender = null; |
| 308 | const key = item.kind === 'historyGap' ? `gap-${item.gap.id}` : `${item.kind}-${index}`; |
| 309 | out.push({ key, item, showSender }); |
| 310 | } |
| 311 | }); |
| 312 | return out; |
| 313 | } |
| 314 | |
| 315 | function roomUnread(r: RoomSummary): number { |
| 316 | return r.unread_messages + r.unread_mentions; |
| 317 | } |
| 318 | |
| 319 | function recordRoute(spaceId: string | null, roomId: string | null, view?: string): void { |
| 320 | if (restoringRoute) return; |
| 321 | const url = new URL(window.location.href); |
| 322 | url.searchParams.delete('space'); |
| 323 | url.searchParams.delete('room'); |
| 324 | url.searchParams.delete('view'); |
| 325 | if (view) url.searchParams.set('view', view); |
| 326 | if (spaceId) url.searchParams.set('space', spaceId); |
| 327 | if (roomId) url.searchParams.set('room', roomId); |
| 328 | const next = `${url.pathname}${url.search}${url.hash}`; |
| 329 | const current = `${window.location.pathname}${window.location.search}${window.location.hash}`; |
| 330 | if (next !== current) window.history.pushState({ spaceId, roomId }, '', next); |
| 331 | } |
| 332 | |
| 333 | async function restoreRoute(): Promise<void> { |
| 334 | const url = new URL(window.location.href); |
| 335 | const roomId = url.searchParams.get('room'); |
| 336 | const spaceId = url.searchParams.get('space'); |
| 337 | restoringRoute = true; |
| 338 | try { |
| 339 | if (url.searchParams.get('view') === 'mentions') { |
| 340 | selectMentions(); |
| 341 | } else if (url.searchParams.get('view') === 'search') { |
| 342 | selectSearch(); |
| 343 | } else if (roomId && $rooms.some((room) => room.room_id === roomId && !room.space)) { |
| 344 | selectedSpaceId = spaceId && $rooms.some((room) => room.room_id === spaceId && room.space) ? spaceId : null; |
| 345 | spaceChildrenError = null; |
| 346 | spaceChildIds = selectedSpaceId ? (await getSpaceChildren(selectedSpaceId)).room_ids ?? [] : null; |
| 347 | await selectRoom(roomId); |
| 348 | } else if (spaceId && $rooms.some((room) => room.room_id === spaceId && room.space)) { |
| 349 | await selectSpace(spaceId); |
| 350 | } else { |
| 351 | await selectHome(); |
| 352 | } |
| 353 | } catch (e) { |
| 354 | pushBanner(e instanceof Error ? e.message : 'Could not restore navigation'); |
| 355 | } finally { |
| 356 | restoringRoute = false; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | function isEditable(target: EventTarget | null): boolean { |
| 361 | if (!(target instanceof HTMLElement)) return false; |
| 362 | return target instanceof HTMLTextAreaElement || target instanceof HTMLInputElement || target.isContentEditable; |
| 363 | } |
| 364 | |
| 365 | onMount(() => { |
| 366 | const onPopState = () => void restoreRoute(); |
| 367 | const onAttention = () => queueReadReceipt(); |
| 368 | const hidePointer = (e: KeyboardEvent) => { |
| 369 | if (e.ctrlKey || e.metaKey || e.altKey || !isEditable(e.target)) return; |
| 370 | if (e.key.length === 1 || e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Enter') { |
| 371 | document.documentElement.classList.add('pointer-hidden'); |
| 372 | } |
| 373 | }; |
| 374 | const showPointer = () => document.documentElement.classList.remove('pointer-hidden'); |
| 375 | const movePointer = (e: PointerEvent) => { |
| 376 | if (e.movementX !== 0 || e.movementY !== 0) showPointer(); |
| 377 | }; |
| 378 | window.addEventListener('popstate', onPopState); |
| 379 | window.addEventListener('focus', onAttention); |
| 380 | document.addEventListener('visibilitychange', onAttention); |
| 381 | window.addEventListener('keydown', hidePointer, true); |
| 382 | window.addEventListener('pointermove', movePointer); |
| 383 | window.addEventListener('pointerdown', showPointer); |
| 384 | void boot(); |
| 385 | return () => { |
| 386 | window.removeEventListener('popstate', onPopState); |
| 387 | window.removeEventListener('focus', onAttention); |
| 388 | document.removeEventListener('visibilitychange', onAttention); |
| 389 | window.removeEventListener('keydown', hidePointer, true); |
| 390 | window.removeEventListener('pointermove', movePointer); |
| 391 | window.removeEventListener('pointerdown', showPointer); |
| 392 | showPointer(); |
| 393 | disconnectEvents(); |
| 394 | stopTyping(); |
| 395 | if (readTimer !== null) window.clearTimeout(readTimer); |
| 396 | }; |
| 397 | }); |
| 398 | |
| 399 | async function boot(): Promise<void> { |
| 400 | try { |
| 401 | const session = await getSession(); |
| 402 | blocked.set(session.blocked ?? false); |
| 403 | sessionUser.set(session.user_id); |
| 404 | if (session.user_id) { |
| 405 | softLogout.set(null); |
| 406 | await refreshRooms(); |
| 407 | await restoreRoute(); |
| 408 | connectEvents(); |
| 409 | void loadProfile(); |
| 410 | void loadEncryption(); |
| 411 | void loadQuickReactions(); |
| 412 | void loadKeywords(); |
| 413 | void loadPinnedThreads(); |
| 414 | void loadPackPreferences(); |
| 415 | void loadUrlPreviewSettings(); |
| 416 | } else { |
| 417 | softLogout.set(session.soft_logout ?? null); |
| 418 | } |
| 419 | } catch (e) { |
| 420 | pushBanner(e instanceof Error ? `Session check failed: ${e.message}` : 'Session check failed'); |
| 421 | sessionUser.set(null); |
| 422 | } finally { |
| 423 | booted = true; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | async function refreshRooms(): Promise<void> { |
| 428 | roomsLoading = true; |
| 429 | try { |
| 430 | const res = await getRooms(); |
| 431 | rooms.set(res.rooms); |
| 432 | pruneSpaceFilter(); |
| 433 | } catch (e) { |
| 434 | pushBanner(e instanceof Error ? e.message : 'Could not load rooms'); |
| 435 | } finally { |
| 436 | roomsLoading = false; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | async function loadProfile(): Promise<void> { |
| 441 | try { |
| 442 | const raw = await getProfile(); |
| 443 | profile = parseOwnProfile(raw); |
| 444 | profileMxc = profile.avatar_url; |
| 445 | } catch { |
| 446 | profile = null; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | async function loadEncryption(): Promise<void> { |
| 451 | try { |
| 452 | const res = await getEncryption(); |
| 453 | const state = parseEncryptionState(res.state); |
| 454 | if (state) encryption.set(state); |
| 455 | const verificationState = parseVerificationState(res.verification); |
| 456 | if (verificationState) verification.set(verificationState); |
| 457 | } catch { |
| 458 | // Encryption status also arrives over SSE; a failed first fetch is not fatal. |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | function afterLogin(userId: string): void { |
| 463 | sessionUser.set(userId); |
| 464 | softLogout.set(null); |
| 465 | blocked.set(false); |
| 466 | void refreshRooms(); |
| 467 | connectEvents(); |
| 468 | void loadProfile(); |
| 469 | void loadEncryption(); |
| 470 | void loadQuickReactions(); |
| 471 | void loadKeywords(); |
| 472 | void loadPinnedThreads(); |
| 473 | void loadPackPreferences(); |
| 474 | void loadUrlPreviewSettings(); |
| 475 | } |
| 476 | |
| 477 | async function doLogout(): Promise<void> { |
| 478 | stopTyping(); |
| 479 | try { |
| 480 | await logout(); |
| 481 | } catch (e) { |
| 482 | pushBanner(e instanceof Error ? e.message : 'Logout failed'); |
| 483 | return; |
| 484 | } |
| 485 | disconnectEvents(); |
| 486 | resetClientState(); |
| 487 | softLogout.set(null); |
| 488 | blocked.set(false); |
| 489 | sessionUser.set(null); |
| 490 | lightbox.set(null); |
| 491 | composer = ''; |
| 492 | drafts = {}; |
| 493 | dialog = null; |
| 494 | cloneSource = null; |
| 495 | membersOpen = false; |
| 496 | sidebarOpen = false; |
| 497 | profile = null; |
| 498 | profileMxc = null; |
| 499 | mentionsOpen = false; |
| 500 | searchOpen = false; |
| 501 | selectedSpaceId = null; |
| 502 | spaceChildIds = null; |
| 503 | spaceChildrenError = null; |
| 504 | openReady = {}; |
| 505 | openFailed = {}; |
| 506 | warmRooms = []; |
| 507 | pickedMentions = {}; |
| 508 | composerRef?.closeFinders(); |
| 509 | clearAllStaged(); |
| 510 | avatarByUser = {}; |
| 511 | resetPending(); |
| 512 | } |
| 513 | |
| 514 | /** Joined spaces that sit inside another joined space, keyed to one such parent. Either side of the link counts. */ |
| 515 | function parentSpaceMap(spaces: RoomSummary[]): Map<string, string> { |
| 516 | const ids = new Set(spaces.map((s) => s.room_id)); |
| 517 | const parents = new Map<string, string>(); |
| 518 | for (const space of spaces) { |
| 519 | for (const child of space.children) { |
| 520 | if (child !== space.room_id && ids.has(child) && !parents.has(child)) parents.set(child, space.room_id); |
| 521 | } |
| 522 | } |
| 523 | for (const space of spaces) { |
| 524 | const parent = space.parent_spaces.find((id) => id !== space.room_id && ids.has(id)); |
| 525 | if (parent && !parents.has(space.room_id)) parents.set(space.room_id, parent); |
| 526 | } |
| 527 | for (const id of [...parents.keys()]) { |
| 528 | const seen = new Set<string>([id]); |
| 529 | let at = parents.get(id); |
| 530 | while (at && !seen.has(at)) { |
| 531 | seen.add(at); |
| 532 | at = parents.get(at); |
| 533 | } |
| 534 | if (at) parents.delete(id); |
| 535 | } |
| 536 | return parents; |
| 537 | } |
| 538 | |
| 539 | function topSpaceOf(id: string, parents: Map<string, string>): string { |
| 540 | let at = id; |
| 541 | while (parents.has(at)) at = parents.get(at)!; |
| 542 | return at; |
| 543 | } |
| 544 | |
| 545 | function pruneSpaceFilter(): void { |
| 546 | if (!selectedSpaceId) return; |
| 547 | if (!$rooms.some((r) => r.room_id === selectedSpaceId)) { |
| 548 | selectedSpaceId = null; |
| 549 | spaceChildIds = null; |
| 550 | spaceChildrenError = null; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | async function selectHome(): Promise<void> { |
| 555 | mentionsOpen = false; |
| 556 | searchOpen = false; |
| 557 | selectedSpaceId = null; |
| 558 | spaceChildIds = null; |
| 559 | spaceChildrenError = null; |
| 560 | if (window.innerWidth > 640) navFolded.set(false); |
| 561 | sidebarOpen = true; |
| 562 | recordRoute(null, null); |
| 563 | } |
| 564 | |
| 565 | function stashDraft(): void { |
| 566 | const roomId = $selectedRoomId; |
| 567 | if (!roomId) return; |
| 568 | if (composer.trim()) drafts[roomId] = composer; |
| 569 | else delete drafts[roomId]; |
| 570 | } |
| 571 | |
| 572 | function selectMentions(): void { |
| 573 | stashDraft(); |
| 574 | stopTyping(); |
| 575 | selectedSpaceId = null; |
| 576 | spaceChildIds = null; |
| 577 | spaceChildrenError = null; |
| 578 | spaceChildrenLoading = false; |
| 579 | selectedRoomId.set(null); |
| 580 | replyingTo = null; |
| 581 | editing = null; |
| 582 | composerRef?.closeFinders(); |
| 583 | peeking = null; |
| 584 | membersOpen = false; |
| 585 | sidebarOpen = false; |
| 586 | searchOpen = false; |
| 587 | mentionsOpen = true; |
| 588 | recordRoute(null, null, 'mentions'); |
| 589 | } |
| 590 | |
| 591 | function selectSearch(): void { |
| 592 | const fromRoom = $selectedRoomId ? $rooms.find((r) => r.room_id === $selectedRoomId) ?? null : null; |
| 593 | const options: ScopeOption[] = []; |
| 594 | if (fromRoom) options.push({ label: fromRoom.name, scope: { kind: 'room', room_id: fromRoom.room_id } }); |
| 595 | if (selectedSpace && spaceChildIds) { |
| 596 | const roomIds = spaceChildIds.filter((id) => $rooms.some((r) => r.room_id === id && !r.space)); |
| 597 | if (roomIds.length) options.push({ label: selectedSpace.name, scope: { kind: 'rooms', room_ids: roomIds } }); |
| 598 | } |
| 599 | options.push({ label: 'Everywhere', scope: { kind: 'all' } }); |
| 600 | stashDraft(); |
| 601 | stopTyping(); |
| 602 | selectedRoomId.set(null); |
| 603 | replyingTo = null; |
| 604 | editing = null; |
| 605 | composerRef?.closeFinders(); |
| 606 | peeking = null; |
| 607 | membersOpen = false; |
| 608 | sidebarOpen = false; |
| 609 | mentionsOpen = false; |
| 610 | searchScopes = options; |
| 611 | searchOpen = true; |
| 612 | recordRoute(selectedSpaceId, null, 'search'); |
| 613 | } |
| 614 | |
| 615 | function toggleChannelsPane(): void { |
| 616 | if (window.innerWidth <= 640) sidebarOpen = !sidebarOpen; |
| 617 | else navFolded.update((v) => !v); |
| 618 | } |
| 619 | |
| 620 | async function selectSpace(spaceId: string): Promise<void> { |
| 621 | mentionsOpen = false; |
| 622 | searchOpen = false; |
| 623 | stashDraft(); |
| 624 | stopTyping(); |
| 625 | selectedSpaceId = spaceId; |
| 626 | spaceChildIds = null; |
| 627 | spaceChildrenError = null; |
| 628 | spaceChildrenLoading = true; |
| 629 | const last = $lastSpaceRooms[spaceId]; |
| 630 | const resume = last && $rooms.some((r) => r.room_id === last && !r.space) ? last : null; |
| 631 | if (resume) { |
| 632 | void selectRoom(resume); |
| 633 | } else { |
| 634 | selectedRoomId.set(null); |
| 635 | } |
| 636 | try { |
| 637 | const res = await getSpaceChildren(spaceId); |
| 638 | if (selectedSpaceId === spaceId) { |
| 639 | spaceChildIds = res.room_ids ?? []; |
| 640 | const firstChannel = spaceChildIds |
| 641 | .map((id) => $rooms.find((room) => room.room_id === id)) |
| 642 | .find((room) => room && !room.space); |
| 643 | if ((!resume || !spaceChildIds.includes(resume)) && firstChannel) { |
| 644 | await selectRoom(firstChannel.room_id); |
| 645 | } |
| 646 | } |
| 647 | } catch (e) { |
| 648 | if (selectedSpaceId === spaceId) { |
| 649 | spaceChildrenError = e instanceof Error ? e.message : 'Could not load rooms in this space'; |
| 650 | spaceChildIds = []; |
| 651 | } |
| 652 | } finally { |
| 653 | if (selectedSpaceId === spaceId) spaceChildrenLoading = false; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | async function selectRoom(roomId: string, peek = false): Promise<void> { |
| 658 | mentionsOpen = false; |
| 659 | searchOpen = false; |
| 660 | peeking = peek ? roomId : null; |
| 661 | stashDraft(); |
| 662 | if (roomId === $selectedRoomId && openReady[roomId]) { |
| 663 | sidebarOpen = false; |
| 664 | return; |
| 665 | } |
| 666 | stopTyping(); |
| 667 | const spaceId = selectedSpaceId; |
| 668 | if (spaceId) lastSpaceRooms.update((all) => ({ ...all, [spaceId]: roomId })); |
| 669 | selectedRoomId.set(roomId); |
| 670 | recordRoute(selectedSpaceId, roomId); |
| 671 | composer = drafts[roomId] ?? ''; |
| 672 | replyingTo = null; |
| 673 | editing = null; |
| 674 | composerRef?.closeFinders(); |
| 675 | stickToBottom = true; |
| 676 | lastReadKey = ''; |
| 677 | sidebarOpen = false; |
| 678 | touchWarmRoom(roomId); |
| 679 | if (openReady[roomId]) { |
| 680 | if (membersOpen) void loadMembers(roomId); |
| 681 | await tick(); |
| 682 | scrollToBottom(); |
| 683 | queueReadReceipt(); |
| 684 | composerRef?.focus(); |
| 685 | return; |
| 686 | } |
| 687 | if (openFailed[roomId]) { |
| 688 | const nextFailed = { ...openFailed }; |
| 689 | delete nextFailed[roomId]; |
| 690 | openFailed = nextFailed; |
| 691 | } |
| 692 | try { |
| 693 | markTimelineOpened(roomId); |
| 694 | await openRoom(roomId); |
| 695 | if (warmRooms.includes(roomId)) openReady = { ...openReady, [roomId]: true }; |
| 696 | } catch (e) { |
| 697 | const message = e instanceof Error ? e.message : `Could not open room ${roomId}`; |
| 698 | openFailed = { ...openFailed, [roomId]: message }; |
| 699 | pushBanner(message); |
| 700 | } |
| 701 | if ($selectedRoomId !== roomId) return; |
| 702 | if (membersOpen) void loadMembers(roomId); |
| 703 | await tick(); |
| 704 | scrollToBottom(); |
| 705 | queueReadReceipt(); |
| 706 | composerRef?.focus(); |
| 707 | } |
| 708 | |
| 709 | function touchWarmRoom(roomId: string): void { |
| 710 | warmRooms = [...warmRooms.filter((id) => id !== roomId), roomId]; |
| 711 | while (warmRooms.length > WARM_ROOM_LIMIT) { |
| 712 | const evicted = warmRooms[0]; |
| 713 | warmRooms = warmRooms.slice(1); |
| 714 | forgetOpenRoom(evicted); |
| 715 | closeRoom(evicted).catch(() => undefined); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | function forgetOpenRoom(roomId: string): void { |
| 720 | warmRooms = warmRooms.filter((id) => id !== roomId); |
| 721 | const nextReady = { ...openReady }; |
| 722 | delete nextReady[roomId]; |
| 723 | openReady = nextReady; |
| 724 | } |
| 725 | |
| 726 | function scrollToBottom(): void { |
| 727 | if (timelineViewport?.element === timelineEl) timelineViewport.scrollToBottom(); |
| 728 | else if (timelineEl) timelineEl.scrollTop = timelineEl.scrollHeight; |
| 729 | } |
| 730 | |
| 731 | function noteUserScroll(): void { |
| 732 | timelineViewport?.releaseScroll(); |
| 733 | } |
| 734 | |
| 735 | function onTimelineKey(e: KeyboardEvent): void { |
| 736 | if (['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End', ' '].includes(e.key)) noteUserScroll(); |
| 737 | } |
| 738 | |
| 739 | function onTimelineScroll(): void { |
| 740 | if (!timelineEl) return; |
| 741 | if (timelineViewport?.consumeScroll()) return; |
| 742 | const gap = timelineEl.scrollHeight - timelineEl.scrollTop - timelineEl.clientHeight; |
| 743 | const wasAtBottom = stickToBottom; |
| 744 | stickToBottom = gap < 2; |
| 745 | if (stickToBottom && !wasAtBottom) queueReadReceipt(); |
| 746 | timelineViewport?.capture(); |
| 747 | if (timelineEl.scrollTop < 80 && !hasStart && !paginateBusy) void paginate(); |
| 748 | } |
| 749 | |
| 750 | function pinTimeline(node: HTMLElement) { |
| 751 | const viewport = new TimelineViewport(node.parentElement!, $selectedRoomId); |
| 752 | timelineViewport = viewport; |
| 753 | const observer = new ResizeObserver(() => { |
| 754 | if (timelineViewport !== viewport || viewport.roomId !== $selectedRoomId) return; |
| 755 | if (stickToBottom) viewport.scrollToBottom(true); |
| 756 | else viewport.restore(); |
| 757 | }); |
| 758 | observer.observe(node); |
| 759 | if (node.parentElement) observer.observe(node.parentElement); |
| 760 | return { destroy: () => { |
| 761 | observer.disconnect(); |
| 762 | viewport.releaseScroll(); |
| 763 | if (timelineViewport === viewport) timelineViewport = null; |
| 764 | } }; |
| 765 | } |
| 766 | |
| 767 | $: void trackTimeline($selectedRoomId, items); |
| 768 | async function trackTimeline(roomId: string | null, list: TimelineItem[]): Promise<void> { |
| 769 | if (!roomId || list.length === 0) return; |
| 770 | if (roomId !== $selectedRoomId) return; |
| 771 | await tick(); |
| 772 | if (roomId !== $selectedRoomId || timelineViewport?.roomId !== roomId) return; |
| 773 | if (stickToBottom) timelineViewport.scrollToBottom(true); |
| 774 | else timelineViewport.restore(); |
| 775 | queueReadReceipt(); |
| 776 | } |
| 777 | |
| 778 | function queueReadReceipt(): void { |
| 779 | if (readTimer !== null) window.clearTimeout(readTimer); |
| 780 | readTimer = window.setTimeout(() => { |
| 781 | readTimer = null; |
| 782 | void sendReadReceipt(); |
| 783 | }, 800); |
| 784 | } |
| 785 | |
| 786 | async function sendReadReceipt(): Promise<void> { |
| 787 | const roomId = $selectedRoomId; |
| 788 | if (!roomId || roomId === peeking) return; |
| 789 | if (document.hidden || !document.hasFocus() || !stickToBottom) return; |
| 790 | const list = $timelines[roomId] ?? []; |
| 791 | for (let i = list.length - 1; i >= 0; i -= 1) { |
| 792 | const entry = list[i]; |
| 793 | if (entry.kind === 'event' && entry.event.event_id) { |
| 794 | const key = `${roomId}:${entry.event.event_id}`; |
| 795 | if (key === lastReadKey) return; |
| 796 | lastReadKey = key; |
| 797 | try { |
| 798 | await markRead(roomId, entry.event.event_id); |
| 799 | } catch { |
| 800 | return; |
| 801 | } |
| 802 | return; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | function send(): void { |
| 808 | if (editing) { |
| 809 | submitEdit(); |
| 810 | return; |
| 811 | } |
| 812 | const roomId = $selectedRoomId; |
| 813 | const body = composer.trim(); |
| 814 | const attachments = roomId ? (staged[roomId] ?? []) : []; |
| 815 | if (!roomId || (!body && attachments.length === 0)) return; |
| 816 | if (!openReady[roomId]) { |
| 817 | pushBanner('Still opening this room — sending is disabled until the room is ready.'); |
| 818 | return; |
| 819 | } |
| 820 | if (attachments.length > 0 && uploadBusy) return; |
| 821 | const command = parseCommand(body); |
| 822 | if (command && !isKnownCommand(command.name)) { |
| 823 | pushBanner(`Unknown command /${command.name}`); |
| 824 | return; |
| 825 | } |
| 826 | if (command && attachments.length > 0) { |
| 827 | if (command.name !== 'roomavatar' && command.name !== 'globalavatar') { |
| 828 | pushBanner(`/${command.name} doesn't take attachments`); |
| 829 | return; |
| 830 | } |
| 831 | if (command.args || attachments.length !== 1 || !attachments[0].file.type.startsWith('image/')) { |
| 832 | pushBanner(`/${command.name} takes a single attached image`); |
| 833 | return; |
| 834 | } |
| 835 | } |
| 836 | composer = ''; |
| 837 | if (roomId in drafts) delete drafts[roomId]; |
| 838 | stickToBottom = true; |
| 839 | const reply = replyingTo; |
| 840 | replyingTo = null; |
| 841 | const text = unescapeCommand(body); |
| 842 | const mentions = resolveMentions(text, pickedMentions[roomId] ?? []); |
| 843 | pickedMentions = { ...pickedMentions, [roomId]: [] }; |
| 844 | composerRef?.closeFinders(); |
| 845 | if (command) { |
| 846 | const image = attachments[0] ?? null; |
| 847 | if (image) { |
| 848 | const { [roomId]: _used, ...rest } = staged; |
| 849 | staged = rest; |
| 850 | } |
| 851 | void execute(roomId, command, reply, mentions, image?.file ?? null).finally(() => { |
| 852 | if (image?.previewUrl) URL.revokeObjectURL(image.previewUrl); |
| 853 | }); |
| 854 | } else if (attachments.length === 0) { |
| 855 | queueSend(roomId, text, reply, mentions, resolveEmotes(text, roomEmotes)); |
| 856 | } else { |
| 857 | const { [roomId]: _sent, ...rest } = staged; |
| 858 | staged = rest; |
| 859 | void sendAttachments(roomId, text, reply, mentions, attachments); |
| 860 | } |
| 861 | if (peeking === roomId) stopPeeking(); |
| 862 | composerRef?.focus(); |
| 863 | } |
| 864 | |
| 865 | function lastOwnEventId(): string | null { |
| 866 | for (let i = items.length - 1; i >= 0; i -= 1) { |
| 867 | const entry = items[i]; |
| 868 | if (entry.kind === 'event' && entry.event.own && entry.event.event_id && entry.event.content.kind !== 'Redacted') { |
| 869 | return entry.event.event_id; |
| 870 | } |
| 871 | } |
| 872 | return null; |
| 873 | } |
| 874 | |
| 875 | async function execute( |
| 876 | roomId: string, |
| 877 | command: ParsedCommand, |
| 878 | reply: ReplyReference | null, |
| 879 | mentions: Mention[], |
| 880 | image: File | null |
| 881 | ): Promise<void> { |
| 882 | const { name, args } = command; |
| 883 | const target = () => { |
| 884 | const found = splitTarget(args, Object.values(people)); |
| 885 | if ('error' in found) throw new Error(found.error); |
| 886 | return found; |
| 887 | }; |
| 888 | const required = (what: string) => { |
| 889 | if (!args) throw new Error(`/${name} needs ${what}`); |
| 890 | return args; |
| 891 | }; |
| 892 | try { |
| 893 | switch (name) { |
| 894 | case 'me': |
| 895 | case 'notice': { |
| 896 | const said = required('something to say'); |
| 897 | await sendMessage(roomId, said, null, mentions, name === 'me' ? 'emote' : 'notice', resolveEmotes(said, roomEmotes)); |
| 898 | break; |
| 899 | } |
| 900 | case 'sticker': { |
| 901 | const { pack, sticker } = findSticker(enabledPacks(packsForRoom($imagePacks, roomId, $rooms), $disabledPackImages), required('a sticker name')); |
| 902 | await runCommand({ op: 'send_sticker', room_id: roomId, pack_id: pack.id, shortcode: sticker.shortcode }); |
| 903 | break; |
| 904 | } |
| 905 | case 'msg': { |
| 906 | const { user_id, rest } = target(); |
| 907 | const res = (await runCommand({ op: 'direct', user_id })) as { room_id: string }; |
| 908 | await refreshRooms(); |
| 909 | await selectRoom(res.room_id); |
| 910 | if (rest) queueSend(res.room_id, rest); |
| 911 | break; |
| 912 | } |
| 913 | case 'join': |
| 914 | await join(required('a room id or alias')); |
| 915 | break; |
| 916 | case 'leave': |
| 917 | await leave(); |
| 918 | break; |
| 919 | case 'invite': |
| 920 | await runCommand({ op: 'invite', room_id: roomId, user_id: target().user_id }); |
| 921 | break; |
| 922 | case 'disinvite': |
| 923 | case 'kick': |
| 924 | case 'ban': |
| 925 | case 'unban': { |
| 926 | const { user_id, rest } = target(); |
| 927 | const op = name === 'disinvite' ? 'kick' : name; |
| 928 | await runCommand({ op, room_id: roomId, user_id, reason: rest || null }); |
| 929 | break; |
| 930 | } |
| 931 | case 'powerlevel': { |
| 932 | const { user_id, rest } = target(); |
| 933 | const level = Number(rest); |
| 934 | if (!rest || !Number.isInteger(level)) throw new Error('/powerlevel needs a whole number after the name'); |
| 935 | await runCommand({ op: 'set_power_level', room_id: roomId, user_id, level }); |
| 936 | break; |
| 937 | } |
| 938 | case 'mute': |
| 939 | case 'unmute': |
| 940 | await runCommand({ op: 'mute', room_id: roomId, user_id: target().user_id, muted: name === 'mute' }); |
| 941 | break; |
| 942 | case 'ignore': |
| 943 | case 'unignore': |
| 944 | await runCommand({ op: name, user_id: target().user_id }); |
| 945 | break; |
| 946 | case 'roomnick': |
| 947 | await runCommand({ op: 'set_room_display_name', room_id: roomId, name: args || null }); |
| 948 | break; |
| 949 | case 'roomavatar': |
| 950 | if (image) { |
| 951 | await uploadRoomAvatar(roomId, image); |
| 952 | } else if (args && !args.startsWith('mxc://')) { |
| 953 | throw new Error('/roomavatar takes an mxc:// link, an attached image, or nothing to drop the override'); |
| 954 | } else { |
| 955 | await runCommand({ op: 'set_room_avatar', room_id: roomId, mxc: args || null }); |
| 956 | } |
| 957 | break; |
| 958 | case 'delete': { |
| 959 | const eventId = reply?.event_id ?? lastOwnEventId(); |
| 960 | if (!eventId) throw new Error('Nothing of yours to delete here'); |
| 961 | await runCommand({ op: 'redact', room_id: roomId, event_id: eventId, reason: args || null }); |
| 962 | break; |
| 963 | } |
| 964 | case 'globalnick': |
| 965 | await runCommand({ op: 'set_display_name', name: required('a name') }); |
| 966 | await loadProfile(); |
| 967 | break; |
| 968 | case 'globalavatar': |
| 969 | if (image) { |
| 970 | await uploadAvatar(image); |
| 971 | await loadProfile(); |
| 972 | } else if (!args) { |
| 973 | avatarInput?.click(); |
| 974 | } else if (args.startsWith('mxc://')) { |
| 975 | await runCommand({ op: 'set_avatar', mxc: args }); |
| 976 | await loadProfile(); |
| 977 | } else { |
| 978 | throw new Error('/globalavatar takes an mxc:// link, or nothing to pick a file'); |
| 979 | } |
| 980 | break; |
| 981 | } |
| 982 | } catch (e) { |
| 983 | pushBanner(e instanceof Error ? e.message : `/${name} failed`); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | async function onAvatarChosen(): Promise<void> { |
| 988 | const file = avatarInput?.files?.[0]; |
| 989 | if (avatarInput) avatarInput.value = ''; |
| 990 | if (!file) return; |
| 991 | try { |
| 992 | await uploadAvatar(file); |
| 993 | await loadProfile(); |
| 994 | } catch (e) { |
| 995 | pushBanner(e instanceof Error ? e.message : 'Avatar upload failed'); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | async function sendAttachments( |
| 1000 | roomId: string, |
| 1001 | body: string, |
| 1002 | reply: ReplyReference | null, |
| 1003 | mentions: Mention[], |
| 1004 | attachments: StagedAttachment[] |
| 1005 | ): Promise<void> { |
| 1006 | let first = true; |
| 1007 | uploadBusy = true; |
| 1008 | try { |
| 1009 | for (const attachment of attachments) { |
| 1010 | uploadName = attachment.file.name || 'attachment'; |
| 1011 | try { |
| 1012 | if (first) await uploadAttachment(roomId, attachment.file, body || null, reply?.event_id ?? null, mentions, resolveEmotes(body, roomEmotes)); |
| 1013 | else await uploadAttachment(roomId, attachment.file); |
| 1014 | first = false; |
| 1015 | } catch (e) { |
| 1016 | pushBanner(e instanceof Error ? e.message : 'Upload failed'); |
| 1017 | } |
| 1018 | if (attachment.previewUrl) URL.revokeObjectURL(attachment.previewUrl); |
| 1019 | } |
| 1020 | } finally { |
| 1021 | uploadBusy = false; |
| 1022 | uploadName = null; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | function stageFiles(files: File[]): void { |
| 1027 | const roomId = $selectedRoomId; |
| 1028 | if (!roomId || !openReady[roomId]) return; |
| 1029 | const accepted = stageAttachments(files, pushBanner); |
| 1030 | if (accepted.length === 0) return; |
| 1031 | staged = { ...staged, [roomId]: [...(staged[roomId] ?? []), ...accepted] }; |
| 1032 | composerRef?.focus(); |
| 1033 | } |
| 1034 | |
| 1035 | function unstage(roomId: string, id: number): void { |
| 1036 | const list = staged[roomId] ?? []; |
| 1037 | const removed = list.find((a) => a.id === id); |
| 1038 | if (removed?.previewUrl) URL.revokeObjectURL(removed.previewUrl); |
| 1039 | staged = { ...staged, [roomId]: list.filter((a) => a.id !== id) }; |
| 1040 | } |
| 1041 | |
| 1042 | function clearAllStaged(): void { |
| 1043 | for (const list of Object.values(staged)) releaseStaged(list); |
| 1044 | staged = {}; |
| 1045 | } |
| 1046 | |
| 1047 | function startEdit(eventId: string, body: string): void { |
| 1048 | const roomId = $selectedRoomId; |
| 1049 | if (!roomId) return; |
| 1050 | const stash = editing ? editing.stash : composer; |
| 1051 | editing = { roomId, eventId, original: body, stash }; |
| 1052 | const entry = items.find((i) => i.kind === 'event' && i.event.event_id === eventId); |
| 1053 | if (entry?.kind === 'event' && entry.event.content.kind === 'Message') { |
| 1054 | const existing = mentionsFromHtml(entry.event.content.message.formatted_body); |
| 1055 | pickedMentions = { ...pickedMentions, [roomId]: [...(pickedMentions[roomId] ?? []), ...existing] }; |
| 1056 | } |
| 1057 | composer = body; |
| 1058 | replyingTo = null; |
| 1059 | composerRef?.focus(); |
| 1060 | } |
| 1061 | |
| 1062 | function cancelEdit(): void { |
| 1063 | if (!editing) return; |
| 1064 | composer = editing.stash; |
| 1065 | editing = null; |
| 1066 | composerRef?.focus(); |
| 1067 | } |
| 1068 | |
| 1069 | function submitEdit(): void { |
| 1070 | if (!editing) return; |
| 1071 | const { roomId, eventId, original } = editing; |
| 1072 | const body = composer.trim(); |
| 1073 | cancelEdit(); |
| 1074 | if (!body || body === original.trim()) return; |
| 1075 | editMessage(roomId, eventId, body, resolveMentions(body, pickedMentions[roomId] ?? []), resolveEmotes(body, roomEmotes)).catch((e) => pushBanner(e instanceof Error ? e.message : 'Edit failed')); |
| 1076 | } |
| 1077 | |
| 1078 | function editLastOwn(): boolean { |
| 1079 | for (let i = items.length - 1; i >= 0; i -= 1) { |
| 1080 | const entry = items[i]; |
| 1081 | if (entry.kind !== 'event' || !entry.event.own) continue; |
| 1082 | const ev = entry.event; |
| 1083 | if (!ev.editable || !ev.event_id || ev.content.kind !== 'Message' || ev.content.message.kind !== 'Text') return false; |
| 1084 | startEdit(ev.event_id, ev.content.message.body); |
| 1085 | return true; |
| 1086 | } |
| 1087 | return false; |
| 1088 | } |
| 1089 | |
| 1090 | function startReply(target: ReplyReference): void { |
| 1091 | if (editing) cancelEdit(); |
| 1092 | replyingTo = target; |
| 1093 | composerRef?.focus(); |
| 1094 | } |
| 1095 | |
| 1096 | let pinnedOpenFor: string | null = null; |
| 1097 | let pinnedCloseVersion = 0; |
| 1098 | let pinsExpanded = false; |
| 1099 | let pinPreview: TimelineEvent | null = null; |
| 1100 | let pinJumpBusy = false; |
| 1101 | $: syncPinned(selectedRoom?.room_id ?? null, (selectedRoom?.pinned_events.length ?? 0) > 0, $selectedRoomId ? $pinnedTimelineVersions[$selectedRoomId] ?? 0 : 0); |
| 1102 | function syncPinned(roomId: string | null, hasPins: boolean, version: number): void { |
| 1103 | const want = hasPins ? roomId : null; |
| 1104 | if (want === pinnedOpenFor && version === pinnedCloseVersion) return; |
| 1105 | if (pinnedOpenFor) runCommand({ op: 'close_pinned', room_id: pinnedOpenFor }).catch(() => undefined); |
| 1106 | pinnedOpenFor = want; |
| 1107 | pinnedCloseVersion = version; |
| 1108 | pinsExpanded = false; |
| 1109 | if (want) runCommand({ op: 'open_pinned', room_id: want }).catch(() => undefined); |
| 1110 | } |
| 1111 | |
| 1112 | $: pins = pinnedList(selectedRoom, $pinnedTimelines); |
| 1113 | function pinnedList(room: RoomSummary | null, all: Record<string, TimelineItem[]>): TimelineEvent[] { |
| 1114 | if (!room || !room.pinned_events.length) return []; |
| 1115 | const order = new Map(room.pinned_events.map((id, i) => [id, i])); |
| 1116 | return (all[room.room_id] ?? []) |
| 1117 | .flatMap((item) => (item.kind === 'event' && item.event.event_id && order.has(item.event.event_id) ? [item.event] : [])) |
| 1118 | .sort((a, b) => (order.get(b.event_id!) ?? 0) - (order.get(a.event_id!) ?? 0)); |
| 1119 | } |
| 1120 | |
| 1121 | function setPinned(eventId: string, pinned: boolean): void { |
| 1122 | const roomId = $selectedRoomId; |
| 1123 | if (!roomId) return; |
| 1124 | runCommand({ op: 'set_pinned', room_id: roomId, event_id: eventId, pinned }).catch((e) => |
| 1125 | pushBanner(e instanceof Error ? e.message : 'Could not change the pin') |
| 1126 | ); |
| 1127 | } |
| 1128 | |
| 1129 | async function jumpToPin(eventId: string): Promise<void> { |
| 1130 | const roomId = $selectedRoomId; |
| 1131 | if (!roomId || !eventId || pinJumpBusy) return; |
| 1132 | pinsExpanded = false; |
| 1133 | const pinned = pins.find((event) => event.event_id === eventId) ?? null; |
| 1134 | if (pinned?.thread_root) { |
| 1135 | openThreadHere(pinned.thread_root, eventId); |
| 1136 | return; |
| 1137 | } |
| 1138 | pinPreview = pinned; |
| 1139 | pinJumpBusy = true; |
| 1140 | try { |
| 1141 | for (let attempt = 0; attempt < 24; attempt += 1) { |
| 1142 | if (($timelines[roomId] ?? []).some((item) => item.kind === 'event' && item.event.event_id === eventId)) { |
| 1143 | pinPreview = null; |
| 1144 | await tick(); |
| 1145 | jumpTo(eventId); |
| 1146 | return; |
| 1147 | } |
| 1148 | await paginateRoom(roomId); |
| 1149 | await new Promise((resolve) => window.setTimeout(resolve, 180)); |
| 1150 | } |
| 1151 | pushBanner('Could not load that pinned message'); |
| 1152 | } catch (e) { |
| 1153 | pushBanner(e instanceof Error ? e.message : 'Could not load that pinned message'); |
| 1154 | } finally { |
| 1155 | pinJumpBusy = false; |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | function jumpTo(eventId: string): void { |
| 1160 | const el = timelineEl?.querySelector<HTMLElement>(`[data-event="${CSS.escape(eventId)}"]`); |
| 1161 | const root = !el && $selectedRoomId ? threadHolding($selectedRoomId, eventId) : null; |
| 1162 | if (root) { |
| 1163 | openThreadHere(root, eventId); |
| 1164 | return; |
| 1165 | } |
| 1166 | if (!el) { |
| 1167 | pushBanner('The original message is not loaded. Scroll up to load older messages.'); |
| 1168 | return; |
| 1169 | } |
| 1170 | stickToBottom = false; |
| 1171 | timelineViewport?.releaseScroll(); |
| 1172 | el.scrollIntoView({ block: 'center', behavior: 'smooth' }); |
| 1173 | el.classList.remove('flash'); |
| 1174 | void el.offsetWidth; |
| 1175 | el.classList.add('flash'); |
| 1176 | } |
| 1177 | |
| 1178 | let typedText = ''; |
| 1179 | let typedRoom: string | null = null; |
| 1180 | $: trackTypingInput(composer, $selectedRoomId, openReady); |
| 1181 | function trackTypingInput(text: string, roomId: string | null, ready: Record<string, boolean>): void { |
| 1182 | const edited = roomId === typedRoom && text !== typedText; |
| 1183 | typedText = text; |
| 1184 | typedRoom = roomId; |
| 1185 | if (!roomId || !ready[roomId] || !text.trim()) { |
| 1186 | stopTyping(); |
| 1187 | } else if (edited && roomId !== peeking) { |
| 1188 | notifyTyping(roomId); |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | $: void trackPending($selectedRoomId, pendingItems); |
| 1193 | async function trackPending(roomId: string | null, list: PendingMessage[]): Promise<void> { |
| 1194 | if (!roomId) return; |
| 1195 | if (roomId !== $selectedRoomId) return; |
| 1196 | await tick(); |
| 1197 | if (roomId !== $selectedRoomId || timelineViewport?.roomId !== roomId) return; |
| 1198 | if (stickToBottom) timelineViewport.scrollToBottom(true); |
| 1199 | else timelineViewport.restore(); |
| 1200 | } |
| 1201 | |
| 1202 | async function react(eventId: string, key: string, shortcode?: string): Promise<void> { |
| 1203 | const roomId = $selectedRoomId; |
| 1204 | if (!roomId || !eventId || reacting) return; |
| 1205 | reacting = true; |
| 1206 | try { |
| 1207 | await reactToMessage(roomId, eventId, key, reactionShortcode(key, shortcode, allPacks($imagePacks))); |
| 1208 | } catch (e) { |
| 1209 | pushBanner(e instanceof Error ? e.message : 'Reaction failed'); |
| 1210 | } finally { |
| 1211 | reacting = false; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | function previewLoader(roomId: string): (url: string) => void { |
| 1216 | return (url) => requestLinkPreview(roomId, url); |
| 1217 | } |
| 1218 | |
| 1219 | async function changeEncryptedPreviews(enabled: boolean): Promise<void> { |
| 1220 | try { |
| 1221 | await saveUrlPreviewSettings({ encrypted_rooms: enabled }); |
| 1222 | } catch (e) { |
| 1223 | pushBanner(e instanceof Error ? e.message : 'Could not save link preview setting'); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | async function changeQuickReactions(list: QuickReaction[]): Promise<void> { |
| 1228 | try { |
| 1229 | await saveQuickReactions(list); |
| 1230 | } catch (e) { |
| 1231 | pushBanner(e instanceof Error ? e.message : 'Could not save quick reactions'); |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | async function paginate(): Promise<void> { |
| 1236 | const roomId = $selectedRoomId; |
| 1237 | if (!roomId || paginateBusy || $recentHistory[roomId] === 'Loading') return; |
| 1238 | paginateBusy = true; |
| 1239 | try { |
| 1240 | await paginateRoom(roomId); |
| 1241 | } catch (e) { |
| 1242 | pushBanner(e instanceof Error ? e.message : 'Loading older messages failed'); |
| 1243 | } finally { |
| 1244 | paginateBusy = false; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | async function fillGap(gapId: string): Promise<void> { |
| 1249 | const roomId = $selectedRoomId; |
| 1250 | if (!roomId || fillingGaps[roomId]) return; |
| 1251 | fillingGaps = { ...fillingGaps, [roomId]: gapId }; |
| 1252 | try { |
| 1253 | await fillHistoryGap(roomId, gapId); |
| 1254 | } catch (e) { |
| 1255 | pushBanner(e instanceof Error ? e.message : 'Loading the missing history failed'); |
| 1256 | } finally { |
| 1257 | if (fillingGaps[roomId] === gapId) { |
| 1258 | const { [roomId]: _done, ...rest } = fillingGaps; |
| 1259 | fillingGaps = rest; |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | async function retryRecentHistory(roomId: string): Promise<void> { |
| 1265 | if (recentRetrying[roomId]) return; |
| 1266 | recentRetrying = { ...recentRetrying, [roomId]: true }; |
| 1267 | try { |
| 1268 | await startRecentHistory(roomId); |
| 1269 | } catch (e) { |
| 1270 | pushBanner(e instanceof Error ? e.message : 'Loading recent history failed'); |
| 1271 | } finally { |
| 1272 | const { [roomId]: _done, ...rest } = recentRetrying; |
| 1273 | recentRetrying = rest; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | async function loadMembers(roomId: string): Promise<void> { |
| 1278 | if (membersFor === roomId && $membersLoading) return; |
| 1279 | membersFor = roomId; |
| 1280 | membersLoading.set(true); |
| 1281 | try { |
| 1282 | const res = await getMembers(roomId); |
| 1283 | membersByRoom.update((all) => ({ ...all, [roomId]: res.members })); |
| 1284 | avatarByUser = { ...avatarByUser, ...avatarMap(res.members) }; |
| 1285 | } catch (e) { |
| 1286 | pushBanner(e instanceof Error ? e.message : 'Could not load members'); |
| 1287 | } finally { |
| 1288 | if (membersFor === roomId) membersLoading.set(false); |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | function avatarMap(list: MemberSummary[]): Record<string, string | null> { |
| 1293 | const next: Record<string, string | null> = {}; |
| 1294 | for (const member of list) next[member.user_id] = member.avatar; |
| 1295 | return next; |
| 1296 | } |
| 1297 | |
| 1298 | function peopleIn(list: TimelineItem[], roster: MemberSummary[]): Record<string, Person> { |
| 1299 | const out: Record<string, Person> = {}; |
| 1300 | for (const item of list) { |
| 1301 | if (item.kind !== 'event') continue; |
| 1302 | const s = item.event.sender; |
| 1303 | out[s.user_id] = { user_id: s.user_id, name: senderLabel(s), avatar: s.avatar }; |
| 1304 | } |
| 1305 | for (const m of roster) out[m.user_id] = { user_id: m.user_id, name: m.name, avatar: m.avatar }; |
| 1306 | return out; |
| 1307 | } |
| 1308 | |
| 1309 | function senderAvatarFor(userId: string): string | null { |
| 1310 | return avatarByUser[userId] ?? null; |
| 1311 | } |
| 1312 | |
| 1313 | $: threadView = $openThread && $openThread.room_id === $selectedRoomId ? $openThread : null; |
| 1314 | $: if ($openThread && $openThread.room_id !== $selectedRoomId) void showThread(null); |
| 1315 | let threadFolds: Record<string, boolean> = {}; |
| 1316 | const BOTH_PANES_MIN_WIDTH = 1300; |
| 1317 | let viewportWidth = typeof window === 'undefined' ? BOTH_PANES_MIN_WIDTH : window.innerWidth; |
| 1318 | let rightFront: 'thread' | 'members' = 'members'; |
| 1319 | $: bothPanesFit = viewportWidth >= BOTH_PANES_MIN_WIDTH; |
| 1320 | $: threadShown = !!threadView && (bothPanesFit || !membersOpen || rightFront === 'thread'); |
| 1321 | $: membersShown = !!selectedRoom && membersOpen && (bothPanesFit || !threadView || rightFront === 'members'); |
| 1322 | |
| 1323 | function openThreadHere(rootEventId: string, focusEventId?: string): void { |
| 1324 | if (!$selectedRoomId) return; |
| 1325 | rightFront = 'thread'; |
| 1326 | void showThread({ room_id: $selectedRoomId, root_event_id: rootEventId, focus_event_id: focusEventId }); |
| 1327 | } |
| 1328 | |
| 1329 | async function openLive(roomId: string, eventId: string, threadRoot: string | null): Promise<void> { |
| 1330 | await selectRoom(roomId); |
| 1331 | if ($selectedRoomId !== roomId) return; |
| 1332 | if (threadRoot) { |
| 1333 | openThreadHere(threadRoot, eventId); |
| 1334 | return; |
| 1335 | } |
| 1336 | await tick(); |
| 1337 | if (timelineEl?.querySelector(`[data-event="${CSS.escape(eventId)}"]`)) jumpTo(eventId); |
| 1338 | } |
| 1339 | |
| 1340 | function threadHolding(roomId: string, eventId: string): string | null { |
| 1341 | for (const [key, list] of Object.entries($threadTimelines)) { |
| 1342 | const [room, root] = key.split('\u0000'); |
| 1343 | if (room === roomId && list.some((item) => item.kind === 'event' && item.event.event_id === eventId)) return root; |
| 1344 | } |
| 1345 | return null; |
| 1346 | } |
| 1347 | |
| 1348 | async function openThreadIn(roomId: string, rootEventId: string): Promise<void> { |
| 1349 | if ($selectedRoomId !== roomId) await selectRoom(roomId); |
| 1350 | if ($selectedRoomId === roomId) openThreadHere(rootEventId); |
| 1351 | } |
| 1352 | |
| 1353 | function threadFoldOpen(roomId: string, folds: Record<string, boolean>, q: string): boolean { |
| 1354 | if (q) return ($threadsByRoom[roomId] ?? []).some((t) => threadMatches(t, q)); |
| 1355 | return !!folds[roomId]; |
| 1356 | } |
| 1357 | |
| 1358 | function toggleMembers(): void { |
| 1359 | if (membersShown) { |
| 1360 | membersOpen = false; |
| 1361 | } else { |
| 1362 | membersOpen = true; |
| 1363 | rightFront = 'members'; |
| 1364 | } |
| 1365 | if (membersOpen && $selectedRoomId) { |
| 1366 | void loadMembers($selectedRoomId); |
| 1367 | void loadLevels($selectedRoomId); |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | async function join(target: string): Promise<void> { |
| 1372 | const room = target.trim(); |
| 1373 | if (!room || joinBusy) return; |
| 1374 | joinBusy = true; |
| 1375 | try { |
| 1376 | const res = await joinRoom(room); |
| 1377 | joinTarget = ''; |
| 1378 | dialog = null; |
| 1379 | await refreshRooms(); |
| 1380 | await selectRoom(res.room_id); |
| 1381 | } catch (e) { |
| 1382 | pushBanner(e instanceof Error ? e.message : 'Join failed'); |
| 1383 | } finally { |
| 1384 | joinBusy = false; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | async function create(): Promise<void> { |
| 1389 | const name = createName.trim(); |
| 1390 | if (!name || createBusy) return; |
| 1391 | createBusy = true; |
| 1392 | try { |
| 1393 | const res = await createRoom(name, createTopic.trim() || undefined); |
| 1394 | createName = ''; |
| 1395 | createTopic = ''; |
| 1396 | dialog = null; |
| 1397 | await refreshRooms(); |
| 1398 | await selectRoom(res.room_id); |
| 1399 | } catch (e) { |
| 1400 | pushBanner(e instanceof Error ? e.message : 'Create room failed'); |
| 1401 | } finally { |
| 1402 | createBusy = false; |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | async function leave(roomId: string | null = $selectedRoomId): Promise<void> { |
| 1407 | if (!roomId || leaveBusy) return; |
| 1408 | leaveBusy = true; |
| 1409 | stopTyping(); |
| 1410 | try { |
| 1411 | await leaveRoom(roomId); |
| 1412 | if ($selectedRoomId === roomId) selectedRoomId.set(null); |
| 1413 | if (warmRooms.includes(roomId)) { |
| 1414 | forgetOpenRoom(roomId); |
| 1415 | closeRoom(roomId).catch(() => undefined); |
| 1416 | } |
| 1417 | await refreshRooms(); |
| 1418 | } catch (e) { |
| 1419 | pushBanner(e instanceof Error ? e.message : 'Leave failed'); |
| 1420 | } finally { |
| 1421 | leaveBusy = false; |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | function connectionClass(state: string): string { |
| 1426 | if (state === 'online') return 'dot-online'; |
| 1427 | if (state === 'connecting' || state === 'reconnecting') return 'dot-busy'; |
| 1428 | return 'dot-off'; |
| 1429 | } |
| 1430 | |
| 1431 | let dragSpaceId: string | null = null; |
| 1432 | let dropTarget: { id: string; after: boolean } | null = null; |
| 1433 | let menu: { items: MenuItem[]; x: number; y: number; above?: boolean } | null = null; |
| 1434 | let userCard: { userId: string; x: number; y: number; confirm: 'kick' | 'ban' | null } | null = null; |
| 1435 | let levelsByRoom: Record<string, PowerLevels | null> = {}; |
| 1436 | let peeking: string | null = null; |
| 1437 | |
| 1438 | $: roomLevels = $selectedRoomId ? (levelsByRoom[$selectedRoomId] ?? null) : null; |
| 1439 | |
| 1440 | function personFor(userId: string): Person { |
| 1441 | return people[userId] ?? { user_id: userId, name: userId, avatar: avatarByUser[userId] ?? null }; |
| 1442 | } |
| 1443 | |
| 1444 | function memberFor(userId: string): MemberSummary | null { |
| 1445 | return members.find((m) => m.user_id === userId) ?? null; |
| 1446 | } |
| 1447 | |
| 1448 | async function loadLevels(roomId: string): Promise<void> { |
| 1449 | try { |
| 1450 | const levels = parsePowerLevels(await runCommand({ op: 'power_levels', room_id: roomId })); |
| 1451 | levelsByRoom = { ...levelsByRoom, [roomId]: levels }; |
| 1452 | } catch { |
| 1453 | levelsByRoom = { ...levelsByRoom, [roomId]: levelsByRoom[roomId] ?? null }; |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | async function openUser(userId: string, x: number, y: number, asMenu: boolean): Promise<void> { |
| 1458 | const roomId = $selectedRoomId; |
| 1459 | if (roomId && !(roomId in levelsByRoom)) await loadLevels(roomId); |
| 1460 | else if (roomId) void loadLevels(roomId); |
| 1461 | if (asMenu) menu = { items: userMenuItems(userId, x, y), x, y }; |
| 1462 | else userCard = { userId, x, y, confirm: null }; |
| 1463 | } |
| 1464 | |
| 1465 | function copyText(text: string): void { |
| 1466 | navigator.clipboard.writeText(text).catch(() => pushBanner('Could not copy to the clipboard')); |
| 1467 | } |
| 1468 | |
| 1469 | function userMenuItems(userId: string, x: number, y: number): MenuItem[] { |
| 1470 | const own = userId === $sessionUser; |
| 1471 | const member = memberFor(userId); |
| 1472 | const items: MenuItem[] = []; |
| 1473 | if (!own) items.push({ label: 'Message', action: () => void userAction(userId, { kind: 'message' }) }); |
| 1474 | items.push({ label: 'Mention', action: () => void userAction(userId, { kind: 'mention' }) }); |
| 1475 | items.push({ label: 'Copy user ID', action: () => copyText(userId) }); |
| 1476 | const firstModeration = items.length; |
| 1477 | if (roomLevels && $sessionUser) { |
| 1478 | const can = allowed(roomLevels, $sessionUser, userId); |
| 1479 | const banned = member?.membership === 'Ban'; |
| 1480 | if (can.setLevel && !own) { |
| 1481 | const muted = isMuted(roomLevels, userId); |
| 1482 | items.push({ label: muted ? 'Unmute' : 'Mute', action: () => void userAction(userId, { kind: muted ? 'unmute' : 'mute' }) }); |
| 1483 | } |
| 1484 | if (can.kick && !banned) items.push({ label: 'Kick…', danger: true, action: () => (userCard = { userId, x, y, confirm: 'kick' }) }); |
| 1485 | if (can.ban && banned) items.push({ label: 'Unban', action: () => void userAction(userId, { kind: 'unban' }) }); |
| 1486 | if (can.ban && !banned) items.push({ label: 'Ban…', danger: true, action: () => (userCard = { userId, x, y, confirm: 'ban' }) }); |
| 1487 | if (can.setLevel) items.push({ label: 'Power level…', action: () => (userCard = { userId, x, y, confirm: null }) }); |
| 1488 | } |
| 1489 | if (items[firstModeration]) items[firstModeration] = { ...items[firstModeration], divider: true }; |
| 1490 | if (!own) { |
| 1491 | const kind = member?.ignored ? 'unignore' : 'ignore'; |
| 1492 | items.push({ label: member?.ignored ? 'Unignore' : 'Ignore', divider: true, action: () => void userAction(userId, { kind }) }); |
| 1493 | } |
| 1494 | return items; |
| 1495 | } |
| 1496 | |
| 1497 | async function insertMention(person: Person): Promise<void> { |
| 1498 | const roomId = $selectedRoomId; |
| 1499 | if (!roomId) return; |
| 1500 | const lead = composer && !/\s$/.test(composer) ? ' ' : ''; |
| 1501 | composer = `${composer}${lead}${person.name} `; |
| 1502 | pickedMentions = { |
| 1503 | ...pickedMentions, |
| 1504 | [roomId]: [...(pickedMentions[roomId] ?? []), { user_id: person.user_id, text: person.name }] |
| 1505 | }; |
| 1506 | await composerRef?.focusEnd(); |
| 1507 | } |
| 1508 | |
| 1509 | async function userAction(userId: string, action: UserAction): Promise<void> { |
| 1510 | const roomId = $selectedRoomId; |
| 1511 | try { |
| 1512 | switch (action.kind) { |
| 1513 | case 'message': { |
| 1514 | const res = (await runCommand({ op: 'direct', user_id: userId })) as { room_id: string }; |
| 1515 | await refreshRooms(); |
| 1516 | await selectRoom(res.room_id); |
| 1517 | return; |
| 1518 | } |
| 1519 | case 'mention': |
| 1520 | await insertMention(personFor(userId)); |
| 1521 | return; |
| 1522 | case 'ignore': |
| 1523 | case 'unignore': |
| 1524 | await runCommand({ op: action.kind, user_id: userId }); |
| 1525 | if (roomId) void loadMembers(roomId); |
| 1526 | return; |
| 1527 | } |
| 1528 | if (!roomId) return; |
| 1529 | switch (action.kind) { |
| 1530 | case 'kick': |
| 1531 | case 'ban': |
| 1532 | await runCommand({ op: action.kind, room_id: roomId, user_id: userId, reason: action.reason }); |
| 1533 | break; |
| 1534 | case 'unban': |
| 1535 | await runCommand({ op: 'unban', room_id: roomId, user_id: userId, reason: null }); |
| 1536 | break; |
| 1537 | case 'mute': |
| 1538 | case 'unmute': |
| 1539 | await runCommand({ op: 'mute', room_id: roomId, user_id: userId, muted: action.kind === 'mute' }); |
| 1540 | break; |
| 1541 | case 'power': |
| 1542 | await runCommand({ op: 'set_power_level', room_id: roomId, user_id: userId, level: action.level }); |
| 1543 | break; |
| 1544 | } |
| 1545 | void loadLevels(roomId); |
| 1546 | void loadMembers(roomId); |
| 1547 | } catch (e) { |
| 1548 | pushBanner(e instanceof Error ? e.message : 'That action failed'); |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | function roomMenuItems(room: RoomSummary): MenuItem[] { |
| 1553 | const items: MenuItem[] = room.space |
| 1554 | ? [{ label: 'Open', action: () => void selectSpace(room.room_id) }] |
| 1555 | : [ |
| 1556 | { label: 'Open', action: () => void selectRoom(room.room_id) }, |
| 1557 | { label: 'Peek', action: () => void selectRoom(room.room_id, true) } |
| 1558 | ]; |
| 1559 | items.push({ label: room.favourite ? 'Unpin' : room.space ? 'Pin to top' : 'Pin', action: () => void togglePin(room) }); |
| 1560 | items.push({ label: 'Copy link', action: () => copyText(`https://matrix.to/#/${room.canonical_alias ?? room.room_id}`) }); |
| 1561 | items.push({ label: 'Copy room ID', action: () => copyText(room.room_id) }); |
| 1562 | if (room.membership === 'Joined') items.push({ label: 'Leave', danger: true, divider: true, action: () => void leave(room.room_id) }); |
| 1563 | return items; |
| 1564 | } |
| 1565 | |
| 1566 | function openRoomMenu(ev: MouseEvent, room: RoomSummary): void { |
| 1567 | menu = { items: roomMenuItems(room), x: ev.clientX, y: ev.clientY }; |
| 1568 | } |
| 1569 | |
| 1570 | function roomName(roomId: string): string { |
| 1571 | return $rooms.find((r) => r.room_id === roomId)?.name ?? roomId; |
| 1572 | } |
| 1573 | |
| 1574 | function roomStickers(roomId: string): StickerHandlers { |
| 1575 | return { |
| 1576 | onSend: (pack, image) => void sendSticker(roomId, pack, image), |
| 1577 | onClone: (pack, image, x, y) => openCloneImageMenu(pack, image, x, y), |
| 1578 | onClonePack: (pack, x, y) => openClonePackMenu(pack, x, y), |
| 1579 | onManage: () => (dialog = 'packs'), |
| 1580 | roomName |
| 1581 | }; |
| 1582 | } |
| 1583 | |
| 1584 | async function sendSticker(roomId: string, pack: ImagePack, image: PackImage): Promise<void> { |
| 1585 | stickToBottom = true; |
| 1586 | try { |
| 1587 | await runCommand({ op: 'send_sticker', room_id: roomId, pack_id: pack.id, shortcode: image.shortcode }); |
| 1588 | if (peeking === roomId) stopPeeking(); |
| 1589 | } catch (e) { |
| 1590 | pushBanner(e instanceof Error ? e.message : 'Could not send the sticker'); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | async function runClone(request: CommandRequest, failure: string): Promise<void> { |
| 1595 | try { |
| 1596 | const res = (await runCommand(request)) as { skipped?: string[] } | undefined; |
| 1597 | if (res?.skipped?.length) pushBanner(`Couldn't copy ${res.skipped.map((s) => `:${s}:`).join(', ')}`); |
| 1598 | } catch (e) { |
| 1599 | pushBanner(e instanceof Error ? e.message : failure); |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | function openCloneImageMenu(pack: ImagePack, image: PackImage, x: number, y: number): void { |
| 1604 | menu = null; |
| 1605 | cloneSource = { kind: 'image', pack, image }; |
| 1606 | } |
| 1607 | |
| 1608 | function openClonePackMenu(pack: ImagePack, x: number, y: number): void { |
| 1609 | menu = null; |
| 1610 | cloneSource = { kind: 'pack', pack }; |
| 1611 | } |
| 1612 | |
| 1613 | function openCloneStickerMenu(eventId: string, body: string, x: number, y: number): void { |
| 1614 | const roomId = $selectedRoomId; |
| 1615 | if (!roomId) return; |
| 1616 | menu = null; |
| 1617 | cloneSource = { kind: 'sticker', room_id: roomId, event_id: eventId, body }; |
| 1618 | } |
| 1619 | |
| 1620 | async function openMessageMenu(event: TimelineEvent, x: number, y: number): Promise<void> { |
| 1621 | const roomId = $selectedRoomId; |
| 1622 | const eventId = event.event_id; |
| 1623 | if (!roomId || !eventId) return; |
| 1624 | if (!(roomId in levelsByRoom)) await loadLevels(roomId); |
| 1625 | const joined = selectedRoom?.membership === 'Joined'; |
| 1626 | const content = event.content; |
| 1627 | const items: MenuItem[] = []; |
| 1628 | if (joined) { |
| 1629 | items.push({ |
| 1630 | label: 'Reply', |
| 1631 | action: () => |
| 1632 | startReply({ |
| 1633 | event_id: eventId, |
| 1634 | details: { kind: 'Ready', sender: event.sender, content, timestamp_ms: event.timestamp_ms } |
| 1635 | }) |
| 1636 | }); |
| 1637 | } |
| 1638 | if (joined && event.own && event.editable && content.kind === 'Message' && content.message.kind === 'Text') { |
| 1639 | const body = content.message.body; |
| 1640 | items.push({ label: 'Edit', action: () => startEdit(eventId, body) }); |
| 1641 | } |
| 1642 | if (content.kind === 'Message' && content.message.body) { |
| 1643 | const body = content.message.body; |
| 1644 | items.push({ label: 'Copy text', action: () => copyText(body) }); |
| 1645 | } |
| 1646 | items.push({ label: 'Copy link', action: () => copyText(`https://matrix.to/#/${roomId}/${eventId}`) }); |
| 1647 | if (joined && selectedRoom?.can_pin && content.kind !== 'Redacted') { |
| 1648 | const pinned = selectedRoom.pinned_events.includes(eventId); |
| 1649 | items.push({ label: pinned ? 'Unpin' : 'Pin', action: () => setPinned(eventId, !pinned) }); |
| 1650 | } |
| 1651 | if (content.kind === 'Sticker') { |
| 1652 | const body = content.body; |
| 1653 | items.push({ label: 'Clone sticker…', action: () => openCloneStickerMenu(eventId, body, x, y) }); |
| 1654 | } |
| 1655 | const me = $sessionUser; |
| 1656 | if (joined && me && roomLevels && canRedact(roomLevels, me, event.sender.user_id) && content.kind !== 'Redacted') { |
| 1657 | items.push({ |
| 1658 | label: 'Delete message…', |
| 1659 | danger: true, |
| 1660 | action: () => |
| 1661 | (menu = { |
| 1662 | x, |
| 1663 | y, |
| 1664 | items: [ |
| 1665 | { label: 'Delete', danger: true, action: () => void runClone({ op: 'redact', room_id: roomId, event_id: eventId, reason: null }, 'Could not delete the message') }, |
| 1666 | { label: 'Cancel', action: () => undefined } |
| 1667 | ] |
| 1668 | }) |
| 1669 | }); |
| 1670 | } |
| 1671 | if (!event.own) { |
| 1672 | const person = userMenuItems(event.sender.user_id, x, y); |
| 1673 | if (person[0]) person[0] = { ...person[0], divider: true }; |
| 1674 | items.push(...person); |
| 1675 | } |
| 1676 | menu = { items, x, y }; |
| 1677 | } |
| 1678 | |
| 1679 | function openAccountMenu(ev: MouseEvent): void { |
| 1680 | const rect = (ev.currentTarget as HTMLElement).getBoundingClientRect(); |
| 1681 | menu = { |
| 1682 | x: rect.left, |
| 1683 | y: rect.top - 6, |
| 1684 | above: true, |
| 1685 | items: [ |
| 1686 | { label: 'Security', action: () => (dialog = 'security') }, |
| 1687 | { label: 'Settings', action: () => (dialog = 'settings') }, |
| 1688 | { label: 'Sticker and emoji packs', action: () => (dialog = 'packs') }, |
| 1689 | { label: 'Log out', danger: true, divider: true, action: () => void doLogout() } |
| 1690 | ] |
| 1691 | }; |
| 1692 | } |
| 1693 | |
| 1694 | let resizing = false; |
| 1695 | |
| 1696 | function startResize(ev: PointerEvent, pane: 'side' | 'members' | 'thread'): void { |
| 1697 | if (ev.button !== 0) return; |
| 1698 | ev.preventDefault(); |
| 1699 | const handle = ev.currentTarget as HTMLElement; |
| 1700 | handle.setPointerCapture(ev.pointerId); |
| 1701 | const store = pane === 'side' ? sideWidth : pane === 'thread' ? threadWidth : membersWidth; |
| 1702 | const range = pane === 'side' ? SIDE_WIDTH : pane === 'thread' ? THREAD_WIDTH : MEMBERS_WIDTH; |
| 1703 | const startX = ev.clientX; |
| 1704 | const startWidth = pane === 'side' ? $sideWidth : pane === 'thread' ? $threadWidth : $membersWidth; |
| 1705 | resizing = true; |
| 1706 | const move = (e: PointerEvent) => { |
| 1707 | const delta = pane === 'side' ? e.clientX - startX : startX - e.clientX; |
| 1708 | store.set(Math.round(Math.min(range.max, Math.max(range.min, startWidth + delta)))); |
| 1709 | }; |
| 1710 | const end = () => { |
| 1711 | resizing = false; |
| 1712 | handle.removeEventListener('pointermove', move); |
| 1713 | handle.removeEventListener('pointerup', end); |
| 1714 | handle.removeEventListener('pointercancel', end); |
| 1715 | }; |
| 1716 | handle.addEventListener('pointermove', move); |
| 1717 | handle.addEventListener('pointerup', end); |
| 1718 | handle.addEventListener('pointercancel', end); |
| 1719 | } |
| 1720 | |
| 1721 | function resetWidth(pane: 'side' | 'members' | 'thread'): void { |
| 1722 | if (pane === 'side') sideWidth.set(SIDE_WIDTH.default); |
| 1723 | else if (pane === 'thread') threadWidth.set(THREAD_WIDTH.default); |
| 1724 | else membersWidth.set(MEMBERS_WIDTH.default); |
| 1725 | } |
| 1726 | |
| 1727 | function stopPeeking(): void { |
| 1728 | peeking = null; |
| 1729 | queueReadReceipt(); |
| 1730 | } |
| 1731 | |
| 1732 | async function togglePin(room: RoomSummary): Promise<void> { |
| 1733 | try { |
| 1734 | await runCommand({ op: 'set_favourite', room_id: room.room_id, favourite: !room.favourite }); |
| 1735 | } catch (e) { |
| 1736 | pushBanner(e instanceof Error ? e.message : 'Could not change the pin'); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | function startRailDrag(ev: DragEvent, id: string): void { |
| 1741 | dragSpaceId = id; |
| 1742 | if (ev.dataTransfer) { |
| 1743 | ev.dataTransfer.effectAllowed = 'move'; |
| 1744 | ev.dataTransfer.setData('text/plain', id); |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | function overRailSpace(ev: DragEvent, space: RoomSummary): void { |
| 1749 | const dragged = orderedRail.find((s) => s.room_id === dragSpaceId); |
| 1750 | if (!dragged || dragged.room_id === space.room_id || dragged.favourite !== space.favourite) return; |
| 1751 | ev.preventDefault(); |
| 1752 | const rect = (ev.currentTarget as HTMLElement).getBoundingClientRect(); |
| 1753 | dropTarget = { id: space.room_id, after: ev.clientY > rect.top + rect.height / 2 }; |
| 1754 | } |
| 1755 | |
| 1756 | async function dropRailSpace(): Promise<void> { |
| 1757 | const moved = dragSpaceId; |
| 1758 | const target = dropTarget; |
| 1759 | dragSpaceId = null; |
| 1760 | dropTarget = null; |
| 1761 | if (!moved || !target) return; |
| 1762 | const ids = orderedRail.map((s) => s.room_id); |
| 1763 | const before = target.after ? (ids[ids.indexOf(target.id) + 1] ?? null) : target.id; |
| 1764 | const order = moveBefore(ids, moved, before === moved ? null : before); |
| 1765 | if (order.join() === ids.join()) return; |
| 1766 | railOverride = order; |
| 1767 | try { |
| 1768 | await runCommand({ op: 'reorder_spaces', order }); |
| 1769 | } catch (e) { |
| 1770 | railOverride = null; |
| 1771 | pushBanner(e instanceof Error ? e.message : 'Could not reorder spaces'); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | let roomMenuOpen = false; |
| 1776 | let roomMenuEl: HTMLDivElement | null = null; |
| 1777 | |
| 1778 | function roomMenuAction(action: () => void): void { |
| 1779 | roomMenuOpen = false; |
| 1780 | action(); |
| 1781 | } |
| 1782 | |
| 1783 | function closeRoomMenuOutside(ev: PointerEvent): void { |
| 1784 | if (roomMenuOpen && !roomMenuEl?.contains(ev.target as Node)) roomMenuOpen = false; |
| 1785 | } |
| 1786 | |
| 1787 | function onKeydown(ev: KeyboardEvent): void { |
| 1788 | if (ev.key === 'Escape') { |
| 1789 | if (roomMenuOpen) roomMenuOpen = false; |
| 1790 | else if (dialog) dialog = null; |
| 1791 | else if (membersShown && window.innerWidth < 1100) membersOpen = false; |
| 1792 | else if (threadShown && window.innerWidth < 1100) void showThread(null); |
| 1793 | else if (sidebarOpen) sidebarOpen = false; |
| 1794 | } |
| 1795 | } |
| 1796 | </script> |
| 1797 | |
| 1798 | <svelte:window |
| 1799 | bind:innerWidth={viewportWidth} |
| 1800 | on:keydown={onKeydown} |
| 1801 | on:pointerdown={closeRoomMenuOutside} |
| 1802 | /> |
| 1803 | |
| 1804 | {#if !booted} |
| 1805 | <div class="splash" role="status" aria-label="Loading Malice" out:fade={{ duration: motionDuration(260) }}> |
| 1806 | <div class="splash-mark" aria-hidden="true">M</div> |
| 1807 | <p>Loading Malice…</p> |
| 1808 | </div> |
| 1809 | {:else if $blocked} |
| 1810 | <div class="splash" role="status" aria-label="Malice is open in another tab" in:fade={{ duration: motionDuration(220) }}> |
| 1811 | <div class="splash-mark" aria-hidden="true">M</div> |
| 1812 | <p>Malice is open in another tab. Close this tab or use that one instead.</p> |
| 1813 | </div> |
| 1814 | {:else if $sessionUser == null} |
| 1815 | <LoginPanel softLogout={$softLogout} on:done={(ev) => afterLogin(ev.detail)} /> |
| 1816 | {:else} |
| 1817 | <div |
| 1818 | class="app" |
| 1819 | in:fade={{ duration: motionDuration(220) }} |
| 1820 | class:nav-folded={$navFolded} |
| 1821 | class:rail-folded={$railFolded && selectedRoom} |
| 1822 | class:members-open={membersShown} |
| 1823 | class:thread-open={threadShown} |
| 1824 | class:resizing |
| 1825 | style:--side-open={`${$sideWidth}px`} |
| 1826 | style:--members-open={`${$membersWidth}px`} |
| 1827 | style:--thread-open={`${$threadWidth}px`} |
| 1828 | style:--msg-gap={`${$messageSpacing}px`} |
| 1829 | style:--msg-line-height={$lineHeight} |
| 1830 | > |
| 1831 | <header class="chat-head"> |
| 1832 | <button |
| 1833 | type="button" |
| 1834 | class="icon-btn only-mobile" |
| 1835 | aria-label="Open room list" |
| 1836 | on:click={() => (sidebarOpen = true)} |
| 1837 | > |
| 1838 | <span aria-hidden="true">☰</span> |
| 1839 | </button> |
| 1840 | <button |
| 1841 | type="button" |
| 1842 | class="icon-btn only-desktop pane-toggle" |
| 1843 | aria-pressed={!$railFolded} |
| 1844 | aria-label={$railFolded ? 'Show spaces' : 'Hide spaces'} |
| 1845 | title={$railFolded ? 'Show spaces' : 'Hide spaces'} |
| 1846 | on:click={() => railFolded.update((v) => !v)} |
| 1847 | > |
| 1848 | <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"> |
| 1849 | <rect x="3" y="4" width="18" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="2" /> |
| 1850 | <circle cx="7" cy="9" r="1.4" fill="currentColor" /> |
| 1851 | <circle cx="7" cy="13" r="1.4" fill="currentColor" /> |
| 1852 | <circle cx="7" cy="17" r="1.4" fill="currentColor" /> |
| 1853 | </svg> |
| 1854 | </button> |
| 1855 | <button |
| 1856 | type="button" |
| 1857 | class="icon-btn only-desktop pane-toggle" |
| 1858 | aria-pressed={!$navFolded} |
| 1859 | aria-label={$navFolded ? 'Show channels' : 'Hide channels'} |
| 1860 | title={$navFolded ? 'Show channels' : 'Hide channels'} |
| 1861 | on:click={toggleChannelsPane} |
| 1862 | > |
| 1863 | <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"> |
| 1864 | <rect x="3" y="4" width="18" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="2" /> |
| 1865 | <path d="M10 4v16" stroke="currentColor" stroke-width="2" /> |
| 1866 | </svg> |
| 1867 | </button> |
| 1868 | {#if selectedRoom} |
| 1869 | <div class="head-title"> |
| 1870 | <div class="head-room"> |
| 1871 | <MxcAvatar mxc={selectedRoom.avatar} label={selectedRoom.name} size={36} shape="rounded" /> |
| 1872 | <div class="head-room-text"> |
| 1873 | <h1><EmojiText text={selectedRoom.name} /></h1> |
| 1874 | <div class="head-meta"> |
| 1875 | {#if selectedRoom.space} |
| 1876 | <span class="pill">space</span> |
| 1877 | {/if} |
| 1878 | {#if selectedRoom.encrypted} |
| 1879 | <span class="pill" title="End-to-end encrypted"><EmojiText text="🔒 encrypted" /></span> |
| 1880 | {/if} |
| 1881 | {#if selectedRoom.direct} |
| 1882 | <span class="pill">direct</span> |
| 1883 | {/if} |
| 1884 | {#if $connection !== 'online'} |
| 1885 | <span class="conn" title={`Sync state: ${$connection}`}> |
| 1886 | <span class="dot {connectionClass($connection)}" aria-hidden="true"></span> |
| 1887 | {$connection} |
| 1888 | </span> |
| 1889 | {/if} |
| 1890 | </div> |
| 1891 | </div> |
| 1892 | </div> |
| 1893 | </div> |
| 1894 | {:else} |
| 1895 | <div class="head-title"> |
| 1896 | <div class="head-room"> |
| 1897 | {#if selectedSpace} |
| 1898 | <MxcAvatar mxc={selectedSpace.avatar} label={selectedSpace.name} size={36} shape="rounded" /> |
| 1899 | {/if} |
| 1900 | <div class="head-room-text"> |
| 1901 | <h1><EmojiText text={mentionsOpen ? 'Mentions' : searchOpen ? 'Search' : selectedSpace?.name ?? 'Home'} /></h1> |
| 1902 | </div> |
| 1903 | </div> |
| 1904 | </div> |
| 1905 | {/if} |
| 1906 | <div class="head-actions"> |
| 1907 | {#if selectedRoom} |
| 1908 | {#if peeking === selectedRoom.room_id} |
| 1909 | <button type="button" class="icon-btn" aria-pressed="true" aria-label="Stop peeking" title="Stop peeking" on:click={stopPeeking}> |
| 1910 | <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"> |
| 1911 | <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" /> |
| 1912 | <circle cx="12" cy="12" r="3" fill="currentColor" /> |
| 1913 | </svg> |
| 1914 | </button> |
| 1915 | {/if} |
| 1916 | {#if selectedRoom.membership !== 'Joined'} |
| 1917 | <button |
| 1918 | type="button" |
| 1919 | class="primary-btn" |
| 1920 | disabled={joinBusy} |
| 1921 | on:click={() => void join(selectedRoom.room_id)} |
| 1922 | > |
| 1923 | {joinBusy ? 'Joining…' : 'Join'} |
| 1924 | </button> |
| 1925 | {/if} |
| 1926 | <button type="button" class="icon-btn" aria-label="Search messages" title="Search messages" on:click={selectSearch}> |
| 1927 | <svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6" fill="none" stroke="currentColor" stroke-width="1.8" /><path d="M15 15l5 5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" /></svg> |
| 1928 | </button> |
| 1929 | <button |
| 1930 | type="button" |
| 1931 | class="icon-btn" |
| 1932 | aria-pressed={membersShown} |
| 1933 | aria-label={membersShown ? 'Hide members' : 'Show members'} |
| 1934 | title="Members" |
| 1935 | on:click={toggleMembers} |
| 1936 | > |
| 1937 | <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"> |
| 1938 | <circle cx="12" cy="8" r="4" fill="none" stroke="currentColor" stroke-width="2" /> |
| 1939 | <path d="M4 20c0-4 3.6-6 8-6s8 2 8 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" /> |
| 1940 | </svg> |
| 1941 | </button> |
| 1942 | <div class="room-menu-wrap" bind:this={roomMenuEl}> |
| 1943 | <button |
| 1944 | type="button" |
| 1945 | class="icon-btn" |
| 1946 | aria-haspopup="menu" |
| 1947 | aria-expanded={roomMenuOpen} |
| 1948 | aria-label="Room options" |
| 1949 | title="Room options" |
| 1950 | on:click={() => (roomMenuOpen = !roomMenuOpen)} |
| 1951 | > |
| 1952 | <span aria-hidden="true">⋯</span> |
| 1953 | </button> |
| 1954 | {#if roomMenuOpen} |
| 1955 | <div class="room-menu" role="menu"> |
| 1956 | {#if selectedRoom.membership === 'Joined'} |
| 1957 | <button |
| 1958 | type="button" |
| 1959 | role="menuitem" |
| 1960 | class="danger" |
| 1961 | disabled={leaveBusy} |
| 1962 | on:click={() => roomMenuAction(() => void leave())} |
| 1963 | > |
| 1964 | {leaveBusy ? 'Leaving…' : 'Leave room'} |
| 1965 | </button> |
| 1966 | {/if} |
| 1967 | </div> |
| 1968 | {/if} |
| 1969 | </div> |
| 1970 | {/if} |
| 1971 | </div> |
| 1972 | </header> |
| 1973 | |
| 1974 | <nav class="rail" aria-label="Servers and spaces"> |
| 1975 | <button |
| 1976 | type="button" |
| 1977 | class="rail-btn" |
| 1978 | class:active={selectedSpaceId === null} |
| 1979 | title="Home — all channels" |
| 1980 | aria-label="Home — all channels" |
| 1981 | aria-pressed={selectedSpaceId === null} |
| 1982 | on:click={() => void selectHome()} |
| 1983 | > |
| 1984 | <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> |
| 1985 | </button> |
| 1986 | {#each [pinnedRail, otherRail] as group} |
| 1987 | {#if group.length > 0} |
| 1988 | <div class="rail-sep" aria-hidden="true"></div> |
| 1989 | {/if} |
| 1990 | {#each group as space (space.room_id)} |
| 1991 | <button |
| 1992 | type="button" |
| 1993 | class="rail-btn rail-space" |
| 1994 | class:active={railSelected === space.room_id} |
| 1995 | class:drop-before={dropTarget?.id === space.room_id && !dropTarget.after} |
| 1996 | class:drop-after={dropTarget?.id === space.room_id && dropTarget.after} |
| 1997 | class:pinned={space.favourite} |
| 1998 | title={space.name} |
| 1999 | aria-label={`Show channels in space ${space.name}`} |
| 2000 | aria-pressed={selectedSpaceId === space.room_id} |
| 2001 | draggable="true" |
| 2002 | on:click={() => void selectSpace(space.room_id)} |
| 2003 | on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, space)} |
| 2004 | on:dragstart={(ev) => startRailDrag(ev, space.room_id)} |
| 2005 | on:dragover={(ev) => overRailSpace(ev, space)} |
| 2006 | on:dragleave={() => dropTarget?.id === space.room_id && (dropTarget = null)} |
| 2007 | on:drop|preventDefault={() => void dropRailSpace()} |
| 2008 | on:dragend={() => ((dragSpaceId = null), (dropTarget = null))} |
| 2009 | > |
| 2010 | <MxcAvatar mxc={space.avatar} label={space.name} size={44} shape="rounded" /> |
| 2011 | </button> |
| 2012 | {/each} |
| 2013 | {/each} |
| 2014 | <button |
| 2015 | type="button" |
| 2016 | class="rail-btn rail-add" |
| 2017 | aria-label="Join or create a room" |
| 2018 | on:click={() => { |
| 2019 | dialog = 'join'; |
| 2020 | }} |
| 2021 | > |
| 2022 | <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> |
| 2023 | </button> |
| 2024 | </nav> |
| 2025 | |
| 2026 | {#if menu} |
| 2027 | <ContextMenu items={menu.items} x={menu.x} y={menu.y} above={menu.above ?? false} onClose={() => (menu = null)} /> |
| 2028 | {/if} |
| 2029 | {#if userCard} |
| 2030 | {#key userCard} |
| 2031 | {@const cardUser = userCard.userId} |
| 2032 | <UserCard |
| 2033 | person={personFor(cardUser)} |
| 2034 | member={memberFor(cardUser)} |
| 2035 | levels={roomLevels} |
| 2036 | self={$sessionUser ?? null} |
| 2037 | x={userCard.x} |
| 2038 | y={userCard.y} |
| 2039 | confirm={userCard.confirm} |
| 2040 | onAction={(action) => void userAction(cardUser, action)} |
| 2041 | onClose={() => (userCard = null)} |
| 2042 | /> |
| 2043 | {/key} |
| 2044 | {/if} |
| 2045 | |
| 2046 | <aside class="sidebar" class:open={sidebarOpen} aria-label="Rooms"> |
| 2047 | <!-- svelte-ignore a11y_no_static_element_interactions --> |
| 2048 | <div class="pane-resize right" title="Drag to resize" on:pointerdown={(e) => startResize(e, 'side')} on:dblclick={() => resetWidth('side')}></div> |
| 2049 | <div class="side-search"> |
| 2050 | <label class="visually-hidden" for="room-search">Search rooms</label> |
| 2051 | <input |
| 2052 | id="room-search" |
| 2053 | type="search" |
| 2054 | placeholder="Search rooms" |
| 2055 | bind:value={search} |
| 2056 | autocomplete="off" |
| 2057 | /> |
| 2058 | <button |
| 2059 | type="button" |
| 2060 | class="icon-btn" |
| 2061 | title="Refresh rooms" |
| 2062 | aria-label="Refresh rooms" |
| 2063 | disabled={roomsLoading} |
| 2064 | on:click={() => void refreshRooms()} |
| 2065 | > |
| 2066 | <span aria-hidden="true">⟳</span> |
| 2067 | </button> |
| 2068 | </div> |
| 2069 | {#key selectedSpaceId ?? 'home'} |
| 2070 | <div class="side-scroll" in:fly={{ y: 5, duration: motionDuration(180) }} out:fade={{ duration: motionDuration(120) }}> |
| 2071 | {#if selectedSpace && spaceParents.has(selectedSpace.room_id)} |
| 2072 | {@const parentId = spaceParents.get(selectedSpace.room_id) ?? ''} |
| 2073 | <button type="button" class="room-row up-row" on:click={() => void selectSpace(parentId)}> |
| 2074 | <span aria-hidden="true">↑</span> |
| 2075 | <span class="room-name"><EmojiText text={$rooms.find((r) => r.room_id === parentId)?.name ?? 'Parent space'} /></span> |
| 2076 | </button> |
| 2077 | {/if} |
| 2078 | {#if !selectedSpaceId} |
| 2079 | <ul class="room-list"> |
| 2080 | <li> |
| 2081 | <button type="button" class="room-row" class:active={mentionsOpen} on:click={selectMentions}> |
| 2082 | <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> |
| 2083 | <span class="room-name">Mentions</span> |
| 2084 | {#if $mentionsSnapshot && $mentionsSnapshot.unread_count > 0} |
| 2085 | <span class="badge mention" aria-label={`${$mentionsSnapshot.unread_count} unread mentions`}>{$mentionsSnapshot.unread_count > 99 ? '99+' : $mentionsSnapshot.unread_count}</span> |
| 2086 | {/if} |
| 2087 | </button> |
| 2088 | </li> |
| 2089 | </ul> |
| 2090 | {/if} |
| 2091 | <ul class="room-list"> |
| 2092 | <li> |
| 2093 | <button type="button" class="room-row" class:active={searchOpen} on:click={selectSearch}> |
| 2094 | <svg width="26" height="26" viewBox="0 0 26 26" aria-hidden="true"><circle cx="11.5" cy="11.5" r="6" fill="none" stroke="currentColor" stroke-width="1.8" /><path d="M16 16l5 5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" /></svg> |
| 2095 | <span class="room-name">Search messages</span> |
| 2096 | </button> |
| 2097 | </li> |
| 2098 | </ul> |
| 2099 | {#if roomsLoading && $rooms.length === 0} |
| 2100 | <p class="side-note">Loading rooms…</p> |
| 2101 | {:else if $rooms.length === 0} |
| 2102 | <p class="side-note">No rooms yet</p> |
| 2103 | <div class="side-cta"> |
| 2104 | <button type="button" on:click={() => (dialog = 'join')}>Join a room</button> |
| 2105 | <button type="button" on:click={() => (dialog = 'create')}>Create one</button> |
| 2106 | </div> |
| 2107 | {:else} |
| 2108 | {#if selectedSpaceId && spaceChildrenLoading} |
| 2109 | <p class="side-note">Loading channels…</p> |
| 2110 | {:else if selectedSpaceId && spaceChildrenError} |
| 2111 | <p class="side-note" role="alert"><EmojiText text={spaceChildrenError} /></p> |
| 2112 | <div class="side-cta"> |
| 2113 | <button type="button" on:click={() => selectedSpaceId && void selectSpace(selectedSpaceId)}>Retry</button> |
| 2114 | <button type="button" on:click={() => void selectHome()}>Back to Home</button> |
| 2115 | </div> |
| 2116 | {:else if selectedSpaceId && spaceChildIds && channelRooms.length === 0} |
| 2117 | <p class="side-note">No channels</p> |
| 2118 | <div class="side-cta"> |
| 2119 | <button type="button" on:click={() => void selectHome()}>Back to Home</button> |
| 2120 | </div> |
| 2121 | {:else} |
| 2122 | {#if invites.length > 0 && !selectedSpaceId} |
| 2123 | <h2 class="side-h">Invites</h2> |
| 2124 | <ul class="room-list"> |
| 2125 | {#each invites as room (room.room_id)} |
| 2126 | <li> |
| 2127 | <button |
| 2128 | type="button" |
| 2129 | class="room-row" |
| 2130 | class:active={$selectedRoomId === room.room_id} |
| 2131 | on:click={() => void selectRoom(room.room_id)} |
| 2132 | on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, room)} |
| 2133 | > |
| 2134 | <MxcAvatar mxc={room.avatar} label={room.name} size={26} shape="rounded" /> |
| 2135 | <span class="room-name"><EmojiText text={room.name} /></span> |
| 2136 | <span |
| 2137 | class="invite-join" |
| 2138 | role="button" |
| 2139 | tabindex="0" |
| 2140 | aria-label={`Join ${room.name}`} |
| 2141 | on:click|stopPropagation={() => void join(room.room_id)} |
| 2142 | on:keydown|stopPropagation={(ev) => { |
| 2143 | if (ev.key === 'Enter' || ev.key === ' ') { |
| 2144 | ev.preventDefault(); |
| 2145 | void join(room.room_id); |
| 2146 | } |
| 2147 | }} |
| 2148 | > |
| 2149 | Join |
| 2150 | </span> |
| 2151 | </button> |
| 2152 | </li> |
| 2153 | {/each} |
| 2154 | </ul> |
| 2155 | {/if} |
| 2156 | |
| 2157 | {#if directRooms.length > 0} |
| 2158 | <h2 class="side-h">Direct messages</h2> |
| 2159 | <ul class="room-list"> |
| 2160 | {#each directRooms as room (room.room_id)} |
| 2161 | <li class="room-item"> |
| 2162 | <button |
| 2163 | type="button" |
| 2164 | class="room-row" |
| 2165 | class:active={$selectedRoomId === room.room_id} |
| 2166 | aria-current={$selectedRoomId === room.room_id ? 'true' : undefined} |
| 2167 | on:click={() => void selectRoom(room.room_id)} |
| 2168 | on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, room)} |
| 2169 | > |
| 2170 | <MxcAvatar mxc={room.avatar} label={room.name} size={26} /> |
| 2171 | <span class="room-name"><EmojiText text={room.name} /></span> |
| 2172 | {#if roomUnread(room) > 0} |
| 2173 | <span |
| 2174 | class="badge" |
| 2175 | class:mention={room.unread_mentions > 0} |
| 2176 | aria-label={`${roomUnread(room)} unread`} |
| 2177 | > |
| 2178 | {roomUnread(room) > 99 ? '99+' : roomUnread(room)} |
| 2179 | </span> |
| 2180 | {/if} |
| 2181 | </button> |
| 2182 | {#if ($threadsByRoom[room.room_id] ?? []).length} |
| 2183 | <button |
| 2184 | type="button" |
| 2185 | class="fold-btn" |
| 2186 | class:open={threadFoldOpen(room.room_id, threadFolds, query)} |
| 2187 | aria-expanded={threadFoldOpen(room.room_id, threadFolds, query)} |
| 2188 | aria-label={`Threads in ${room.name}`} |
| 2189 | title="Threads" |
| 2190 | on:click={() => (threadFolds = { ...threadFolds, [room.room_id]: !threadFolds[room.room_id] })} |
| 2191 | > |
| 2192 | <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> |
| 2193 | </button> |
| 2194 | {/if} |
| 2195 | <PinButton pinned={room.favourite} label={room.name} onToggle={() => void togglePin(room)} /> |
| 2196 | </li> |
| 2197 | {#if threadFoldOpen(room.room_id, threadFolds, query)} |
| 2198 | <li> |
| 2199 | <RoomThreads |
| 2200 | roomId={room.room_id} |
| 2201 | threads={$threadsByRoom[room.room_id] ?? []} |
| 2202 | {query} |
| 2203 | activeRoot={threadView?.room_id === room.room_id ? threadView.root_event_id : null} |
| 2204 | onOpen={(root) => void openThreadIn(room.room_id, root)} |
| 2205 | /> |
| 2206 | </li> |
| 2207 | {/if} |
| 2208 | {/each} |
| 2209 | </ul> |
| 2210 | {/if} |
| 2211 | |
| 2212 | {#if groupRooms.length > 0} |
| 2213 | <h2 class="side-h">{selectedSpace ? 'Channels' : 'Rooms'}</h2> |
| 2214 | <ul class="room-list"> |
| 2215 | {#each groupRooms as room (room.room_id)} |
| 2216 | <li class="room-item"> |
| 2217 | <button |
| 2218 | type="button" |
| 2219 | class="room-row" |
| 2220 | class:active={$selectedRoomId === room.room_id} |
| 2221 | aria-current={$selectedRoomId === room.room_id ? 'true' : undefined} |
| 2222 | on:click={() => void selectRoom(room.room_id)} |
| 2223 | on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, room)} |
| 2224 | > |
| 2225 | <MxcAvatar mxc={room.avatar} label={room.name} size={26} shape="rounded" /> |
| 2226 | <span class="room-name"><EmojiText text={room.name} /></span> |
| 2227 | {#if roomUnread(room) > 0} |
| 2228 | <span |
| 2229 | class="badge" |
| 2230 | class:mention={room.unread_mentions > 0} |
| 2231 | aria-label={`${roomUnread(room)} unread`} |
| 2232 | > |
| 2233 | {roomUnread(room) > 99 ? '99+' : roomUnread(room)} |
| 2234 | </span> |
| 2235 | {/if} |
| 2236 | </button> |
| 2237 | {#if ($threadsByRoom[room.room_id] ?? []).length} |
| 2238 | <button |
| 2239 | type="button" |
| 2240 | class="fold-btn" |
| 2241 | class:open={threadFoldOpen(room.room_id, threadFolds, query)} |
| 2242 | aria-expanded={threadFoldOpen(room.room_id, threadFolds, query)} |
| 2243 | aria-label={`Threads in ${room.name}`} |
| 2244 | title="Threads" |
| 2245 | on:click={() => (threadFolds = { ...threadFolds, [room.room_id]: !threadFolds[room.room_id] })} |
| 2246 | > |
| 2247 | <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> |
| 2248 | </button> |
| 2249 | {/if} |
| 2250 | <PinButton pinned={room.favourite} label={room.name} onToggle={() => void togglePin(room)} /> |
| 2251 | </li> |
| 2252 | {#if threadFoldOpen(room.room_id, threadFolds, query)} |
| 2253 | <li> |
| 2254 | <RoomThreads |
| 2255 | roomId={room.room_id} |
| 2256 | threads={$threadsByRoom[room.room_id] ?? []} |
| 2257 | {query} |
| 2258 | activeRoot={threadView?.room_id === room.room_id ? threadView.root_event_id : null} |
| 2259 | onOpen={(root) => void openThreadIn(room.room_id, root)} |
| 2260 | /> |
| 2261 | </li> |
| 2262 | {/if} |
| 2263 | {/each} |
| 2264 | </ul> |
| 2265 | {/if} |
| 2266 | |
| 2267 | {#if spaceList.length > 0} |
| 2268 | <h2 class="side-h">{selectedSpace ? 'Subspaces' : 'Spaces'}</h2> |
| 2269 | <ul class="room-list"> |
| 2270 | {#each spaceList as room (room.room_id)} |
| 2271 | <li class="room-item"> |
| 2272 | <button |
| 2273 | type="button" |
| 2274 | class="room-row" |
| 2275 | class:active={selectedSpaceId === room.room_id} |
| 2276 | aria-label={`Show channels in space ${room.name}`} |
| 2277 | on:click={() => void selectSpace(room.room_id)} |
| 2278 | on:contextmenu|preventDefault={(ev) => openRoomMenu(ev, room)} |
| 2279 | > |
| 2280 | <MxcAvatar mxc={room.avatar} label={room.name} size={26} shape="rounded" /> |
| 2281 | <span class="room-name"><EmojiText text={room.name} /></span> |
| 2282 | </button> |
| 2283 | <PinButton pinned={room.favourite} label={room.name} onToggle={() => void togglePin(room)} /> |
| 2284 | </li> |
| 2285 | {/each} |
| 2286 | </ul> |
| 2287 | {/if} |
| 2288 | |
| 2289 | {#if query && visibleRooms.length === 0} |
| 2290 | <p class="side-note">No rooms match “<EmojiText text={search.trim()} />”.</p> |
| 2291 | {/if} |
| 2292 | {/if} |
| 2293 | {/if} |
| 2294 | </div> |
| 2295 | {/key} |
| 2296 | |
| 2297 | </aside> |
| 2298 | <div class="account"> |
| 2299 | <button type="button" class="me-btn" title={$sessionUser} aria-haspopup="menu" on:click={openAccountMenu}> |
| 2300 | {#if profileMxc} |
| 2301 | <MxcAvatar mxc={profileMxc} label={profile?.display_name ?? $sessionUser} size={32} /> |
| 2302 | {:else} |
| 2303 | <span class="me-avatar" aria-hidden="true">{$sessionUser.slice(1, 2).toUpperCase()}</span> |
| 2304 | {/if} |
| 2305 | <span class="me-names"> |
| 2306 | <span class="me-name"><EmojiText text={profile?.display_name || $sessionUser} /></span> |
| 2307 | {#if profile?.display_name && profile.display_name !== $sessionUser}<span class="me-id">{$sessionUser}</span>{/if} |
| 2308 | </span> |
| 2309 | </button> |
| 2310 | <div class="account-actions"> |
| 2311 | <button type="button" class="icon-btn" title="Encryption and verification" aria-label="Encryption and verification" on:click={() => (dialog = 'security')}> |
| 2312 | <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> |
| 2313 | </button> |
| 2314 | <button type="button" class="icon-btn" title="Settings" aria-label="Settings" on:click={() => (dialog = 'settings')}> |
| 2315 | <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> |
| 2316 | </button> |
| 2317 | <button type="button" class="icon-btn" title="Log out" aria-label="Log out" on:click={() => void doLogout()}> |
| 2318 | <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> |
| 2319 | </button> |
| 2320 | </div> |
| 2321 | </div> |
| 2322 | {#if sidebarOpen} |
| 2323 | <button type="button" class="scrim" aria-label="Close room list" on:click={() => (sidebarOpen = false)}></button> |
| 2324 | {/if} |
| 2325 | |
| 2326 | <main class="chat"> |
| 2327 | {#if $banners.length > 0} |
| 2328 | <div class="banners" aria-live="polite"> |
| 2329 | {#each $banners as banner (banner.id)} |
| 2330 | <div class="banner" role="alert"> |
| 2331 | <span><EmojiText text={banner.message} /></span> |
| 2332 | <button |
| 2333 | type="button" |
| 2334 | aria-label="Dismiss error" |
| 2335 | on:click={() => dismissBanner(banner.id)} |
| 2336 | > |
| 2337 | ✕ |
| 2338 | </button> |
| 2339 | </div> |
| 2340 | {/each} |
| 2341 | </div> |
| 2342 | {/if} |
| 2343 | {#key mentionsOpen ? 'mentions' : searchOpen ? 'search' : $selectedRoomId ?? 'home'} |
| 2344 | <div class="chat-view"> |
| 2345 | {#if mentionsOpen && $sessionUser} |
| 2346 | <MentionsInbox self={$sessionUser} onLive={(roomId, eventId, threadRoot) => void openLive(roomId, eventId, threadRoot)} /> |
| 2347 | {:else if searchOpen} |
| 2348 | <SearchView scopes={searchScopes} self={$sessionUser ?? null} {roomName} onOpen={(roomId, eventId, threadRoot) => void openLive(roomId, eventId, threadRoot)} /> |
| 2349 | {:else if !selectedRoom} |
| 2350 | <div class="empty" in:fade={{ duration: motionDuration(180) }}> |
| 2351 | <div class="empty-mark" aria-hidden="true">◈</div> |
| 2352 | {#if selectedSpace} |
| 2353 | <h1><EmojiText text={selectedSpace.name} /></h1> |
| 2354 | {:else} |
| 2355 | <h1>Welcome to Malice</h1> |
| 2356 | {/if} |
| 2357 | <div class="empty-cta"> |
| 2358 | <button type="button" class="primary-btn" on:click={() => (dialog = 'join')}>Join a room</button> |
| 2359 | <button type="button" class="ghost-btn" on:click={() => (dialog = 'create')}>Create a room</button> |
| 2360 | </div> |
| 2361 | <p class="conn-line"> |
| 2362 | <span class="dot {connectionClass($connection)}" aria-hidden="true"></span> |
| 2363 | {$connection} |
| 2364 | </p> |
| 2365 | </div> |
| 2366 | {:else} |
| 2367 | {#if pins.length} |
| 2368 | <div class="pinned-strip" class:open={pinsExpanded}> |
| 2369 | <div class="pinned-head"> |
| 2370 | <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> |
| 2371 | <button type="button" class="pinned-latest" title="Jump to pinned message" on:click={() => jumpToPin(pins[0].event_id ?? '')}> |
| 2372 | <strong><EmojiText text={people[pins[0].sender.user_id]?.name ?? senderLabel(pins[0].sender)} /></strong> |
| 2373 | <span><EmojiText text={contentPreview(pins[0].content)} /></span> |
| 2374 | </button> |
| 2375 | {#if pins.length > 1} |
| 2376 | <button type="button" class="pinned-count" aria-expanded={pinsExpanded} on:click={() => (pinsExpanded = !pinsExpanded)}> |
| 2377 | {pins.length} pinned |
| 2378 | <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> |
| 2379 | </button> |
| 2380 | {/if} |
| 2381 | {#if pinsExpanded && selectedRoom.can_pin} |
| 2382 | <button type="button" class="icon-btn" aria-label="Unpin" title="Unpin" on:click={() => setPinned(pins[0].event_id ?? '', false)}> |
| 2383 | <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> |
| 2384 | </button> |
| 2385 | {/if} |
| 2386 | </div> |
| 2387 | {#if pinsExpanded} |
| 2388 | <ul class="pinned-list"> |
| 2389 | {#each pins.slice(1) as pin (pin.event_id)} |
| 2390 | <li> |
| 2391 | <button type="button" on:click={() => jumpToPin(pin.event_id ?? '')}> |
| 2392 | <strong><EmojiText text={people[pin.sender.user_id]?.name ?? senderLabel(pin.sender)} /></strong> |
| 2393 | <span><EmojiText text={contentPreview(pin.content)} /></span> |
| 2394 | </button> |
| 2395 | {#if selectedRoom.can_pin} |
| 2396 | <button type="button" class="icon-btn" aria-label="Unpin" title="Unpin" on:click={() => setPinned(pin.event_id ?? '', false)}> |
| 2397 | <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> |
| 2398 | </button> |
| 2399 | {/if} |
| 2400 | </li> |
| 2401 | {/each} |
| 2402 | </ul> |
| 2403 | {/if} |
| 2404 | </div> |
| 2405 | {/if} |
| 2406 | {#if recoveryBanner} |
| 2407 | <div class="sec-banner warn" role="status"> |
| 2408 | <span>Message history is locked</span> |
| 2409 | <button type="button" on:click={() => (dialog = 'security')}>Recover</button> |
| 2410 | </div> |
| 2411 | {/if} |
| 2412 | {#if verificationBanner} |
| 2413 | <div class="sec-banner" role="status"> |
| 2414 | {#if verificationBanner.kind === 'Incoming'} |
| 2415 | <span>A device wants to verify this session</span> |
| 2416 | <button type="button" on:click={() => (dialog = 'security')}>Review request</button> |
| 2417 | {:else if verificationBanner.kind === 'Comparison'} |
| 2418 | <span>Verification codes ready</span> |
| 2419 | <button type="button" on:click={() => (dialog = 'security')}>Compare codes</button> |
| 2420 | {:else if verificationBanner.kind === 'Waiting'} |
| 2421 | <span>Verification started</span> |
| 2422 | <button type="button" on:click={() => (dialog = 'security')}>Open verification</button> |
| 2423 | {:else if verificationBanner.kind === 'Failed'} |
| 2424 | <span>Verification failed: <EmojiText text={verificationBanner.message} /></span> |
| 2425 | <button type="button" on:click={() => (dialog = 'security')}>Try again</button> |
| 2426 | {:else if verificationBanner.kind === 'Cancelled'} |
| 2427 | <span>Verification cancelled: <EmojiText text={verificationBanner.reason} /></span> |
| 2428 | <button type="button" on:click={() => (dialog = 'security')}>Open security</button> |
| 2429 | {:else} |
| 2430 | <span>Verification in progress</span> |
| 2431 | <button type="button" on:click={() => (dialog = 'security')}>Open security</button> |
| 2432 | {/if} |
| 2433 | </div> |
| 2434 | {/if} |
| 2435 | {#if $selectedRoomId && openFailed[$selectedRoomId]} |
| 2436 | <p class="conn-banner error" role="alert"><EmojiText text={openFailed[$selectedRoomId]} /></p> |
| 2437 | {/if} |
| 2438 | |
| 2439 | {#if pinPreview} |
| 2440 | <div class="pin-preview" role="dialog" aria-label="Pinned message preview"> |
| 2441 | <div class="pin-preview-head"> |
| 2442 | <strong><EmojiText text={people[pinPreview.sender.user_id]?.name ?? senderLabel(pinPreview.sender)} /></strong> |
| 2443 | <button type="button" class="icon-btn" aria-label="Close pinned message preview" on:click={() => (pinPreview = null)}>✕</button> |
| 2444 | </div> |
| 2445 | <p><EmojiText text={contentPreview(pinPreview.content)} /></p> |
| 2446 | <button type="button" class="primary-btn" disabled={pinJumpBusy} on:click={() => void jumpToPin(pinPreview?.event_id ?? '')}> |
| 2447 | {pinJumpBusy ? 'Loading message…' : 'Jump to message'} |
| 2448 | </button> |
| 2449 | </div> |
| 2450 | {/if} |
| 2451 | |
| 2452 | <!-- svelte-ignore a11y_no_static_element_interactions --> |
| 2453 | <div |
| 2454 | class="timeline" |
| 2455 | in:fly={{ y: 6, duration: motionDuration(180) }} |
| 2456 | out:fade={{ duration: motionDuration(120) }} |
| 2457 | bind:this={timelineEl} |
| 2458 | on:scroll={onTimelineScroll} |
| 2459 | on:wheel={noteUserScroll} |
| 2460 | on:touchmove={noteUserScroll} |
| 2461 | on:keydown={onTimelineKey} |
| 2462 | on:pointerdown={noteUserScroll} |
| 2463 | aria-label={`Messages in ${selectedRoom.name}`} |
| 2464 | > |
| 2465 | <div class="timeline-inner" use:pinTimeline> |
| 2466 | <div class="timeline-top"> |
| 2467 | {#if recentState === 'Loading'} |
| 2468 | <p class="side-note">Loading recent history…</p> |
| 2469 | {:else if recentState && typeof recentState === 'object'} |
| 2470 | <div class="history-gap"> |
| 2471 | <span>Recent history could not be loaded</span> |
| 2472 | <button type="button" class="ghost-btn" disabled={!!recentRetrying[selectedRoom.room_id]} on:click={() => void retryRecentHistory(selectedRoom.room_id)}> |
| 2473 | {recentRetrying[selectedRoom.room_id] ? 'Loading…' : 'Retry'} |
| 2474 | </button> |
| 2475 | </div> |
| 2476 | {/if} |
| 2477 | {#if hasStart} |
| 2478 | <p class="start-note">Beginning of history</p> |
| 2479 | {:else} |
| 2480 | <button type="button" class="ghost-btn" disabled={paginateBusy || recentState === 'Loading'} on:click={() => void paginate()}> |
| 2481 | {paginateBusy ? 'Loading…' : 'Load older messages'} |
| 2482 | </button> |
| 2483 | {/if} |
| 2484 | </div> |
| 2485 | {#if grouped.length === 0} |
| 2486 | <p class="side-note timeline-empty">No messages yet</p> |
| 2487 | {:else} |
| 2488 | {#each grouped as g (g.key)} |
| 2489 | {#if g.item.kind === 'day'} |
| 2490 | <div class="day-row"><span>{formatDay(g.item.timestamp_ms)}</span></div> |
| 2491 | {:else if g.item.kind === 'readMarker'} |
| 2492 | <div class="new-row"><span>New</span></div> |
| 2493 | {:else if g.item.kind === 'start'} |
| 2494 | <p class="start-note">Beginning of history</p> |
| 2495 | {:else if g.item.kind === 'historyGap'} |
| 2496 | {#if g.item.gap.continuity !== 'Verified'} |
| 2497 | {@const gap = g.item.gap} |
| 2498 | {@const filling = fillingGaps[selectedRoom.room_id] === gap.id || gap.lifecycle === 'Fetching'} |
| 2499 | <div class="history-gap"> |
| 2500 | <span>{gap.failure ?? 'Some history is not loaded'}</span> |
| 2501 | <button type="button" class="ghost-btn" disabled={!!fillingGaps[selectedRoom.room_id] || gap.lifecycle === 'Fetching' || gap.lifecycle === 'Unavailable'} on:click={() => void fillGap(gap.id)}> |
| 2502 | {filling ? 'Loading…' : gap.lifecycle === 'Unavailable' ? 'History unavailable' : 'Fetch older history'} |
| 2503 | </button> |
| 2504 | </div> |
| 2505 | {/if} |
| 2506 | {:else if g.item.kind === 'unknown'} |
| 2507 | <p class="unknown-note">Unsupported event ({g.item.label})</p> |
| 2508 | {:else} |
| 2509 | <MessageRow |
| 2510 | itemId={g.key} |
| 2511 | event={g.item.event} |
| 2512 | showSender={g.showSender} |
| 2513 | senderAvatar={senderAvatarFor(g.item.event.sender.user_id) ?? g.item.event.sender.avatar} |
| 2514 | {reacting} |
| 2515 | onReact={(eventId, key, shortcode) => void react(eventId, key, shortcode)} |
| 2516 | quickReactions={usableQuickReactions} |
| 2517 | packs={roomPacks} |
| 2518 | linkPreviews={$linkPreviews} |
| 2519 | {loadPreview} |
| 2520 | onQuickChange={(list) => void changeQuickReactions(list)} |
| 2521 | {people} |
| 2522 | self={$sessionUser ?? null} |
| 2523 | onUser={(userId, x, y, asMenu) => void openUser(userId, x, y, asMenu)} |
| 2524 | onCloneSticker={openCloneStickerMenu} |
| 2525 | onMore={(ev, x, y) => void openMessageMenu(ev, x, y)} |
| 2526 | onOpenThread={selectedRoom.membership === 'Joined' || g.item.event.thread_summary ? openThreadHere : null} |
| 2527 | onReply={selectedRoom.membership === 'Joined' ? startReply : null} |
| 2528 | onJump={jumpTo} |
| 2529 | onEdit={selectedRoom.membership === 'Joined' ? startEdit : null} |
| 2530 | editing={editing !== null && editing.eventId === g.item.event.event_id} |
| 2531 | showSent={g.item.event.item_id === lastSentId && pendingItems.length === 0} |
| 2532 | /> |
| 2533 | {/if} |
| 2534 | {/each} |
| 2535 | {/if} |
| 2536 | {#each pendingItems as p, i (p.id)} |
| 2537 | <MessageRow |
| 2538 | itemId={`pending-${p.id}`} |
| 2539 | event={pendingToEvent(p)} |
| 2540 | onJump={jumpTo} |
| 2541 | showSender={pendingShowSender(i)} |
| 2542 | senderAvatar={senderAvatarFor($sessionUser ?? '')} |
| 2543 | {reacting} |
| 2544 | onReact={(eventId, key, shortcode) => void react(eventId, key, shortcode)} |
| 2545 | quickReactions={usableQuickReactions} |
| 2546 | packs={roomPacks} |
| 2547 | linkPreviews={$linkPreviews} |
| 2548 | {loadPreview} |
| 2549 | onQuickChange={(list) => void changeQuickReactions(list)} |
| 2550 | /> |
| 2551 | {#if p.status === 'failed'} |
| 2552 | <div class="pending-actions"> |
| 2553 | <span class="pending-error" role="alert"><EmojiText text={p.error ?? ''} /></span> |
| 2554 | <button type="button" class="ghost-btn" on:click={() => retryPending(p.id)}>Retry</button> |
| 2555 | <button type="button" class="ghost-btn danger" on:click={() => discardPending(p.id)}>Discard</button> |
| 2556 | </div> |
| 2557 | {/if} |
| 2558 | {/each} |
| 2559 | </div> |
| 2560 | </div> |
| 2561 | |
| 2562 | {#if selectedRoom.membership === 'Joined'} |
| 2563 | <input |
| 2564 | type="file" |
| 2565 | accept="image/*" |
| 2566 | bind:this={avatarInput} |
| 2567 | class="visually-hidden" |
| 2568 | aria-label="Choose a new avatar" |
| 2569 | on:change={() => void onAvatarChosen()} |
| 2570 | /> |
| 2571 | <Composer |
| 2572 | bind:this={composerRef} |
| 2573 | bind:value={composer} |
| 2574 | inputId="composer" |
| 2575 | label={`Message ${selectedRoom.name}`} |
| 2576 | placeholder={`Message ${selectedRoom.name}`} |
| 2577 | ready={!!($selectedRoomId && openReady[$selectedRoomId])} |
| 2578 | picked={($selectedRoomId && pickedMentions[$selectedRoomId]) || []} |
| 2579 | onPick={(mention) => $selectedRoomId && (pickedMentions = { ...pickedMentions, [$selectedRoomId]: [...(pickedMentions[$selectedRoomId] ?? []), mention] })} |
| 2580 | staged={currentStaged} |
| 2581 | onStage={stageFiles} |
| 2582 | onUnstage={(id) => $selectedRoomId && unstage($selectedRoomId, id)} |
| 2583 | {uploadBusy} |
| 2584 | {uploadName} |
| 2585 | editing={editing ? { original: editing.original } : null} |
| 2586 | onCancelEdit={cancelEdit} |
| 2587 | {replyingTo} |
| 2588 | onCancelReply={() => (replyingTo = null)} |
| 2589 | {people} |
| 2590 | self={$sessionUser ?? null} |
| 2591 | emotes={roomEmotes} |
| 2592 | packs={roomPacks} |
| 2593 | stickers={$selectedRoomId ? roomStickers($selectedRoomId) : null} |
| 2594 | commands |
| 2595 | onSubmit={send} |
| 2596 | onEditLast={editLastOwn} |
| 2597 | onMentionStart={() => $selectedRoomId && !$membersByRoom[$selectedRoomId] && void loadMembers($selectedRoomId)} |
| 2598 | /> |
| 2599 | {:else} |
| 2600 | <div class="join-bar"> |
| 2601 | <p>You are not a member of this room.</p> |
| 2602 | <button type="button" class="primary-btn" disabled={joinBusy} on:click={() => void join(selectedRoom.room_id)}> |
| 2603 | <EmojiText text={joinBusy ? 'Joining…' : `Join ${selectedRoom.name}`} /> |
| 2604 | </button> |
| 2605 | </div> |
| 2606 | {/if} |
| 2607 | {/if} |
| 2608 | </div> |
| 2609 | {/key} |
| 2610 | </main> |
| 2611 | |
| 2612 | {#if selectedRoom} |
| 2613 | <aside class="thread" aria-hidden={!threadShown} aria-label={`Thread in ${selectedRoom.name}`}> |
| 2614 | <!-- svelte-ignore a11y_no_static_element_interactions --> |
| 2615 | <div class="pane-resize left" title="Drag to resize" on:pointerdown={(e) => startResize(e, 'thread')} on:dblclick={() => resetWidth('thread')}></div> |
| 2616 | {#if threadView} |
| 2617 | <ThreadPane |
| 2618 | roomId={threadView.room_id} |
| 2619 | rootEventId={threadView.root_event_id} |
| 2620 | roomName={selectedRoom.name} |
| 2621 | joined={selectedRoom.membership === 'Joined'} |
| 2622 | self={$sessionUser ?? null} |
| 2623 | {people} |
| 2624 | {senderAvatarFor} |
| 2625 | quickReactions={usableQuickReactions} |
| 2626 | packs={roomPacks} |
| 2627 | linkPreviews={$linkPreviews} |
| 2628 | {loadPreview} |
| 2629 | onQuickChange={(list) => void changeQuickReactions(list)} |
| 2630 | onUser={(userId, x, y, asMenu) => void openUser(userId, x, y, asMenu)} |
| 2631 | onMore={(ev, x, y) => void openMessageMenu(ev, x, y)} |
| 2632 | onMentionStart={() => !$membersByRoom[threadView.room_id] && void loadMembers(threadView.room_id)} |
| 2633 | focusEventId={threadView.focus_event_id ?? null} |
| 2634 | onClose={() => void showThread(null)} |
| 2635 | /> |
| 2636 | {/if} |
| 2637 | </aside> |
| 2638 | <aside class="members" aria-hidden={!membersShown} aria-label={`Members of ${selectedRoom.name}`}> |
| 2639 | <!-- svelte-ignore a11y_no_static_element_interactions --> |
| 2640 | <div class="pane-resize left" title="Drag to resize" on:pointerdown={(e) => startResize(e, 'members')} on:dblclick={() => resetWidth('members')}></div> |
| 2641 | <div class="members-head"> |
| 2642 | <h2>Members</h2> |
| 2643 | <button type="button" class="icon-btn" aria-label="Close members" on:click={() => (membersOpen = false)}> |
| 2644 | <span aria-hidden="true">✕</span> |
| 2645 | </button> |
| 2646 | </div> |
| 2647 | {#if $membersLoading && members.length === 0} |
| 2648 | <p class="side-note">Loading members…</p> |
| 2649 | {:else if members.length === 0} |
| 2650 | <p class="side-note">No members loaded.</p> |
| 2651 | {#if $selectedRoomId} |
| 2652 | <button type="button" class="ghost-btn" on:click={() => $selectedRoomId && void loadMembers($selectedRoomId)}> |
| 2653 | Retry |
| 2654 | </button> |
| 2655 | {/if} |
| 2656 | {:else} |
| 2657 | <ul class="member-list"> |
| 2658 | {#each memberGroups as group (group.label)} |
| 2659 | <li class="member-group"> |
| 2660 | <h3 class="member-group-label">{group.label}<span>{group.members.length}</span></h3> |
| 2661 | <ul class="member-group-list"> |
| 2662 | {#each group.members as member (member.user_id)} |
| 2663 | <li> |
| 2664 | <button |
| 2665 | type="button" |
| 2666 | class="member" |
| 2667 | on:click={(ev) => { |
| 2668 | const rect = ev.currentTarget.getBoundingClientRect(); |
| 2669 | void openUser(member.user_id, rect.left - 308, rect.top, false); |
| 2670 | }} |
| 2671 | on:contextmenu|preventDefault={(ev) => void openUser(member.user_id, ev.clientX, ev.clientY, true)} |
| 2672 | > |
| 2673 | <MxcAvatar mxc={member.avatar} label={member.display_name || member.name || member.user_id} seed={member.user_id} size={28} /> |
| 2674 | <span class="member-names"> |
| 2675 | <span class="member-name"><EmojiText text={member.display_name || member.name} /></span> |
| 2676 | <span class="member-id">{member.user_id}</span> |
| 2677 | </span> |
| 2678 | </button> |
| 2679 | </li> |
| 2680 | {/each} |
| 2681 | </ul> |
| 2682 | </li> |
| 2683 | {/each} |
| 2684 | </ul> |
| 2685 | {/if} |
| 2686 | </aside> |
| 2687 | {/if} |
| 2688 | |
| 2689 | {#if cloneSource} |
| 2690 | <div class="modal-wrap" role="presentation" on:click|self={() => (cloneSource = null)}> |
| 2691 | <PackCloneDialog source={cloneSource} packs={$imagePacks} rooms={$rooms} onError={pushBanner} onClose={() => (cloneSource = null)} /> |
| 2692 | </div> |
| 2693 | {/if} |
| 2694 | |
| 2695 | {#if dialog} |
| 2696 | <div class="modal-wrap" role="presentation" on:click|self={() => (dialog = null)}> |
| 2697 | {#if dialog === 'security'} |
| 2698 | <SecurityPanel |
| 2699 | encryptionState={$encryption} |
| 2700 | verificationState={$verification} |
| 2701 | onAction={() => void loadEncryption()} |
| 2702 | encryptedPreviews={$urlPreviewSettings.encrypted_rooms} |
| 2703 | onEncryptedPreviews={(enabled) => void changeEncryptedPreviews(enabled)} |
| 2704 | on:close={() => (dialog = null)} |
| 2705 | /> |
| 2706 | {:else if dialog === 'settings'} |
| 2707 | <SettingsPanel |
| 2708 | quick={$quickReactions} |
| 2709 | packs={roomPacks} |
| 2710 | onQuickChange={(list) => void changeQuickReactions(list)} |
| 2711 | on:close={() => (dialog = null)} |
| 2712 | on:packs={() => (dialog = 'packs')} |
| 2713 | /> |
| 2714 | {:else if dialog === 'packs'} |
| 2715 | <PackManager packs={$imagePacks} rooms={$rooms} onError={pushBanner} on:close={() => (dialog = null)} /> |
| 2716 | {:else} |
| 2717 | <div class="modal" role="dialog" aria-modal="true" aria-label={dialog === 'join' ? 'Join a room' : 'Create a room'}> |
| 2718 | <div class="modal-tabs" role="tablist" aria-label="Room actions"> |
| 2719 | <button |
| 2720 | type="button" |
| 2721 | role="tab" |
| 2722 | aria-selected={dialog === 'join'} |
| 2723 | class:active={dialog === 'join'} |
| 2724 | on:click={() => (dialog = 'join')} |
| 2725 | > |
| 2726 | Join |
| 2727 | </button> |
| 2728 | <button |
| 2729 | type="button" |
| 2730 | role="tab" |
| 2731 | aria-selected={dialog === 'create'} |
| 2732 | class:active={dialog === 'create'} |
| 2733 | on:click={() => (dialog = 'create')} |
| 2734 | > |
| 2735 | Create |
| 2736 | </button> |
| 2737 | <button |
| 2738 | type="button" |
| 2739 | class="icon-btn modal-x" |
| 2740 | aria-label="Close dialog" |
| 2741 | on:click={() => (dialog = null)} |
| 2742 | > |
| 2743 | <span aria-hidden="true">✕</span> |
| 2744 | </button> |
| 2745 | </div> |
| 2746 | {#if dialog === 'join'} |
| 2747 | <form on:submit|preventDefault={() => void join(joinTarget)}> |
| 2748 | <label class="field"> |
| 2749 | <span>Room ID or alias</span> |
| 2750 | <input |
| 2751 | type="text" |
| 2752 | placeholder="!room:example.org or #alias:example.org" |
| 2753 | bind:value={joinTarget} |
| 2754 | required |
| 2755 | disabled={joinBusy} |
| 2756 | /> |
| 2757 | </label> |
| 2758 | <button type="submit" class="primary-btn wide" disabled={joinBusy || !joinTarget.trim()}> |
| 2759 | {joinBusy ? 'Joining…' : 'Join room'} |
| 2760 | </button> |
| 2761 | </form> |
| 2762 | {:else} |
| 2763 | <form on:submit|preventDefault={() => void create()}> |
| 2764 | <label class="field"> |
| 2765 | <span>Room name</span> |
| 2766 | <input |
| 2767 | type="text" |
| 2768 | placeholder="Weekend plans" |
| 2769 | bind:value={createName} |
| 2770 | required |
| 2771 | disabled={createBusy} |
| 2772 | /> |
| 2773 | </label> |
| 2774 | <label class="field"> |
| 2775 | <span>Topic (optional)</span> |
| 2776 | <input |
| 2777 | type="text" |
| 2778 | placeholder="What should this room be about?" |
| 2779 | bind:value={createTopic} |
| 2780 | disabled={createBusy} |
| 2781 | /> |
| 2782 | </label> |
| 2783 | <button type="submit" class="primary-btn wide" disabled={createBusy || !createName.trim()}> |
| 2784 | {createBusy ? 'Creating…' : 'Create room'} |
| 2785 | </button> |
| 2786 | </form> |
| 2787 | {/if} |
| 2788 | </div> |
| 2789 | {/if} |
| 2790 | </div> |
| 2791 | {/if} |
| 2792 | </div> |
| 2793 | {/if} |
| 2794 | |
| 2795 | <ImageLightbox /> |