d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 1 | <script lang="ts" context="module"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 2 | export type UserAction = |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 3 | | { kind: 'message' | 'mention' | 'unban' | 'mute' | 'unmute' | 'ignore' | 'unignore' } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 4 | | { kind: 'kick' | 'ban'; reason: string | null } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 5 | | { kind: 'power'; level: number }; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 6 | </script> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 7 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 8 | <script lang="ts"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 9 | import { onMount, tick } from 'svelte'; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 10 | import MxcAvatar from './MxcAvatar.svelte'; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 11 | import { allowed, isMuted, levelOf, roleName, type PowerLevels } from './permissions'; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 12 | import type { MemberSummary, Person } from './types'; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 13 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 14 | export let person: Person; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 15 | export let member: MemberSummary | null = null; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 16 | export let levels: PowerLevels | null = null; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 17 | export let self: string | null = null; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 18 | export let x: number; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 19 | export let y: number; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 20 | export let confirm: 'kick' | 'ban' | null = null; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 21 | export let onAction: (action: UserAction) => void; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 22 | export let onClose: () => void; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 23 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 24 | const MARGIN = 8; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 25 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 26 | let card: HTMLDivElement; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 27 | let left = x; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 28 | let top = y; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 29 | let reason = ''; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 30 | let copied = false; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 31 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 32 | $: own = person.user_id === self; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 33 | $: level = levels ? levelOf(levels, person.user_id) : null; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 34 | $: role = level !== null ? roleName(level) : null; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 35 | $: muted = levels ? isMuted(levels, person.user_id) : false; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 36 | $: can = levels && self ? allowed(levels, self, person.user_id) : null; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 37 | $: banned = member?.membership === 'Ban'; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 38 | $: powerInput = level !== null && Number.isFinite(level) ? String(level) : ''; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 39 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 40 | onMount(async () => { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 41 | await tick(); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 42 | const rect = card.getBoundingClientRect(); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 43 | left = Math.max(MARGIN, Math.min(x, window.innerWidth - rect.width - MARGIN)); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 44 | top = Math.max(MARGIN, Math.min(y, window.innerHeight - rect.height - MARGIN)); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 45 | }); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 46 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 47 | function act(action: UserAction): void { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 48 | onClose(); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 49 | onAction(action); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 50 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 51 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 52 | function setPower(): void { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 53 | const value = Number(powerInput); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 54 | if (!Number.isInteger(value) || value === level) return; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 55 | act({ kind: 'power', level: value }); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 56 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 57 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 58 | async function copyId(): Promise<void> { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 59 | try { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 60 | await navigator.clipboard.writeText(person.user_id); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 61 | copied = true; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 62 | window.setTimeout(() => (copied = false), 1500); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 63 | } catch { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 64 | copied = false; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 65 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 66 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 67 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 68 | function outside(ev: PointerEvent): void { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 69 | if (!card.contains(ev.target as Node)) onClose(); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 70 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 71 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 72 | function key(ev: KeyboardEvent): void { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 73 | if (ev.key !== 'Escape') return; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 74 | ev.stopPropagation(); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 75 | if (confirm) confirm = null; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 76 | else onClose(); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 77 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 78 | </script> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 79 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 80 | <svelte:window on:pointerdown|capture={outside} on:keydown|capture={key} on:resize={onClose} /> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 81 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 82 | <div class="user-card" role="dialog" aria-label={person.name} style={`left:${left}px;top:${top}px`} bind:this={card}> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 83 | <div class="identity"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 84 | <MxcAvatar mxc={person.avatar} label={person.name} size={64} /> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 85 | <div class="names"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 86 | <strong class="name">{person.name}</strong> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 87 | <button type="button" class="user-id" title="Copy user ID" on:click={() => void copyId()}> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 88 | {copied ? 'Copied' : person.user_id} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 89 | </button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 90 | <div class="tags"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 91 | {#if role}<span class="tag">{role}</span>{/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 92 | {#if level !== null && Number.isFinite(level) && level !== 0}<span class="tag">Power {level}</span>{/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 93 | {#if muted}<span class="tag warn">Muted</span>{/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 94 | {#if banned}<span class="tag danger">Banned</span>{/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 95 | {#if member?.ignored}<span class="tag">Ignored</span>{/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 96 | </div> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 97 | </div> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 98 | </div> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 99 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 100 | {#if confirm} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 101 | <form class="confirm" on:submit|preventDefault={() => confirm && act({ kind: confirm, reason: reason.trim() || null })}> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 102 | <!-- svelte-ignore a11y_autofocus --> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 103 | <input type="text" placeholder="Reason" bind:value={reason} autofocus /> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 104 | <div class="row"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 105 | <button type="button" class="ghost-btn" on:click={() => (confirm = null)}>Cancel</button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 106 | <button type="submit" class="ghost-btn danger">{confirm === 'kick' ? 'Kick' : 'Ban'} {person.name}</button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 107 | </div> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 108 | </form> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 109 | {:else} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 110 | <div class="row"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 111 | {#if !own} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 112 | <button type="button" class="ghost-btn" on:click={() => act({ kind: 'message' })}>Message</button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 113 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 114 | <button type="button" class="ghost-btn" on:click={() => act({ kind: 'mention' })}>Mention</button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 115 | </div> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 116 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 117 | {#if can && (can.kick || can.ban || can.setLevel)} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 118 | <div class="row"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 119 | {#if can.setLevel && !own} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 120 | <button type="button" class="ghost-btn" on:click={() => act({ kind: muted ? 'unmute' : 'mute' })}> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 121 | {muted ? 'Unmute' : 'Mute'} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 122 | </button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 123 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 124 | {#if can.kick && !banned && member && member.membership !== 'Leave'} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 125 | <button type="button" class="ghost-btn danger" on:click={() => (confirm = 'kick')}>Kick</button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 126 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 127 | {#if can.ban} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 128 | {#if banned} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 129 | <button type="button" class="ghost-btn" on:click={() => act({ kind: 'unban' })}>Unban</button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 130 | {:else} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 131 | <button type="button" class="ghost-btn danger" on:click={() => (confirm = 'ban')}>Ban</button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 132 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 133 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 134 | </div> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 135 | {#if can.setLevel} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 136 | <form class="row power" on:submit|preventDefault={setPower}> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 137 | <label for="power-level">Power level</label> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 138 | <input id="power-level" type="number" step="1" max={Number.isFinite(can.maxLevel) ? can.maxLevel : undefined} bind:value={powerInput} /> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 139 | <button type="submit" class="ghost-btn" disabled={powerInput === '' || Number(powerInput) === level}>Set</button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 140 | </form> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 141 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 142 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 143 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 144 | {#if !own} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 145 | <div class="row"> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 146 | <button type="button" class="ghost-btn subtle" on:click={() => act({ kind: member?.ignored ? 'unignore' : 'ignore' })}> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 147 | {member?.ignored ? 'Unignore' : 'Ignore'} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 148 | </button> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 149 | </div> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 150 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 151 | {/if} |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 152 | </div> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 153 | |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 154 | <style> |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 155 | .user-card { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 156 | position: fixed; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 157 | z-index: 90; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 158 | width: 300px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 159 | max-width: calc(100vw - 16px); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 160 | display: flex; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 161 | flex-direction: column; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 162 | gap: 10px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 163 | padding: 14px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 164 | background: var(--panel-2); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 165 | border: 1px solid var(--border); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 166 | border-radius: 12px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 167 | box-shadow: 0 12px 32px rgb(0 0 0 / 0.4); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 168 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 169 | .identity { display: flex; gap: 12px; align-items: center; } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 170 | .names { display: flex; flex-direction: column; gap: 2px; min-width: 0; } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 171 | .name { font-size: 16px; overflow-wrap: anywhere; } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 172 | .user-id { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 173 | padding: 0; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 174 | border: none; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 175 | background: none; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 176 | color: var(--muted); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 177 | font: inherit; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 178 | font-size: 12.5px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 179 | text-align: left; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 180 | cursor: copy; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 181 | overflow-wrap: anywhere; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 182 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 183 | .user-id:hover { color: var(--text); } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 184 | .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 185 | .tag { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 186 | font-size: 11px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 187 | padding: 1px 6px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 188 | border-radius: 999px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 189 | border: 1px solid var(--border); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 190 | color: var(--muted); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 191 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 192 | .tag.warn { color: var(--warn-text); border-color: var(--warn-border); } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 193 | .tag.danger { color: var(--danger); border-color: var(--danger-border); } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 194 | .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 195 | .row > :global(.ghost-btn) { flex: 1; } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 196 | .power label { font-size: 12.5px; color: var(--muted); } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 197 | .power input { width: 80px; flex: 1; } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 198 | input { |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 199 | background: var(--bg-soft); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 200 | border: 1px solid var(--border); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 201 | border-radius: 6px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 202 | color: var(--text); |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 203 | padding: 5px 8px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 204 | font: inherit; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 205 | font-size: 13px; |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 206 | } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 207 | .confirm { display: flex; flex-direction: column; gap: 8px; } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 208 | .subtle { color: var(--muted); } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 209 | </style> |