atagen

malice

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