atagen

malice

public
Star0
Watch0
29f8ccacfdc74bc3e65d79bdba38cb6ba8f3ade0
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git

Blame: web/src/lib/MessageRow.svelte

973f8fbdaf80atagen2026-09-28 09:10 UTC1
<script lang="ts">
973f8fbdaf80atagen2026-09-28 09:10 UTC2
  import MediaAttachmentView from './MediaAttachmentView.svelte';
973f8fbdaf80atagen2026-09-28 09:10 UTC3
  import MxcAvatar from './MxcAvatar.svelte';
544a170ead2catagen2026-10-20 11:47 UTC4
  import Emoji from './Emoji.svelte';
544a170ead2catagen2026-10-20 11:47 UTC5
  import EmojiText from './EmojiText.svelte';
544a170ead2catagen2026-10-20 11:47 UTC6
  import ReactionPicker from './ReactionPicker.svelte';
b8ab00377c20atagen2026-10-22 05:13 UTC7
  import LinkCard from './LinkCard.svelte';
ecb8598b38afatagen2026-10-22 09:19 UTC8
  import { mediaUrl, messageMediaUrl } from './api';
b8ab00377c20atagen2026-10-22 05:13 UTC9
  import type { ImagePack, LinkPreview, QuickReaction, SendState, TimelineContent, TimelineEvent } from './types';
973f8fbdaf80atagen2026-09-28 09:10 UTC10
  import { senderLabel } from './types';
973f8fbdaf80atagen2026-09-28 09:10 UTC11
  import { formatClock, formatDay, initialsOf, senderHue } from './format';
973f8fbdaf80atagen2026-09-28 09:10 UTC12
  import { findUrls } from './urls';
973f8fbdaf80atagen2026-09-28 09:10 UTC13
973f8fbdaf80atagen2026-09-28 09:10 UTC14
  export let itemId: string;
973f8fbdaf80atagen2026-09-28 09:10 UTC15
  export let event: TimelineEvent;
973f8fbdaf80atagen2026-09-28 09:10 UTC16
  export let showSender: boolean;
973f8fbdaf80atagen2026-09-28 09:10 UTC17
  export let reacting: boolean;
ecb8598b38afatagen2026-10-22 09:19 UTC18
  export let onReact: (eventId: string, key: string, shortcode?: string) => void;
973f8fbdaf80atagen2026-09-28 09:10 UTC19
  export let senderAvatar: string | null = null;
544a170ead2catagen2026-10-20 11:47 UTC20
  export let quickReactions: QuickReaction[] = [];
544a170ead2catagen2026-10-20 11:47 UTC21
  export let packs: ImagePack[] = [];
544a170ead2catagen2026-10-20 11:47 UTC22
  export let onQuickChange: (list: QuickReaction[]) => void = () => {};
ecb8598b38afatagen2026-10-22 09:19 UTC23
  export let linkPreviews: Record<string, LinkPreview | null> = {};
ecb8598b38afatagen2026-10-22 09:19 UTC24
  export let loadPreview: ((url: string) => void) | null = null;
973f8fbdaf80atagen2026-09-28 09:10 UTC25
544a170ead2catagen2026-10-20 11:47 UTC26
  const PICKER_WIDTH = 320;
544a170ead2catagen2026-10-20 11:47 UTC27
  const PICKER_HEIGHT = 380;
544a170ead2catagen2026-10-20 11:47 UTC28
  const PICKER_MARGIN = 8;
544a170ead2catagen2026-10-20 11:47 UTC29
544a170ead2catagen2026-10-20 11:47 UTC30
  let row: HTMLDivElement;
544a170ead2catagen2026-10-20 11:47 UTC31
  let pickerPop: HTMLDivElement | undefined;
544a170ead2catagen2026-10-20 11:47 UTC32
  let selected = false;
544a170ead2catagen2026-10-20 11:47 UTC33
  let pickerOpen = false;
544a170ead2catagen2026-10-20 11:47 UTC34
  let pickerStyle = '';
973f8fbdaf80atagen2026-09-28 09:10 UTC35
973f8fbdaf80atagen2026-09-28 09:10 UTC36
  const MEMBERSHIP_LABELS: Record<string, string> = {
973f8fbdaf80atagen2026-09-28 09:10 UTC37
    Joined: 'joined the room',
973f8fbdaf80atagen2026-09-28 09:10 UTC38
    Left: 'left the room',
973f8fbdaf80atagen2026-09-28 09:10 UTC39
    Banned: 'was banned',
973f8fbdaf80atagen2026-09-28 09:10 UTC40
    Unbanned: 'was unbanned',
973f8fbdaf80atagen2026-09-28 09:10 UTC41
    Kicked: 'was kicked',
973f8fbdaf80atagen2026-09-28 09:10 UTC42
    KickedAndBanned: 'was kicked and banned',
973f8fbdaf80atagen2026-09-28 09:10 UTC43
    Invited: 'was invited',
973f8fbdaf80atagen2026-09-28 09:10 UTC44
    InvitationAccepted: 'accepted the invite',
973f8fbdaf80atagen2026-09-28 09:10 UTC45
    InvitationRejected: 'rejected the invite',
973f8fbdaf80atagen2026-09-28 09:10 UTC46
    InvitationRevoked: 'had the invite revoked',
973f8fbdaf80atagen2026-09-28 09:10 UTC47
    Knocked: 'requested to join',
973f8fbdaf80atagen2026-09-28 09:10 UTC48
    KnockAccepted: 'was let in',
973f8fbdaf80atagen2026-09-28 09:10 UTC49
    KnockRetracted: 'withdrew the request to join',
973f8fbdaf80atagen2026-09-28 09:10 UTC50
    KnockDenied: 'had the request to join denied'
973f8fbdaf80atagen2026-09-28 09:10 UTC51
  };
