| 1 | <script lang="ts"> |
| 2 | import MediaAttachmentView from './MediaAttachmentView.svelte'; |
| 3 | import MxcAvatar from './MxcAvatar.svelte'; |
| 4 | import Emoji from './Emoji.svelte'; |
| 5 | import EmojiText from './EmojiText.svelte'; |
| 6 | import MessageText from './MessageText.svelte'; |
| 7 | import ReactionPicker from './ReactionPicker.svelte'; |
| 8 | import LinkCard from './LinkCard.svelte'; |
| 9 | import { mediaUrl, messageMediaUrl } from './api'; |
| 10 | import type { ImagePack, LinkPreview, Person, QuickReaction, ReplyReference, SendState, TimelineContent, TimelineEvent } from './types'; |
| 11 | import { senderLabel } from './types'; |
| 12 | import { formatClock, formatDay, initialsOf, senderHue } from './format'; |
| 13 | import { findUrls } from './urls'; |
| 14 | import { mentionsFromHtml, resolveMentions, stripMarkdownPills } from './mentions'; |
| 15 | |
| 16 | export let itemId: string; |
| 17 | export let event: TimelineEvent; |
| 18 | export let showSender: boolean; |
| 19 | export let reacting: boolean; |
| 20 | export let onReact: (eventId: string, key: string, shortcode?: string) => void; |
| 21 | export let senderAvatar: string | null = null; |
| 22 | export let quickReactions: QuickReaction[] = []; |
| 23 | export let packs: ImagePack[] = []; |
| 24 | export let onQuickChange: (list: QuickReaction[]) => void = () => {}; |
| 25 | export let linkPreviews: Record<string, LinkPreview | null> = {}; |
| 26 | export let loadPreview: ((url: string) => void) | null = null; |
| 27 | export let people: Record<string, Person> = {}; |
| 28 | export let onReply: ((target: ReplyReference) => void) | null = null; |
| 29 | export let onJump: ((eventId: string) => void) | null = null; |
| 30 | export let onEdit: ((eventId: string, body: string) => void) | null = null; |
| 31 | export let editing = false; |
| 32 | export let showSent = true; |
| 33 | export let readOnly = false; |
| 34 | export let self: string | null = null; |
| 35 | export let onUser: ((userId: string, x: number, y: number, menu: boolean) => void) | null = null; |
| 36 | export let onCloneSticker: ((eventId: string, body: string, x: number, y: number) => void) | null = null; |
| 37 | export let onMore: ((event: TimelineEvent, x: number, y: number) => void) | null = null; |
| 38 | |
| 39 | function openUser(ev: MouseEvent, menu: boolean): void { |
| 40 | if (!onUser) return; |
| 41 | const rect = (ev.currentTarget as HTMLElement).getBoundingClientRect(); |
| 42 | onUser(event.sender.user_id, menu ? ev.clientX : rect.left, menu ? ev.clientY : rect.bottom + 4, menu); |
| 43 | } |
| 44 | |
| 45 | const PICKER_WIDTH = 320; |
| 46 | const PICKER_HEIGHT = 380; |
| 47 | const PICKER_MARGIN = 8; |
| 48 | const MAX_READERS = 3; |
| 49 | const STATE_LABELS: Record<string, string> = { |
| 50 | 'm.room.pinned_events': 'changed the pinned messages', |
| 51 | 'm.room.power_levels': 'changed the room permissions', |
| 52 | 'm.room.join_rules': 'changed who can join', |
| 53 | 'm.room.history_visibility': 'changed who can read history', |
| 54 | 'm.room.guest_access': 'changed guest access', |
| 55 | 'm.room.canonical_alias': 'changed the room address', |
| 56 | 'm.room.server_acl': 'changed the server access list', |
| 57 | 'm.space.child': 'changed the rooms in this space', |
| 58 | 'm.space.parent': 'changed the parent space', |
| 59 | 'im.ponies.room_emotes': 'updated a sticker pack' |
| 60 | }; |
| 61 | |
| 62 | let row: HTMLDivElement; |
| 63 | let pickerPop: HTMLDivElement | undefined; |
| 64 | let selected = false; |
| 65 | let pickerOpen = false; |
| 66 | let pickerStyle = ''; |
| 67 | |
| 68 | const MEMBERSHIP_LABELS: Record<string, string> = { |
| 69 | Joined: 'joined the room', |
| 70 | Left: 'left the room', |
| 71 | Banned: 'was banned', |
| 72 | Unbanned: 'was unbanned', |
| 73 | Kicked: 'was kicked', |
| 74 | KickedAndBanned: 'was kicked and banned', |
| 75 | Invited: 'was invited', |
| 76 | InvitationAccepted: 'accepted the invite', |
| 77 | InvitationRejected: 'rejected the invite', |
| 78 | InvitationRevoked: 'had the invite revoked', |
| 79 | Knocked: 'requested to join', |
| 80 | KnockAccepted: 'was let in', |
| 81 | KnockRetracted: 'withdrew the request to join', |
| 82 | KnockDenied: 'had the request to join denied' |
| 83 | }; |
| 84 | |
| 85 | $: name = event.sender.display_name ?? people[event.sender.user_id]?.name ?? event.sender.user_id; |
| 86 | $: displayName = event.sender.name_ambiguous ? `${name} (${event.sender.user_id})` : name; |
| 87 | $: readers = event.read_by.map((id) => people[id] ?? { user_id: id, name: id, avatar: null }); |
| 88 | $: interactive = event.content.kind === 'Message' || event.content.kind === 'Sticker' || event.content.kind === 'Poll'; |
| 89 | $: message = event.content.kind === 'Message' ? event.content.message : null; |
| 90 | $: stripped = stripMarkdownPills(message ? (message.media ? message.media.caption : message.body) ?? '' : ''); |
| 91 | $: linked = message ? [...mentionsFromHtml(message.formatted_body), ...stripped.mentions] : []; |
| 92 | $: mentions = resolveMentions(stripped.text, linked); |
| 93 | $: mentionsMe = self !== null && [...linked, ...mentions].some((m) => m.user_id === self); |
| 94 | $: previews = findUrls(stripped.text); |
| 95 | $: bundled = message ? message.link_previews : []; |
| 96 | $: cards = previews |
| 97 | .map((link) => ({ link, preview: bundled.find((b) => b.url === link.href) ?? linkPreviews[link.href] ?? null })) |
| 98 | .filter((c) => c.preview && (c.preview.title || c.preview.description || c.preview.image)); |
| 99 | $: if (loadPreview) { |
| 100 | for (const link of previews) { |
| 101 | if (!bundled.some((b) => b.url === link.href) && !(link.href in linkPreviews)) loadPreview(link.href); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | $: sent = interactive && showSent && event.own && event.send_state.kind === 'Sent' && event.event_id !== null; |
| 106 | |
| 107 | function sendLabel(state: SendState): string { |
| 108 | if (state.kind === 'Failed') return state.will_retry ? 'failed — will retry' : 'failed — not delivered'; |
| 109 | if (state.kind === 'Sending') return 'sending…'; |
| 110 | return ''; |
| 111 | } |
| 112 | |
| 113 | function toggleSelected(e: MouseEvent) { |
| 114 | if (readOnly || !interactive || (e.target as Element).closest('a, button, input, video, audio, .picker-pop')) return; |
| 115 | selected = !selected; |
| 116 | } |
| 117 | |
| 118 | function deselectOutside(e: PointerEvent) { |
| 119 | if (selected && !pickerOpen && !row.contains(e.target as Node)) selected = false; |
| 120 | } |
| 121 | |
| 122 | function openPicker(e: MouseEvent) { |
| 123 | if (pickerOpen) { |
| 124 | pickerOpen = false; |
| 125 | return; |
| 126 | } |
| 127 | const rect = (e.currentTarget as HTMLElement).getBoundingClientRect(); |
| 128 | const height = Math.min(PICKER_HEIGHT, window.innerHeight - 2 * PICKER_MARGIN); |
| 129 | const below = window.innerHeight - rect.bottom - PICKER_MARGIN >= height; |
| 130 | const top = below ? rect.bottom + 4 : Math.max(PICKER_MARGIN, rect.top - height - 4); |
| 131 | const maxLeft = window.innerWidth - PICKER_WIDTH - PICKER_MARGIN; |
| 132 | const left = Math.max(PICKER_MARGIN, Math.min(rect.right - PICKER_WIDTH, maxLeft)); |
| 133 | pickerStyle = `top:${top}px;left:${left}px;height:${height}px`; |
| 134 | selected = true; |
| 135 | pickerOpen = true; |
| 136 | } |
| 137 | |
| 138 | function closePicker() { |
| 139 | pickerOpen = false; |
| 140 | } |
| 141 | |
| 142 | function isImageKey(key: string): boolean { |
| 143 | return key.startsWith('mxc://') || packs.some((p) => p.images.some((i) => i.reaction_key === key)); |
| 144 | } |
| 145 | |
| 146 | function react(key: string, shortcode: string | null) { |
| 147 | if (shortcode && isImageKey(key)) onReact(event.event_id ?? '', key, shortcode); |
| 148 | else onReact(event.event_id ?? '', key); |
| 149 | } |
| 150 | |
| 151 | function reply() { |
| 152 | if (!event.event_id || !onReply) return; |
| 153 | onReply({ |
| 154 | event_id: event.event_id, |
| 155 | details: { kind: 'Ready', sender: event.sender, content: event.content, timestamp_ms: event.timestamp_ms } |
| 156 | }); |
| 157 | } |
| 158 | |
| 159 | $: editableBody = |
| 160 | event.own && event.editable && event.event_id && event.content.kind === 'Message' && event.content.message.kind === 'Text' |
| 161 | ? event.content.message.body |
| 162 | : null; |
| 163 | |
| 164 | function edit() { |
| 165 | if (!event.event_id || editableBody === null || !onEdit) return; |
| 166 | onEdit(event.event_id, editableBody); |
| 167 | } |
| 168 | |
| 169 | function reactorNames(senders: string[]): string { |
| 170 | const names = senders.map((id) => people[id]?.name ?? id); |
| 171 | if (names.length <= 12) return names.join(', '); |
| 172 | return `${names.slice(0, 12).join(', ')} and ${names.length - 12} more`; |
| 173 | } |
| 174 | |
| 175 | function pick(key: string, shortcode: string | null) { |
| 176 | pickerOpen = false; |
| 177 | react(key, shortcode); |
| 178 | } |
| 179 | |
| 180 | function closeOnScroll(e: Event) { |
| 181 | if (pickerOpen && !pickerPop?.contains(e.target as Node)) pickerOpen = false; |
| 182 | } |
| 183 | |
| 184 | function actorLabel(userId: string, name: string | null): string { |
| 185 | return name ?? people[userId]?.name ?? userId; |
| 186 | } |
| 187 | |
| 188 | function replyPreview(content: TimelineContent): string { |
| 189 | if (content.kind === 'Message') return stripMarkdownPills(content.message.body).text; |
| 190 | if (content.kind === 'Sticker') return content.body || 'Sticker'; |
| 191 | if (content.kind === 'Poll') return `Poll: ${content.question}`; |
| 192 | if (content.kind === 'Redacted') return 'Message deleted'; |
| 193 | if (content.kind === 'UnableToDecrypt') return 'Unable to decrypt'; |
| 194 | return systemLine(content); |
| 195 | } |
| 196 | |
| 197 | function systemLine(content: TimelineContent, actor = displayName): string { |
| 198 | switch (content.kind) { |
| 199 | case 'Redacted': |
| 200 | return 'Message deleted'; |
| 201 | case 'UnableToDecrypt': |
| 202 | return `Message from ${actor} could not be decrypted`; |
| 203 | case 'Membership': { |
| 204 | const who = actorLabel(content.user_id, content.display_name); |
| 205 | return `${who} ${MEMBERSHIP_LABELS[content.change] ?? 'updated their membership'}`; |
| 206 | } |
| 207 | case 'Profile': { |
| 208 | const who = actorLabel(content.user_id, null); |
| 209 | const parts: string[] = []; |
| 210 | if (content.display_name) { |
| 211 | parts.push( |
| 212 | content.display_name.new |
| 213 | ? `changed their display name to "${content.display_name.new}"` |
| 214 | : 'removed their display name' |
| 215 | ); |
| 216 | } |
| 217 | if (content.avatar) parts.push('changed their avatar'); |
| 218 | return `${who} ${parts.length > 0 ? parts.join(' and ') : 'updated their profile'}`; |
| 219 | } |
| 220 | case 'RoomName': |
| 221 | return content.name |
| 222 | ? `${actor} changed the room name to "${content.name}"` |
| 223 | : `${actor} removed the room name`; |
| 224 | case 'RoomTopic': |
| 225 | return content.topic |
| 226 | ? `${actor} changed the topic to "${content.topic}"` |
| 227 | : `${actor} removed the topic`; |
| 228 | case 'RoomAvatar': |
| 229 | return content.avatar ? `${actor} changed the room avatar` : `${actor} removed the room avatar`; |
| 230 | case 'EncryptionEnabled': |
| 231 | return `${actor} enabled encryption in this room`; |
| 232 | case 'RoomCreated': |
| 233 | return `${actor} created the room`; |
| 234 | case 'RoomUpgraded': |
| 235 | return `${actor} upgraded the room to a new version`; |
| 236 | case 'OtherState': |
| 237 | return `${actor} ${STATE_LABELS[content.event_type] ?? `sent a state event (${content.event_type})`}`; |
| 238 | case 'Other': |
| 239 | return `${actor} sent an event (${content.event_type})`; |
| 240 | default: |
| 241 | return actor; |
| 242 | } |
| 243 | } |
| 244 | </script> |
| 245 | |
| 246 | <svelte:window |
| 247 | on:pointerdown={deselectOutside} |
| 248 | on:keydown={(e) => e.key === 'Escape' && (selected = false)} |
| 249 | on:scroll|capture={closeOnScroll} |
| 250 | on:resize={closePicker} |
| 251 | /> |
| 252 | |
| 253 | <!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions --> |
| 254 | <div |
| 255 | class="msg" |
| 256 | class:own={event.own} |
| 257 | class:editing |
| 258 | class:mentioned={mentionsMe} |
| 259 | class:system={!interactive} |
| 260 | class:has-readers={interactive && readers.length > 0} |
| 261 | class:selected |
| 262 | data-item={itemId} |
| 263 | data-event={event.event_id} |
| 264 | bind:this={row} |
| 265 | on:click={toggleSelected} |
| 266 | > |
| 267 | {#if !readOnly && interactive && event.event_id} |
| 268 | <div class="actions" role="toolbar" aria-label={`Actions for message from ${displayName}`}> |
| 269 | {#each quickReactions as r (r.key)} |
| 270 | {@const label = r.shortcode ? `:${r.shortcode}:` : r.key} |
| 271 | <button |
| 272 | type="button" |
| 273 | title={`React ${label}`} |
| 274 | aria-label={`React ${label} to message from ${displayName}`} |
| 275 | disabled={reacting} |
| 276 | on:click={() => react(r.key, r.shortcode)} |
| 277 | > |
| 278 | {#if r.key.startsWith('mxc://')} |
| 279 | <img class="emote" src={mediaUrl(r.key) ?? ''} alt="" /> |
| 280 | {:else} |
| 281 | <Emoji emoji={r.key} size={18} /> |
| 282 | {/if} |
| 283 | </button> |
| 284 | {/each} |
| 285 | <button |
| 286 | type="button" |
| 287 | title="Add reaction" |
| 288 | aria-label={`Add reaction to message from ${displayName}`} |
| 289 | aria-haspopup="dialog" |
| 290 | aria-expanded={pickerOpen} |
| 291 | on:pointerdown|stopPropagation |
| 292 | on:click={openPicker} |
| 293 | > |
| 294 | ☺+ |
| 295 | </button> |
| 296 | {#if onCloneSticker && event.content.kind === 'Sticker'} |
| 297 | {@const stickerBody = event.content.body} |
| 298 | {@const stickerId = event.event_id} |
| 299 | <button |
| 300 | type="button" |
| 301 | title="Clone sticker" |
| 302 | aria-label="Clone sticker to one of your packs" |
| 303 | on:click|stopPropagation={(ev) => onCloneSticker?.(stickerId, stickerBody, ev.clientX, ev.clientY)} |
| 304 | > |
| 305 | ⧉ |
| 306 | </button> |
| 307 | {/if} |
| 308 | {#if onReply} |
| 309 | <button |
| 310 | type="button" |
| 311 | title="Reply" |
| 312 | aria-label={`Reply to message from ${displayName}`} |
| 313 | on:click|stopPropagation={reply} |
| 314 | > |
| 315 | ↩ |
| 316 | </button> |
| 317 | {/if} |
| 318 | {#if onEdit && editableBody !== null} |
| 319 | <button type="button" title="Edit" aria-label="Edit your message" on:click|stopPropagation={edit}> |
| 320 | ✎ |
| 321 | </button> |
| 322 | {/if} |
| 323 | {#if onMore} |
| 324 | <button |
| 325 | type="button" |
| 326 | title="More" |
| 327 | aria-label={`More actions for message from ${displayName}`} |
| 328 | aria-haspopup="menu" |
| 329 | on:click|stopPropagation={(ev) => onMore?.(event, ev.clientX, ev.clientY)} |
| 330 | > |
| 331 | ⋯ |
| 332 | </button> |
| 333 | {/if} |
| 334 | </div> |
| 335 | {#if pickerOpen} |
| 336 | <div class="picker-pop" style={pickerStyle} bind:this={pickerPop}> |
| 337 | <ReactionPicker {packs} quick={quickReactions} onPick={pick} {onQuickChange} onClose={closePicker} /> |
| 338 | </div> |
| 339 | {/if} |
| 340 | {/if} |
| 341 | {#if showSender} |
| 342 | <button |
| 343 | type="button" |
| 344 | class="user-hit" |
| 345 | disabled={!onUser} |
| 346 | tabindex="-1" |
| 347 | aria-hidden="true" |
| 348 | on:click|stopPropagation={(ev) => openUser(ev, false)} |
| 349 | on:contextmenu|preventDefault|stopPropagation={(ev) => openUser(ev, true)} |
| 350 | > |
| 351 | {#if senderAvatar} |
| 352 | <MxcAvatar mxc={senderAvatar} label={name} size={34} /> |
| 353 | {:else} |
| 354 | <span class="avatar" style={`background:hsl(${senderHue(event.sender.user_id)} 35% 32%)`}> |
| 355 | <span><EmojiText text={initialsOf(name)} /></span> |
| 356 | </span> |
| 357 | {/if} |
| 358 | </button> |
| 359 | {:else} |
| 360 | <div class="avatar-spacer" aria-hidden="true"> |
| 361 | <span class="hover-time">{formatClock(event.timestamp_ms)}</span> |
| 362 | </div> |
| 363 | {/if} |
| 364 | <div class="msg-body"> |
| 365 | {#if showSender} |
| 366 | <div class="msg-head"> |
| 367 | <button |
| 368 | type="button" |
| 369 | class="sender" |
| 370 | disabled={!onUser} |
| 371 | style={`color:hsl(${senderHue(event.sender.user_id)} 70% var(--name-lightness))`} |
| 372 | on:click|stopPropagation={(ev) => openUser(ev, false)} |
| 373 | on:contextmenu|preventDefault|stopPropagation={(ev) => openUser(ev, true)} |
| 374 | > |
| 375 | <EmojiText text={displayName} /> |
| 376 | </button> |
| 377 | <time class="time" datetime={new Date(event.timestamp_ms).toISOString()}> |
| 378 | {formatDay(event.timestamp_ms)} {formatClock(event.timestamp_ms)} |
| 379 | </time> |
| 380 | {#if event.content.kind === 'Message' && event.content.message.edited} |
| 381 | <span class="edited" title="Edited">(edited)</span> |
| 382 | {/if} |
| 383 | </div> |
| 384 | {/if} |
| 385 | {#if event.reply_to} |
| 386 | {@const target = event.reply_to.event_id} |
| 387 | <button |
| 388 | type="button" |
| 389 | class="reply-quote" |
| 390 | disabled={!onJump} |
| 391 | title="Jump to the original message" |
| 392 | on:click|stopPropagation={() => onJump?.(target)} |
| 393 | > |
| 394 | {#if event.reply_to.details.kind === 'Ready'} |
| 395 | <span class="reply-sender"><EmojiText text={event.reply_to.details.sender.display_name ?? people[event.reply_to.details.sender.user_id]?.name ?? senderLabel(event.reply_to.details.sender)} /></span> |
| 396 | <span class="reply-text"><EmojiText text={replyPreview(event.reply_to.details.content)} /></span> |
| 397 | {:else if event.reply_to.details.kind === 'Pending'} |
| 398 | Loading reply… |
| 399 | {:else} |
| 400 | Reply unavailable |
| 401 | {/if} |
| 402 | </button> |
| 403 | {/if} |
| 404 | |
| 405 | {#if event.content.kind === 'Message'} |
| 406 | {@const m = event.content.message} |
| 407 | {#if stripped.text} |
| 408 | <div class="text" class:emote={m.kind === 'Emote'} class:notice={m.kind === 'Notice' || m.kind === 'ServerNotice'}>{#if m.kind === 'Emote'}* <EmojiText text={displayName} /> {/if}<MessageText text={stripped.text} html={m.formatted_body} jumbo={m.kind === 'Text'} {mentions} {self} nameOf={(id) => people[id]?.name ?? null} />{#if m.edited && !showSender}<span class="edited" title="Edited">(edited)</span>{/if}</div> |
| 409 | {/if} |
| 410 | {#if m.media} |
| 411 | <MediaAttachmentView attachment={m.media} /> |
| 412 | {/if} |
| 413 | {#if cards.length > 0} |
| 414 | <div class="link-previews"> |
| 415 | {#each cards as card (card.link.href)} |
| 416 | <LinkCard link={card.link} preview={card.preview} /> |
| 417 | {/each} |
| 418 | </div> |
| 419 | {/if} |
| 420 | {:else if event.content.kind === 'Sticker'} |
| 421 | {#if event.content.media} |
| 422 | <MediaAttachmentView attachment={event.content.media} /> |
| 423 | {:else if event.content.body}<p class="text"><EmojiText text={event.content.body} /></p>{/if} |
| 424 | {:else if event.content.kind === 'Poll'} |
| 425 | <p class="text"><EmojiText text={`📊 ${event.content.question}`} /></p> |
| 426 | {:else} |
| 427 | <p class="system-line"><EmojiText text={systemLine(event.content, displayName)} /></p> |
| 428 | {/if} |
| 429 | |
| 430 | {#if interactive && event.reactions.length > 0} |
| 431 | <div class="reactions" aria-label="Reactions"> |
| 432 | {#each event.reactions as r (r.key)} |
| 433 | <button |
| 434 | type="button" |
| 435 | class="reaction" |
| 436 | class:mine={r.own} |
| 437 | aria-label={`${r.shortcode ? `:${r.shortcode}:` : r.key.startsWith('mxc://') ? 'custom emote' : r.key}, ${r.count} reaction${r.count === 1 ? '' : 's'}`} |
| 438 | disabled={readOnly || !event.event_id || reacting} |
| 439 | on:click={() => event.event_id && onReact(event.event_id, r.key)} |
| 440 | > |
| 441 | {#if r.image} |
| 442 | <img class="emote" src={messageMediaUrl(r.image, 'Thumbnail')} alt={r.shortcode ?? ''} title={r.shortcode ?? ''} /> |
| 443 | {:else if r.key.startsWith('mxc://')} |
| 444 | <img class="emote" src={mediaUrl(r.key) ?? ''} alt="" /> |
| 445 | {:else} |
| 446 | <Emoji emoji={r.key} size={16} /> |
| 447 | {/if} |
| 448 | <span class="count">{r.count}</span> |
| 449 | <span class="reactors" role="tooltip" id={`${itemId}-reactors-${r.key}`}> |
| 450 | <span class="reactors-key"><EmojiText text={r.shortcode ? `:${r.shortcode}:` : r.key.startsWith('mxc://') ? 'custom emote' : r.key} /></span> |
| 451 | <EmojiText text={reactorNames(r.senders)} /> |
| 452 | </span> |
| 453 | </button> |
| 454 | {/each} |
| 455 | </div> |
| 456 | {/if} |
| 457 | {#if sent}<span class="sent-tick" title="Sent" aria-label="Sent">✓</span>{/if} |
| 458 | {#if interactive && sendLabel(event.send_state)} |
| 459 | <div class="msg-foot"> |
| 460 | <span class="sendstate" class:failed={event.send_state.kind === 'Failed'}>{sendLabel(event.send_state)}</span> |
| 461 | </div> |
| 462 | {/if} |
| 463 | {#if interactive && readers.length > 0} |
| 464 | {@const seenBy = `Seen by ${readers.map((r) => r.name).join(', ')}`} |
| 465 | <div class="readby" title={seenBy} aria-label={seenBy} role="img"> |
| 466 | {#each readers.slice(0, MAX_READERS) as r (r.user_id)} |
| 467 | <MxcAvatar mxc={r.avatar} label={r.name} size={16} /> |
| 468 | {/each} |
| 469 | {#if readers.length > MAX_READERS}<span class="more">+{readers.length - MAX_READERS}</span>{/if} |
| 470 | </div> |
| 471 | {/if} |
| 472 | </div> |
| 473 | </div> |
| 474 | |
| 475 | <style> |
| 476 | .msg { position: relative; display: flex; gap: 10px; padding: var(--msg-gap, 3px) 0; } |
| 477 | .msg:hover, .msg.selected { background: var(--hover-faint); } |
| 478 | .msg:hover .hover-time, .msg.selected .hover-time { opacity: 1; } |
| 479 | .msg-foot { display: flex; align-items: center; gap: 8px; } |
| 480 | .sendstate { font-size: 11px; color: var(--muted); } |
| 481 | .sent-tick { position: absolute; right: 12px; bottom: 4px; font-size: 11px; color: var(--muted); } |
| 482 | .sendstate.failed { color: var(--danger); } |
| 483 | .link-previews { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; max-width: 420px; } |
| 484 | .avatar { |
| 485 | flex: none; |
| 486 | width: 34px; height: 34px; |
| 487 | border-radius: 50%; |
| 488 | display: grid; place-items: center; |
| 489 | font-size: 12px; font-weight: 700; color: #fff; |
| 490 | } |
| 491 | .avatar-spacer { flex: none; width: 34px; padding-top: 2px; text-align: center; } |
| 492 | .hover-time { opacity: 0; font-size: 10.5px; color: var(--muted); } |
| 493 | .msg-body { min-width: 0; flex: 1; } |
| 494 | .msg-head { display: flex; align-items: baseline; gap: 8px; } |
| 495 | .sender { font-weight: 650; font-size: 13.5px; padding: 0; border: none; background: none; font-family: inherit; cursor: pointer; } |
| 496 | .sender:hover { text-decoration: underline; } |
| 497 | .user-hit { flex: none; align-self: flex-start; padding: 0; border: none; background: none; border-radius: 50%; cursor: pointer; } |
| 498 | .time, .edited { color: var(--muted); font-size: 11.5px; } |
| 499 | .text .edited { margin-left: 6px; } |
| 500 | .msg.editing { background: color-mix(in srgb, var(--accent) 10%, transparent); } |
| 501 | .msg.mentioned { background: color-mix(in srgb, var(--warn) 8%, transparent); box-shadow: inset 2px 0 0 var(--warn); } |
| 502 | .reply-quote { |
| 503 | display: flex; gap: 6px; align-items: baseline; |
| 504 | max-width: min(100%, 520px); |
| 505 | border: none; |
| 506 | border-left: 2px solid var(--accent); |
| 507 | padding: 2px 8px; |
| 508 | margin: 2px 0 4px; |
| 509 | color: var(--muted); |
| 510 | font-size: 12.5px; |
| 511 | text-align: left; |
| 512 | background: var(--bg-soft); |
| 513 | border-radius: 0 var(--r-sm) var(--r-sm) 0; |
| 514 | cursor: pointer; |
| 515 | } |
| 516 | .reply-quote:disabled { cursor: default; } |
| 517 | .reply-quote:hover:not(:disabled) { color: var(--text); } |
| 518 | .reply-sender { flex: none; font-weight: 650; } |
| 519 | .reply-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } |
| 520 | :global(.msg.flash) { animation: reply-flash 1.2s ease-out; } |
| 521 | @keyframes -global-reply-flash { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } } |
| 522 | .text { |
| 523 | margin: 1px 0 2px; |
| 524 | font-size: 14px; |
| 525 | line-height: var(--msg-line-height, 1.5); |
| 526 | white-space: pre-wrap; |
| 527 | overflow-wrap: anywhere; |
| 528 | } |
| 529 | .text.emote { font-style: italic; color: var(--muted); } |
| 530 | .text.notice { color: var(--muted); } |
| 531 | .system-line { color: var(--muted); font-size: 12.5px; font-style: italic; margin: 1px 0; } |
| 532 | .msg.system { opacity: 0.85; --msg-gap: 1.5px; } |
| 533 | .msg.system .avatar-spacer { height: 0; padding-top: 0; } |
| 534 | .reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: max(4px, var(--msg-gap, 3px)); } |
| 535 | .reaction { |
| 536 | display: inline-flex; align-items: center; gap: 4px; |
| 537 | background: var(--bg-soft); |
| 538 | border: 1px solid var(--border); |
| 539 | border-radius: var(--r-sm); |
| 540 | padding: 1px 8px; |
| 541 | font-size: 13px; |
| 542 | color: var(--text); |
| 543 | cursor: pointer; |
| 544 | } |
| 545 | .reaction { position: relative; } |
| 546 | .reactors { |
| 547 | position: absolute; |
| 548 | left: 0; |
| 549 | bottom: calc(100% + 6px); |
| 550 | z-index: 15; |
| 551 | display: none; |
| 552 | width: max-content; |
| 553 | max-width: 260px; |
| 554 | padding: 6px 9px; |
| 555 | border: 1px solid var(--border); |
| 556 | border-radius: var(--r-md); |
| 557 | background: var(--panel-2); |
| 558 | box-shadow: 0 6px 18px rgb(0 0 0 / 0.3); |
| 559 | color: var(--text); |
| 560 | font-size: 12px; |
| 561 | line-height: 1.35; |
| 562 | text-align: left; |
| 563 | white-space: normal; |
| 564 | pointer-events: none; |
| 565 | } |
| 566 | .reactors-key { display: block; color: var(--muted); font-size: 11px; } |
| 567 | .reaction:hover .reactors, .reaction:focus-visible .reactors { display: block; } |
| 568 | .reaction.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); } |
| 569 | .reaction:disabled { cursor: default; opacity: 0.85; } |
| 570 | .msg.has-readers .msg-body { padding-right: 72px; } |
| 571 | .readby { position: absolute; right: 12px; bottom: 4px; display: flex; align-items: center; } |
| 572 | .readby > :global(* + *) { margin-left: -4px; } |
| 573 | .readby :global(.mxc-avatar), .readby :global(.mxc-fallback) { box-shadow: 0 0 0 1.5px var(--bg); } |
| 574 | .readby .more { margin-left: 3px; font-size: 10.5px; color: var(--muted); } |
| 575 | .actions { |
| 576 | position: absolute; top: -12px; right: 10px; z-index: 2; |
| 577 | display: flex; gap: 2px; |
| 578 | padding: 2px; |
| 579 | background: var(--bg-soft); |
| 580 | border: 1px solid var(--border); |
| 581 | border-radius: var(--r-md); |
| 582 | box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); |
| 583 | opacity: 0; |
| 584 | visibility: hidden; |
| 585 | pointer-events: none; |
| 586 | } |
| 587 | .msg:hover .actions, .msg:focus-within .actions, .msg.selected .actions { opacity: 1; visibility: visible; pointer-events: auto; } |
| 588 | :global(.timeline-inner:has(.msg.selected)) .msg:not(.selected) .actions { opacity: 0; visibility: hidden; pointer-events: none; } |
| 589 | .actions button { |
| 590 | background: transparent; |
| 591 | border: 1px solid transparent; |
| 592 | border-radius: var(--r-sm); |
| 593 | cursor: pointer; |
| 594 | font-size: 14px; |
| 595 | padding: 1px 5px; |
| 596 | } |
| 597 | .actions button:hover:not(:disabled) { border-color: var(--border); background: var(--hover); } |
| 598 | .actions button:disabled { opacity: 0.4; cursor: default; } |
| 599 | .emote { width: 1.3em; height: 1.3em; object-fit: contain; vertical-align: middle; } |
| 600 | .picker-pop { position: fixed; z-index: 60; width: 320px; max-width: calc(100vw - 16px); animation: pop-in var(--pop); } |
| 601 | </style> |