atagen

malice

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