973f8fbdaf80atagen2026-09-28 09:10 UTC52
973f8fbdaf80atagen2026-09-28 09:10 UTC53
  $: name = senderLabel(event.sender);
973f8fbdaf80atagen2026-09-28 09:10 UTC54
  $: displayName = event.sender.name_ambiguous ? `${name} (${event.sender.user_id})` : name;
973f8fbdaf80atagen2026-09-28 09:10 UTC55
  $: interactive = event.content.kind === 'Message' || event.content.kind === 'Sticker' || event.content.kind === 'Poll';
973f8fbdaf80atagen2026-09-28 09:10 UTC56
  $: previews = event.content.kind === 'Message' ? findUrls(event.content.message.body) : [];
ecb8598b38afatagen2026-10-22 09:19 UTC57
  $: bundled = event.content.kind === 'Message' ? event.content.message.link_previews : [];
ecb8598b38afatagen2026-10-22 09:19 UTC58
  $: if (loadPreview) {
ecb8598b38afatagen2026-10-22 09:19 UTC59
    for (const link of previews) {
ecb8598b38afatagen2026-10-22 09:19 UTC60
      if (!bundled.some((b) => b.url === link.href) && !(link.href in linkPreviews)) loadPreview(link.href);
ecb8598b38afatagen2026-10-22 09:19 UTC61
    }
ecb8598b38afatagen2026-10-22 09:19 UTC62
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC63
973f8fbdaf80atagen2026-09-28 09:10 UTC64
  function sendLabel(state: SendState): string {
973f8fbdaf80atagen2026-09-28 09:10 UTC65
    if (state.kind === 'Failed') return state.will_retry ? 'failed — will retry' : 'failed — not delivered';
973f8fbdaf80atagen2026-09-28 09:10 UTC66
    if (state.kind === 'Sending') return 'sending…';
973f8fbdaf80atagen2026-09-28 09:10 UTC67
    if (event.own && state.kind === 'Sent' && event.event_id) return '✓ sent';
973f8fbdaf80atagen2026-09-28 09:10 UTC68
    return '';
973f8fbdaf80atagen2026-09-28 09:10 UTC69
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC70
544a170ead2catagen2026-10-20 11:47 UTC71
  function toggleSelected(e: MouseEvent) {
544a170ead2catagen2026-10-20 11:47 UTC72
    if (!interactive || (e.target as Element).closest('a, button, input, video, audio, .picker-pop')) return;
544a170ead2catagen2026-10-20 11:47 UTC73
    selected = !selected;
544a170ead2catagen2026-10-20 11:47 UTC74
  }
544a170ead2catagen2026-10-20 11:47 UTC75
544a170ead2catagen2026-10-20 11:47 UTC76
  function deselectOutside(e: PointerEvent) {
544a170ead2catagen2026-10-20 11:47 UTC77
    if (selected && !pickerOpen && !row.contains(e.target as Node)) selected = false;
544a170ead2catagen2026-10-20 11:47 UTC78
  }
544a170ead2catagen2026-10-20 11:47 UTC79
544a170ead2catagen2026-10-20 11:47 UTC80
  function openPicker(e: MouseEvent) {
544a170ead2catagen2026-10-20 11:47 UTC81
    if (pickerOpen) {
544a170ead2catagen2026-10-20 11:47 UTC82
      pickerOpen = false;
544a170ead2catagen2026-10-20 11:47 UTC83
      return;
544a170ead2catagen2026-10-20 11:47 UTC84
    }
544a170ead2catagen2026-10-20 11:47 UTC85
    const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
544a170ead2catagen2026-10-20 11:47 UTC86
    const height = Math.min(PICKER_HEIGHT, window.innerHeight - 2 * PICKER_MARGIN);
544a170ead2catagen2026-10-20 11:47 UTC87
    const below = window.innerHeight - rect.bottom - PICKER_MARGIN >= height;
544a170ead2catagen2026-10-20 11:47 UTC88
    const top = below ? rect.bottom + 4 : Math.max(PICKER_MARGIN, rect.top - height - 4);
544a170ead2catagen2026-10-20 11:47 UTC89
    const maxLeft = window.innerWidth - PICKER_WIDTH - PICKER_MARGIN;
544a170ead2catagen2026-10-20 11:47 UTC90
    const left = Math.max(PICKER_MARGIN, Math.min(rect.right - PICKER_WIDTH, maxLeft));
544a170ead2catagen2026-10-20 11:47 UTC91
    pickerStyle = `top:${top}px;left:${left}px;height:${height}px`;
544a170ead2catagen2026-10-20 11:47 UTC92
    selected = true;
544a170ead2catagen2026-10-20 11:47 UTC93
    pickerOpen = true;
544a170ead2catagen2026-10-20 11:47 UTC94
  }
544a170ead2catagen2026-10-20 11:47 UTC95
544a170ead2catagen2026-10-20 11:47 UTC96
  function closePicker() {
544a170ead2catagen2026-10-20 11:47 UTC97
    pickerOpen = false;
544a170ead2catagen2026-10-20 11:47 UTC98
  }
544a170ead2catagen2026-10-20 11:47 UTC99
ecb8598b38afatagen2026-10-22 09:19 UTC100
  function isImageKey(key: string): boolean {
ecb8598b38afatagen2026-10-22 09:19 UTC101
    return key.startsWith('mxc://') || packs.some((p) => p.images.some((i) => i.reaction_key === key));
ecb8598b38afatagen2026-10-22 09:19 UTC102
  }
ecb8598b38afatagen2026-10-22 09:19 UTC103
ecb8598b38afatagen2026-10-22 09:19 UTC104
  function react(key: string, shortcode: string | null) {
ecb8598b38afatagen2026-10-22 09:19 UTC105
    if (shortcode && isImageKey(key)) onReact(event.event_id ?? '', key, shortcode);
ecb8598b38afatagen2026-10-22 09:19 UTC106
    else onReact(event.event_id ?? '', key);
ecb8598b38afatagen2026-10-22 09:19 UTC107
  }
ecb8598b38afatagen2026-10-22 09:19 UTC108
ecb8598b38afatagen2026-10-22 09:19 UTC109
  function pick(key: string, shortcode: string | null) {
544a170ead2catagen2026-10-20 11:47 UTC110
    pickerOpen = false;
ecb8598b38afatagen2026-10-22 09:19 UTC111
    react(key, shortcode);
544a170ead2catagen2026-10-20 11:47 UTC112
  }
544a170ead2catagen2026-10-20 11:47 UTC113
544a170ead2catagen2026-10-20 11:47 UTC114
  function closeOnScroll(e: Event) {
544a170ead2catagen2026-10-20 11:47 UTC115
    if (pickerOpen && !pickerPop?.contains(e.target as Node)) pickerOpen = false;
544a170ead2catagen2026-10-20 11:47 UTC116
  }
544a170ead2catagen2026-10-20 11:47 UTC117
973f8fbdaf80atagen2026-09-28 09:10 UTC118
  function actorLabel(userId: string, name: string | null): string {
973f8fbdaf80atagen2026-09-28 09:10 UTC119
    return name ?? userId;
973f8fbdaf80atagen2026-09-28 09:10 UTC120
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC121
973f8fbdaf80atagen2026-09-28 09:10 UTC122
  function replyPreview(content: TimelineContent): string {
973f8fbdaf80atagen2026-09-28 09:10 UTC123
    if (content.kind === 'Message') return content.message.body;
973f8fbdaf80atagen2026-09-28 09:10 UTC124
    if (content.kind === 'Sticker') return content.body || 'Sticker';
973f8fbdaf80atagen2026-09-28 09:10 UTC125
    if (content.kind === 'Poll') return `Poll: ${content.question}`;
973f8fbdaf80atagen2026-09-28 09:10 UTC126
    if (content.kind === 'Redacted') return 'Message deleted';
973f8fbdaf80atagen2026-09-28 09:10 UTC127
    if (content.kind === 'UnableToDecrypt') return 'Unable to decrypt';
973f8fbdaf80atagen2026-09-28 09:10 UTC128
    return systemLine(content);
973f8fbdaf80atagen2026-09-28 09:10 UTC129
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC130
973f8fbdaf80atagen2026-09-28 09:10 UTC131
  function systemLine(content: TimelineContent): string {
973f8fbdaf80atagen2026-09-28 09:10 UTC132
    switch (content.kind) {
973f8fbdaf80atagen2026-09-28 09:10 UTC133
      case 'Redacted':
973f8fbdaf80atagen2026-09-28 09:10 UTC134
        return 'Message deleted';
973f8fbdaf80atagen2026-09-28 09:10 UTC135
      case 'UnableToDecrypt':
973f8fbdaf80atagen2026-09-28 09:10 UTC136
        return `Message from ${displayName} could not be decrypted`;
973f8fbdaf80atagen2026-09-28 09:10 UTC137
      case 'Membership': {
973f8fbdaf80atagen2026-09-28 09:10 UTC138
        const who = actorLabel(content.user_id, content.display_name);
973f8fbdaf80atagen2026-09-28 09:10 UTC139
        return `${who} ${MEMBERSHIP_LABELS[content.change] ?? 'updated their membership'}`;
973f8fbdaf80atagen2026-09-28 09:10 UTC140
      }
973f8fbdaf80atagen2026-09-28 09:10 UTC141
      case 'Profile': {
973f8fbdaf80atagen2026-09-28 09:10 UTC142
        const who = actorLabel(content.user_id, null);
973f8fbdaf80atagen2026-09-28 09:10 UTC143
        const parts: string[] = [];
973f8fbdaf80atagen2026-09-28 09:10 UTC144
        if (content.display_name) {
973f8fbdaf80atagen2026-09-28 09:10 UTC145
          parts.push(
973f8fbdaf80atagen2026-09-28 09:10 UTC146
            content.display_name.new
973f8fbdaf80atagen2026-09-28 09:10 UTC147
              ? `changed their display name to "${content.display_name.new}"`
973f8fbdaf80atagen2026-09-28 09:10 UTC148
              : 'removed their display name'
973f8fbdaf80atagen2026-09-28 09:10 UTC149
          );
973f8fbdaf80atagen2026-09-28 09:10 UTC150
        }
973f8fbdaf80atagen2026-09-28 09:10 UTC151
        if (content.avatar) parts.push('changed their avatar');
973f8fbdaf80atagen2026-09-28 09:10 UTC152
        return `${who} ${parts.length > 0 ? parts.join(' and ') : 'updated their profile'}`;
973f8fbdaf80atagen2026-09-28 09:10 UTC153
      }
973f8fbdaf80atagen2026-09-28 09:10 UTC154
      case 'RoomName':
973f8fbdaf80atagen2026-09-28 09:10 UTC155
        return content.name
973f8fbdaf80atagen2026-09-28 09:10 UTC156
          ? `${displayName} changed the room name to "${content.name}"`
973f8fbdaf80atagen2026-09-28 09:10 UTC157
          : `${displayName} removed the room name`;
973f8fbdaf80atagen2026-09-28 09:10 UTC158
      case 'RoomTopic':
973f8fbdaf80atagen2026-09-28 09:10 UTC159
        return content.topic
973f8fbdaf80atagen2026-09-28 09:10 UTC160
          ? `${displayName} changed the topic to "${content.topic}"`
973f8fbdaf80atagen2026-09-28 09:10 UTC161
          : `${displayName} removed the topic`;
973f8fbdaf80atagen2026-09-28 09:10 UTC162
      case 'RoomAvatar':
973f8fbdaf80atagen2026-09-28 09:10 UTC163
        return content.avatar ? `${displayName} changed the room avatar` : `${displayName} removed the room avatar`;
973f8fbdaf80atagen2026-09-28 09:10 UTC164
      case 'EncryptionEnabled':
973f8fbdaf80atagen2026-09-28 09:10 UTC165
        return `${displayName} enabled encryption in this room`;
973f8fbdaf80atagen2026-09-28 09:10 UTC166
      case 'RoomCreated':
973f8fbdaf80atagen2026-09-28 09:10 UTC167
        return `${displayName} created the room`;
973f8fbdaf80atagen2026-09-28 09:10 UTC168
      case 'RoomUpgraded':
973f8fbdaf80atagen2026-09-28 09:10 UTC169
        return `${displayName} upgraded the room to a new version`;
973f8fbdaf80atagen2026-09-28 09:10 UTC170
      case 'OtherState':
973f8fbdaf80atagen2026-09-28 09:10 UTC171
        return `${displayName} sent a state event (${content.event_type})`;
973f8fbdaf80atagen2026-09-28 09:10 UTC172
      case 'Other':
973f8fbdaf80atagen2026-09-28 09:10 UTC173
        return `${displayName} sent an event (${content.event_type})`;
973f8fbdaf80atagen2026-09-28 09:10 UTC174
      default:
973f8fbdaf80atagen2026-09-28 09:10 UTC175
        return displayName;
973f8fbdaf80atagen2026-09-28 09:10 UTC176
    }
973f8fbdaf80atagen2026-09-28 09:10 UTC177
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC178
</script>
973f8fbdaf80atagen2026-09-28 09:10 UTC179
544a170ead2catagen2026-10-20 11:47 UTC180
<svelte:window
544a170ead2catagen2026-10-20 11:47 UTC181
  on:pointerdown={deselectOutside}
544a170ead2catagen2026-10-20 11:47 UTC182
  on:keydown={(e) => e.key === 'Escape' && (selected = false)}
544a170ead2catagen2026-10-20 11:47 UTC183
  on:scroll|capture={closeOnScroll}
544a170ead2catagen2026-10-20 11:47 UTC184
  on:resize={closePicker}
544a170ead2catagen2026-10-20 11:47 UTC185
/>
544a170ead2catagen2026-10-20 11:47 UTC186
544a170ead2catagen2026-10-20 11:47 UTC187
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
544a170ead2catagen2026-10-20 11:47 UTC188
<div
544a170ead2catagen2026-10-20 11:47 UTC189
  class="msg"
544a170ead2catagen2026-10-20 11:47 UTC190
  class:own={event.own}
544a170ead2catagen2026-10-20 11:47 UTC191
  class:system={!interactive}
544a170ead2catagen2026-10-20 11:47 UTC192
  class:selected
544a170ead2catagen2026-10-20 11:47 UTC193
  data-item={itemId}
544a170ead2catagen2026-10-20 11:47 UTC194
  bind:this={row}
544a170ead2catagen2026-10-20 11:47 UTC195
  on:click={toggleSelected}
544a170ead2catagen2026-10-20 11:47 UTC196
>
544a170ead2catagen2026-10-20 11:47 UTC197
  {#if interactive && event.event_id}
544a170ead2catagen2026-10-20 11:47 UTC198
    <div class="actions" role="toolbar" aria-label={`Actions for message from ${displayName}`}>
544a170ead2catagen2026-10-20 11:47 UTC199
      {#each quickReactions as r (r.key)}
544a170ead2catagen2026-10-20 11:47 UTC200
        {@const label = r.shortcode ? `:${r.shortcode}:` : r.key}
544a170ead2catagen2026-10-20 11:47 UTC201
        <button
544a170ead2catagen2026-10-20 11:47 UTC202
          type="button"
544a170ead2catagen2026-10-20 11:47 UTC203
          title={`React ${label}`}
544a170ead2catagen2026-10-20 11:47 UTC204
          aria-label={`React ${label} to message from ${displayName}`}
544a170ead2catagen2026-10-20 11:47 UTC205
          disabled={reacting}
ecb8598b38afatagen2026-10-22 09:19 UTC206
          on:click={() => react(r.key, r.shortcode)}
544a170ead2catagen2026-10-20 11:47 UTC207
        >
544a170ead2catagen2026-10-20 11:47 UTC208
          {#if r.key.startsWith('mxc://')}
544a170ead2catagen2026-10-20 11:47 UTC209
            <img class="emote" src={mediaUrl(r.key) ?? ''} alt="" />
544a170ead2catagen2026-10-20 11:47 UTC210
          {:else}
544a170ead2catagen2026-10-20 11:47 UTC211
            <Emoji emoji={r.key} size={18} />
544a170ead2catagen2026-10-20 11:47 UTC212
          {/if}
544a170ead2catagen2026-10-20 11:47 UTC213
        </button>
544a170ead2catagen2026-10-20 11:47 UTC214
      {/each}
544a170ead2catagen2026-10-20 11:47 UTC215
      <button
544a170ead2catagen2026-10-20 11:47 UTC216
        type="button"
544a170ead2catagen2026-10-20 11:47 UTC217
        title="Add reaction"
544a170ead2catagen2026-10-20 11:47 UTC218
        aria-label={`Add reaction to message from ${displayName}`}
544a170ead2catagen2026-10-20 11:47 UTC219
        aria-haspopup="dialog"
544a170ead2catagen2026-10-20 11:47 UTC220
        aria-expanded={pickerOpen}
544a170ead2catagen2026-10-20 11:47 UTC221
        on:pointerdown|stopPropagation
544a170ead2catagen2026-10-20 11:47 UTC222
        on:click={openPicker}
544a170ead2catagen2026-10-20 11:47 UTC223
      >
544a170ead2catagen2026-10-20 11:47 UTC224
        ☺+
544a170ead2catagen2026-10-20 11:47 UTC225
      </button>
544a170ead2catagen2026-10-20 11:47 UTC226
    </div>
544a170ead2catagen2026-10-20 11:47 UTC227
    {#if pickerOpen}
544a170ead2catagen2026-10-20 11:47 UTC228
      <div class="picker-pop" style={pickerStyle} bind:this={pickerPop}>
ecb8598b38afatagen2026-10-22 09:19 UTC229
        <ReactionPicker {packs} quick={quickReactions} onPick={pick} {onQuickChange} onClose={closePicker} />
544a170ead2catagen2026-10-20 11:47 UTC230
      </div>
544a170ead2catagen2026-10-20 11:47 UTC231
    {/if}
544a170ead2catagen2026-10-20 11:47 UTC232
  {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC233
  {#if showSender}
973f8fbdaf80atagen2026-09-28 09:10 UTC234
    {#if senderAvatar}
973f8fbdaf80atagen2026-09-28 09:10 UTC235
      <MxcAvatar mxc={senderAvatar} label={name} size={34} />
973f8fbdaf80atagen2026-09-28 09:10 UTC236
    {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC237
      <div
973f8fbdaf80atagen2026-09-28 09:10 UTC238
        class="avatar"
973f8fbdaf80atagen2026-09-28 09:10 UTC239
        aria-hidden="true"
973f8fbdaf80atagen2026-09-28 09:10 UTC240
        style={`background:hsl(${senderHue(event.sender.user_id)} 35% 32%)`}
973f8fbdaf80atagen2026-09-28 09:10 UTC241
      >
973f8fbdaf80atagen2026-09-28 09:10 UTC242
        {initialsOf(name)}
973f8fbdaf80atagen2026-09-28 09:10 UTC243
      </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC244
    {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC245
  {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC246
    <div class="avatar-spacer" aria-hidden="true">
973f8fbdaf80atagen2026-09-28 09:10 UTC247
      <span class="hover-time">{formatClock(event.timestamp_ms)}</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC248
    </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC249
  {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC250
  <div class="msg-body">
973f8fbdaf80atagen2026-09-28 09:10 UTC251
    {#if showSender}
973f8fbdaf80atagen2026-09-28 09:10 UTC252
      <div class="msg-head">
973f8fbdaf80atagen2026-09-28 09:10 UTC253
        <span class="sender" style={`color:hsl(${senderHue(event.sender.user_id)} 70% 72%)`}>
973f8fbdaf80atagen2026-09-28 09:10 UTC254
          {displayName}
973f8fbdaf80atagen2026-09-28 09:10 UTC255
        </span>
973f8fbdaf80atagen2026-09-28 09:10 UTC256
        <time class="time" datetime={new Date(event.timestamp_ms).toISOString()}>
973f8fbdaf80atagen2026-09-28 09:10 UTC257
          {formatDay(event.timestamp_ms)} {formatClock(event.timestamp_ms)}
973f8fbdaf80atagen2026-09-28 09:10 UTC258
        </time>
973f8fbdaf80atagen2026-09-28 09:10 UTC259
        {#if event.content.kind === 'Message' && event.content.message.edited}
973f8fbdaf80atagen2026-09-28 09:10 UTC260
          <span class="edited" title="Edited">(edited)</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC261
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC262
      </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC263
    {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC264
    {#if event.reply_to}
973f8fbdaf80atagen2026-09-28 09:10 UTC265
      <div class="reply-quote">
973f8fbdaf80atagen2026-09-28 09:10 UTC266
        {#if event.reply_to.details.kind === 'Ready'}
544a170ead2catagen2026-10-20 11:47 UTC267
          Replying to {senderLabel(event.reply_to.details.sender)}: <EmojiText text={replyPreview(event.reply_to.details.content)} />
973f8fbdaf80atagen2026-09-28 09:10 UTC268
        {:else if event.reply_to.details.kind === 'Pending'}
973f8fbdaf80atagen2026-09-28 09:10 UTC269
          Loading reply…
973f8fbdaf80atagen2026-09-28 09:10 UTC270
        {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC271
          Reply unavailable
973f8fbdaf80atagen2026-09-28 09:10 UTC272
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC273
      </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC274
    {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC275
973f8fbdaf80atagen2026-09-28 09:10 UTC276
    {#if event.content.kind === 'Message'}
973f8fbdaf80atagen2026-09-28 09:10 UTC277
      {@const m = event.content.message}
973f8fbdaf80atagen2026-09-28 09:10 UTC278
      <p class="text" class:emote={m.kind === 'Emote'} class:notice={m.kind === 'Notice' || m.kind === 'ServerNotice'}>
544a170ead2catagen2026-10-20 11:47 UTC279
        {#if m.kind === 'Emote'}* {displayName} {/if}<EmojiText text={m.body} jumbo={m.kind === 'Text'} />
973f8fbdaf80atagen2026-09-28 09:10 UTC280
      </p>
973f8fbdaf80atagen2026-09-28 09:10 UTC281
      {#if m.media}
973f8fbdaf80atagen2026-09-28 09:10 UTC282
        <MediaAttachmentView attachment={m.media} />
973f8fbdaf80atagen2026-09-28 09:10 UTC283
      {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC284
      {#if previews.length > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC285
        <div class="link-previews">
973f8fbdaf80atagen2026-09-28 09:10 UTC286
          {#each previews as preview (preview.href)}
ecb8598b38afatagen2026-10-22 09:19 UTC287
            <LinkCard link={preview} preview={bundled.find((b) => b.url === preview.href) ?? linkPreviews[preview.href] ?? null} />
973f8fbdaf80atagen2026-09-28 09:10 UTC288
          {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC289
        </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC290
      {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC291
    {:else if event.content.kind === 'Sticker'}
544a170ead2catagen2026-10-20 11:47 UTC292
      {#if event.content.body}<p class="text"><EmojiText text={event.content.body} /></p>{/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC293
      {#if event.content.media}
973f8fbdaf80atagen2026-09-28 09:10 UTC294
        <MediaAttachmentView attachment={event.content.media} />
973f8fbdaf80atagen2026-09-28 09:10 UTC295
      {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC296
    {:else if event.content.kind === 'Poll'}
973f8fbdaf80atagen2026-09-28 09:10 UTC297
      <p class="text">📊 {event.content.question}</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC298
    {:else}
973f8fbdaf80atagen2026-09-28 09:10 UTC299
      <p class="system-line">{systemLine(event.content)}</p>
973f8fbdaf80atagen2026-09-28 09:10 UTC300
    {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC301
973f8fbdaf80atagen2026-09-28 09:10 UTC302
    {#if interactive && event.reactions.length > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC303
      <div class="reactions" aria-label="Reactions">
973f8fbdaf80atagen2026-09-28 09:10 UTC304
        {#each event.reactions as r (r.key)}
973f8fbdaf80atagen2026-09-28 09:10 UTC305
          <button
973f8fbdaf80atagen2026-09-28 09:10 UTC306
            type="button"
973f8fbdaf80atagen2026-09-28 09:10 UTC307
            class="reaction"
973f8fbdaf80atagen2026-09-28 09:10 UTC308
            class:mine={r.own}
973f8fbdaf80atagen2026-09-28 09:10 UTC309
            title={r.own ? 'You reacted — activate to remove' : `${r.count} reaction${r.count === 1 ? '' : 's'}`}
973f8fbdaf80atagen2026-09-28 09:10 UTC310
            disabled={!event.event_id || reacting}
973f8fbdaf80atagen2026-09-28 09:10 UTC311
            on:click={() => event.event_id && onReact(event.event_id, r.key)}
973f8fbdaf80atagen2026-09-28 09:10 UTC312
          >
ecb8598b38afatagen2026-10-22 09:19 UTC313
            {#if r.image}
ecb8598b38afatagen2026-10-22 09:19 UTC314
              <img class="emote" src={messageMediaUrl(r.image, 'Thumbnail')} alt={r.shortcode ?? ''} title={r.shortcode ?? ''} />
ecb8598b38afatagen2026-10-22 09:19 UTC315
            {:else if r.key.startsWith('mxc://')}
544a170ead2catagen2026-10-20 11:47 UTC316
              <img class="emote" src={mediaUrl(r.key) ?? ''} alt="" />
544a170ead2catagen2026-10-20 11:47 UTC317
            {:else}
544a170ead2catagen2026-10-20 11:47 UTC318
              <Emoji emoji={r.key} size={16} />
544a170ead2catagen2026-10-20 11:47 UTC319
            {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC320
            <span class="count">{r.count}</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC321
          </button>
973f8fbdaf80atagen2026-09-28 09:10 UTC322
        {/each}
973f8fbdaf80atagen2026-09-28 09:10 UTC323
      </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC324
    {/if}
544a170ead2catagen2026-10-20 11:47 UTC325
    {#if interactive && (sendLabel(event.send_state) || event.read_by.length > 0)}
973f8fbdaf80atagen2026-09-28 09:10 UTC326
      <div class="msg-foot">
973f8fbdaf80atagen2026-09-28 09:10 UTC327
        {#if sendLabel(event.send_state)}
973f8fbdaf80atagen2026-09-28 09:10 UTC328
          <span class="sendstate" class:failed={event.send_state.kind === 'Failed'}>{sendLabel(event.send_state)}</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC329
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC330
        {#if event.read_by.length > 0}
973f8fbdaf80atagen2026-09-28 09:10 UTC331
          <span class="readby" title={event.read_by.join(', ')}>✓✓ {event.read_by.length}</span>
973f8fbdaf80atagen2026-09-28 09:10 UTC332
        {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC333
      </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC334
    {/if}
973f8fbdaf80atagen2026-09-28 09:10 UTC335
  </div>
973f8fbdaf80atagen2026-09-28 09:10 UTC336
</div>
973f8fbdaf80atagen2026-09-28 09:10 UTC337
973f8fbdaf80atagen2026-09-28 09:10 UTC338
<style>
544a170ead2catagen2026-10-20 11:47 UTC339
  .msg { position: relative; display: flex; gap: 10px; padding: 3px 0; }
544a170ead2catagen2026-10-20 11:47 UTC340
  .msg:hover, .msg.selected { background: rgba(255, 255, 255, 0.018); }
544a170ead2catagen2026-10-20 11:47 UTC341
  .msg:hover .hover-time, .msg.selected .hover-time { opacity: 1; }
544a170ead2catagen2026-10-20 11:47 UTC342
  .msg-foot { display: flex; align-items: center; gap: 8px; }
973f8fbdaf80atagen2026-09-28 09:10 UTC343
  .sendstate { font-size: 11px; color: var(--muted); }
973f8fbdaf80atagen2026-09-28 09:10 UTC344
  .sendstate.failed { color: var(--danger); }
973f8fbdaf80atagen2026-09-28 09:10 UTC345
  .link-previews { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; max-width: 420px; }
973f8fbdaf80atagen2026-09-28 09:10 UTC346
  .avatar {
973f8fbdaf80atagen2026-09-28 09:10 UTC347
    flex: none;
973f8fbdaf80atagen2026-09-28 09:10 UTC348
    width: 34px; height: 34px;
973f8fbdaf80atagen2026-09-28 09:10 UTC349
    border-radius: 50%;
973f8fbdaf80atagen2026-09-28 09:10 UTC350
    display: grid; place-items: center;
973f8fbdaf80atagen2026-09-28 09:10 UTC351
    font-size: 12px; font-weight: 700; color: #fff;
973f8fbdaf80atagen2026-09-28 09:10 UTC352
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC353
  .avatar-spacer { flex: none; width: 34px; padding-top: 2px; text-align: center; }
973f8fbdaf80atagen2026-09-28 09:10 UTC354
  .hover-time { opacity: 0; font-size: 10.5px; color: var(--muted); }
973f8fbdaf80atagen2026-09-28 09:10 UTC355
  .msg-body { min-width: 0; flex: 1; }
973f8fbdaf80atagen2026-09-28 09:10 UTC356
  .msg-head { display: flex; align-items: baseline; gap: 8px; }
973f8fbdaf80atagen2026-09-28 09:10 UTC357
  .sender { font-weight: 650; font-size: 13.5px; }
973f8fbdaf80atagen2026-09-28 09:10 UTC358
  .time, .edited { color: var(--muted); font-size: 11.5px; }
973f8fbdaf80atagen2026-09-28 09:10 UTC359
  .reply-quote {
973f8fbdaf80atagen2026-09-28 09:10 UTC360
    border-left: 2px solid var(--accent);
973f8fbdaf80atagen2026-09-28 09:10 UTC361
    padding: 2px 8px;
973f8fbdaf80atagen2026-09-28 09:10 UTC362
    margin: 2px 0 4px;
973f8fbdaf80atagen2026-09-28 09:10 UTC363
    color: var(--muted);
973f8fbdaf80atagen2026-09-28 09:10 UTC364
    font-size: 12.5px;
973f8fbdaf80atagen2026-09-28 09:10 UTC365
    background: var(--bg-soft);
973f8fbdaf80atagen2026-09-28 09:10 UTC366
    border-radius: 0 6px 6px 0;
973f8fbdaf80atagen2026-09-28 09:10 UTC367
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC368
  .text {
973f8fbdaf80atagen2026-09-28 09:10 UTC369
    margin: 1px 0 2px;
973f8fbdaf80atagen2026-09-28 09:10 UTC370
    font-size: 14px;
973f8fbdaf80atagen2026-09-28 09:10 UTC371
    line-height: 1.5;
973f8fbdaf80atagen2026-09-28 09:10 UTC372
    white-space: pre-wrap;
973f8fbdaf80atagen2026-09-28 09:10 UTC373
    overflow-wrap: anywhere;
973f8fbdaf80atagen2026-09-28 09:10 UTC374
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC375
  .text.emote { font-style: italic; color: var(--muted); }
973f8fbdaf80atagen2026-09-28 09:10 UTC376
  .text.notice { color: var(--muted); }
973f8fbdaf80atagen2026-09-28 09:10 UTC377
  .system-line { color: var(--muted); font-size: 12.5px; font-style: italic; margin: 1px 0; }
973f8fbdaf80atagen2026-09-28 09:10 UTC378
  .msg.system { opacity: 0.85; }
973f8fbdaf80atagen2026-09-28 09:10 UTC379
  .reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
973f8fbdaf80atagen2026-09-28 09:10 UTC380
  .reaction {
973f8fbdaf80atagen2026-09-28 09:10 UTC381
    display: inline-flex; align-items: center; gap: 4px;
973f8fbdaf80atagen2026-09-28 09:10 UTC382
    background: var(--bg-soft);
973f8fbdaf80atagen2026-09-28 09:10 UTC383
    border: 1px solid var(--border);
973f8fbdaf80atagen2026-09-28 09:10 UTC384
    border-radius: 999px;
973f8fbdaf80atagen2026-09-28 09:10 UTC385
    padding: 1px 8px;
973f8fbdaf80atagen2026-09-28 09:10 UTC386
    font-size: 13px;
973f8fbdaf80atagen2026-09-28 09:10 UTC387
    color: var(--text);
973f8fbdaf80atagen2026-09-28 09:10 UTC388
    cursor: pointer;
973f8fbdaf80atagen2026-09-28 09:10 UTC389
  }
973f8fbdaf80atagen2026-09-28 09:10 UTC390
  .reaction.mine { border-color: var(--accent); background: rgba(88, 101, 242, 0.16); }
973f8fbdaf80atagen2026-09-28 09:10 UTC391
  .reaction:disabled { cursor: default; opacity: 0.85; }
973f8fbdaf80atagen2026-09-28 09:10 UTC392
  .readby { font-size: 11px; color: var(--muted); }
544a170ead2catagen2026-10-20 11:47 UTC393
  .actions {
544a170ead2catagen2026-10-20 11:47 UTC394
    position: absolute; top: -14px; right: 12px; z-index: 2;
544a170ead2catagen2026-10-20 11:47 UTC395
    display: flex; gap: 2px;
544a170ead2catagen2026-10-20 11:47 UTC396
    padding: 2px;
544a170ead2catagen2026-10-20 11:47 UTC397
    background: var(--bg-soft);
544a170ead2catagen2026-10-20 11:47 UTC398
    border: 1px solid var(--border);
544a170ead2catagen2026-10-20 11:47 UTC399
    border-radius: 8px;
544a170ead2catagen2026-10-20 11:47 UTC400
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
544a170ead2catagen2026-10-20 11:47 UTC401
    opacity: 0;
544a170ead2catagen2026-10-20 11:47 UTC402
    pointer-events: none;
544a170ead2catagen2026-10-20 11:47 UTC403
  }
544a170ead2catagen2026-10-20 11:47 UTC404
  .msg:hover .actions, .msg:focus-within .actions, .msg.selected .actions { opacity: 1; pointer-events: auto; }
544a170ead2catagen2026-10-20 11:47 UTC405
  .actions button {
973f8fbdaf80atagen2026-09-28 09:10 UTC406
    background: transparent;
973f8fbdaf80atagen2026-09-28 09:10 UTC407
    border: 1px solid transparent;
973f8fbdaf80atagen2026-09-28 09:10 UTC408
    border-radius: 6px;
973f8fbdaf80atagen2026-09-28 09:10 UTC409
    cursor: pointer;
544a170ead2catagen2026-10-20 11:47 UTC410
    font-size: 14px;
544a170ead2catagen2026-10-20 11:47 UTC411
    padding: 1px 5px;
973f8fbdaf80atagen2026-09-28 09:10 UTC412
  }
544a170ead2catagen2026-10-20 11:47 UTC413
  .actions button:hover:not(:disabled) { border-color: var(--border); background: rgba(255, 255, 255, 0.06); }
544a170ead2catagen2026-10-20 11:47 UTC414
  .actions button:disabled { opacity: 0.4; cursor: default; }
544a170ead2catagen2026-10-20 11:47 UTC415
  .emote { width: 1.3em; height: 1.3em; object-fit: contain; vertical-align: middle; }
544a170ead2catagen2026-10-20 11:47 UTC416
  .picker-pop { position: fixed; z-index: 60; width: 320px; max-width: calc(100vw - 16px); }
973f8fbdaf80atagen2026-09-28 09:10 UTC417
</style>