atagen

malice

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