2026-07-03 16:20:45 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from "svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {matchTag, tagSpec} from "@welshman/util"
|
2026-07-03 16:20:45 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
|
|
|
|
import InboxOut from "@assets/icons/inbox-out.svg?dataurl"
|
|
|
|
|
import MinusCircle from "@assets/icons/minus-circle.svg?dataurl"
|
|
|
|
|
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
|
|
|
|
|
import Close from "@assets/icons/close.svg?dataurl"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Confirm from "@lib/components/Confirm.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {app, deletes, profiles, relayManagement, relays, user} from "@app/core"
|
|
|
|
|
import {deriveUserIsSpaceAdmin} from "@app/management"
|
2026-07-03 16:20:45 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
|
|
|
|
import {pushModal} from "@app/modal"
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
event: TrustedEvent
|
|
|
|
|
onResolved?: () => void
|
|
|
|
|
onClick: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, event, onResolved, onClick}: Props = $props()
|
|
|
|
|
|
|
|
|
|
const userIsAdmin = deriveUserIsSpaceAdmin(url)
|
2026-07-28 16:16:26 +00:00
|
|
|
const etag = matchTag(tagSpec("e"), event.tags)
|
|
|
|
|
const ptag = matchTag(tagSpec("p"), event.tags)
|
2026-07-03 16:20:45 +00:00
|
|
|
|
|
|
|
|
const deleteReport = async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const protect = await $relays.hasNip(url, 70)
|
|
|
|
|
const command = await $deletes.deleteEvent(event, w => w.setProtected(protect))
|
|
|
|
|
|
|
|
|
|
command.publishToRelays([url])
|
2026-07-03 16:20:45 +00:00
|
|
|
onResolved?.()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dismissReport = async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement.forUrl(url).banEvent(event.id, "Dismissed by admin")
|
2026-07-03 16:20:45 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "Content has successfully been deleted!"})
|
2026-07-28 16:16:26 +00:00
|
|
|
$app.repository.removeEvent(event.id)
|
2026-07-03 16:20:45 +00:00
|
|
|
onResolved?.()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const banContent = () => {
|
|
|
|
|
const [_, id, reason = ""] = etag!
|
|
|
|
|
|
|
|
|
|
pushModal(Confirm, {
|
|
|
|
|
title: `Remove Content`,
|
|
|
|
|
message: `Are you sure you want to delete this content from the space?`,
|
|
|
|
|
confirm: async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement.forUrl(url).banEvent(id, reason)
|
2026-07-03 16:20:45 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "Content has successfully been deleted!"})
|
2026-07-28 16:16:26 +00:00
|
|
|
$app.repository.removeEvent(event.id)
|
|
|
|
|
$app.repository.removeEvent(id)
|
2026-07-03 16:20:45 +00:00
|
|
|
history.back()
|
|
|
|
|
setTimeout(() => onResolved?.())
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const banMember = () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const [_, reported, reason = ""] = ptag!
|
2026-07-03 16:20:45 +00:00
|
|
|
|
|
|
|
|
pushModal(Confirm, {
|
|
|
|
|
title: "Ban User",
|
2026-07-28 16:16:26 +00:00
|
|
|
message: `Are you sure you want to ban @${$profiles.display(reported).get()} from the space?`,
|
2026-07-03 16:20:45 +00:00
|
|
|
confirm: async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement.forUrl(url).banPubkey(reported, reason)
|
2026-07-03 16:20:45 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "User has successfully been banned!"})
|
2026-07-28 16:16:26 +00:00
|
|
|
$app.repository.removeEvent(event.id)
|
2026-07-03 16:20:45 +00:00
|
|
|
history.back()
|
|
|
|
|
setTimeout(() => onResolved?.())
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let ul: Element
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
ul.addEventListener("click", onClick)
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<ul class="menu whitespace-nowrap rounded-2xl bg-surface p-2" bind:this={ul}>
|
2026-07-28 16:16:26 +00:00
|
|
|
{#if event.pubkey === $user.pubkey}
|
2026-07-03 16:20:45 +00:00
|
|
|
<li>
|
|
|
|
|
<Button onclick={deleteReport}>
|
|
|
|
|
<Icon icon={Close} />
|
|
|
|
|
Delete Report
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if $userIsAdmin}
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={dismissReport}>
|
|
|
|
|
<Icon icon={InboxOut} />
|
|
|
|
|
Dismiss Report
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{#if etag}
|
|
|
|
|
<li>
|
|
|
|
|
<Button class="text-error" onclick={banContent}>
|
|
|
|
|
<Icon icon={TrashBin2} />
|
|
|
|
|
Remove Content
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if ptag}
|
|
|
|
|
<li>
|
|
|
|
|
<Button class="text-error" onclick={banMember}>
|
|
|
|
|
<Icon icon={MinusCircle} />
|
|
|
|
|
Ban User
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
|
|
|
|
{/if}
|
|
|
|
|
</ul>
|