2024-12-16 20:54:17 +00:00
|
|
|
<script lang="ts">
|
2026-02-10 00:57:44 +00:00
|
|
|
import {onMount} from "svelte"
|
2026-08-21 20:47:06 +00:00
|
|
|
import {removeUndefined, spec} from "@welshman/lib"
|
2025-09-10 22:26:39 +00:00
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
2026-06-18 10:52:04 +00:00
|
|
|
import UserCircle from "@assets/icons/user-circle.svg?dataurl"
|
2025-11-13 21:44:52 +00:00
|
|
|
import MinusCircle from "@assets/icons/minus-circle.svg?dataurl"
|
2026-06-30 17:02:02 +00:00
|
|
|
import UserMinus from "@assets/icons/user-minus.svg?dataurl"
|
2026-09-08 18:04:37 +00:00
|
|
|
import Letter from "@assets/icons/letter-opened.svg?dataurl"
|
2026-02-13 21:05:17 +00:00
|
|
|
import Restart from "@assets/icons/restart.svg?dataurl"
|
2024-12-16 20:54:17 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2025-11-13 21:44:52 +00:00
|
|
|
import Confirm from "@lib/components/Confirm.svelte"
|
2024-12-16 20:54:17 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
2026-01-30 22:14:12 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
2024-12-16 20:54:17 +00:00
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
2025-05-29 21:30:22 +00:00
|
|
|
import Profile from "@app/components/Profile.svelte"
|
2026-07-03 00:01:31 +00:00
|
|
|
import ProfileAbout from "@app/components/ProfileAbout.svelte"
|
2025-06-05 20:01:36 +00:00
|
|
|
import ProfileBadges from "@app/components/ProfileBadges.svelte"
|
2026-07-03 00:27:28 +00:00
|
|
|
import ProfileMenu from "@app/components/ProfileMenu.svelte"
|
2026-09-11 00:37:37 +00:00
|
|
|
import ProfilePinnedNote from "@app/components/ProfilePinnedNote.svelte"
|
2026-09-11 00:12:19 +00:00
|
|
|
import ProfileStatus from "@app/components/ProfileStatus.svelte"
|
2026-09-08 18:04:37 +00:00
|
|
|
import {messagingRelayLists, profiles, relayManagement, user} from "@app/core"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {deriveUserIsSpaceAdmin} from "@app/management"
|
2026-09-08 18:04:37 +00:00
|
|
|
import {navigate, popModal, pushModal} from "@app/modal"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
2026-09-08 18:04:37 +00:00
|
|
|
import {goToChat, makeProfilePath} from "@app/routes"
|
2024-12-16 20:54:17 +00:00
|
|
|
|
2025-04-15 18:03:27 +00:00
|
|
|
export type Props = {
|
|
|
|
|
pubkey: string
|
|
|
|
|
url?: string
|
|
|
|
|
}
|
2024-12-16 20:54:17 +00:00
|
|
|
|
2025-04-15 18:03:27 +00:00
|
|
|
const {pubkey, url}: Props = $props()
|
|
|
|
|
|
2025-11-13 21:44:52 +00:00
|
|
|
const userIsAdmin = deriveUserIsSpaceAdmin(url)
|
|
|
|
|
|
2026-09-08 18:04:37 +00:00
|
|
|
const isSelf = $derived($user.pubkey === pubkey)
|
|
|
|
|
|
2024-12-16 20:54:17 +00:00
|
|
|
const back = () => history.back()
|
|
|
|
|
|
2026-09-08 17:23:22 +00:00
|
|
|
const viewProfile = () => navigate(makeProfilePath(pubkey), {replaceState: true})
|
2025-11-13 21:44:52 +00:00
|
|
|
|
2026-09-08 18:04:37 +00:00
|
|
|
const sendMessage = () => {
|
|
|
|
|
popModal()
|
|
|
|
|
goToChat([pubkey])
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const report = (error: string | undefined, message: string) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message})
|
|
|
|
|
back()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-13 21:44:52 +00:00
|
|
|
const banMember = () =>
|
|
|
|
|
pushModal(Confirm, {
|
|
|
|
|
title: "Ban User",
|
2026-08-21 20:47:06 +00:00
|
|
|
message: `Are you sure you want to ban @${$profiles.display(pubkey, removeUndefined([url])).get()} from the space?`,
|
2025-11-13 21:44:52 +00:00
|
|
|
confirm: async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement.forUrl(url!).banPubkey(pubkey)
|
|
|
|
|
|
|
|
|
|
report(error, "User has successfully been banned!")
|
2025-11-13 21:44:52 +00:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2026-06-30 17:02:02 +00:00
|
|
|
const removeMember = async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement.forUrl(url!).unallowPubkey(pubkey)
|
2026-06-30 17:02:02 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
report(error, "User has successfully been removed!")
|
2026-06-30 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-13 21:05:17 +00:00
|
|
|
const restoreMember = async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement.forUrl(url!).allowPubkey(pubkey)
|
2026-02-13 21:05:17 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
report(error, "User has successfully been restored!")
|
2026-02-13 21:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
let isBanned = $state(false)
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
|
if (url && $userIsAdmin) {
|
|
|
|
|
$relayManagement
|
|
|
|
|
.forUrl(url)
|
|
|
|
|
.listBannedPubkeys()
|
|
|
|
|
.then(({result = []}) => {
|
|
|
|
|
isBanned = result.some(spec({pubkey}))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-10 00:57:44 +00:00
|
|
|
onMount(() => {
|
2026-07-28 16:16:26 +00:00
|
|
|
$messagingRelayLists.load(pubkey)
|
2026-02-10 00:57:44 +00:00
|
|
|
})
|
2024-12-16 20:54:17 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-01-30 22:14:12 +00:00
|
|
|
<Modal>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<div class="flex flex-col gap-4">
|
|
|
|
|
<div class="flex justify-between">
|
|
|
|
|
<Profile showPubkey avatarSize={14} {pubkey} {url} />
|
2026-07-03 00:27:28 +00:00
|
|
|
<ProfileMenu {pubkey} {url}>
|
|
|
|
|
{#snippet customActions()}
|
2026-09-08 18:04:37 +00:00
|
|
|
{#if !isSelf}
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={sendMessage}>
|
|
|
|
|
<Icon size={4} icon={Letter} />
|
|
|
|
|
Send Message
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2026-07-03 00:27:28 +00:00
|
|
|
{#if $userIsAdmin}
|
|
|
|
|
{#if isBanned}
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={restoreMember}>
|
2026-09-08 18:04:37 +00:00
|
|
|
<Icon size={4} icon={Restart} />
|
2026-07-03 00:27:28 +00:00
|
|
|
Restore Membership
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{:else}
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={removeMember}>
|
2026-09-08 18:04:37 +00:00
|
|
|
<Icon size={4} icon={UserMinus} />
|
2026-07-03 00:27:28 +00:00
|
|
|
Remove Member
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<Button class="text-error" onclick={banMember}>
|
2026-09-08 18:04:37 +00:00
|
|
|
<Icon size={4} icon={MinusCircle} />
|
2026-07-03 00:27:28 +00:00
|
|
|
Ban User
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2026-01-30 22:14:12 +00:00
|
|
|
{/if}
|
2026-07-03 00:27:28 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</ProfileMenu>
|
2025-11-13 21:44:52 +00:00
|
|
|
</div>
|
2026-09-11 00:12:19 +00:00
|
|
|
<ProfileStatus {pubkey} {url} />
|
2026-07-03 00:01:31 +00:00
|
|
|
<ProfileAbout {pubkey} {url} />
|
2026-01-30 22:14:12 +00:00
|
|
|
<ProfileBadges {pubkey} {url} />
|
2026-09-11 00:37:37 +00:00
|
|
|
<ProfilePinnedNote {pubkey} {url} />
|
2026-01-30 22:14:12 +00:00
|
|
|
</div>
|
|
|
|
|
</ModalBody>
|
2024-12-16 20:54:17 +00:00
|
|
|
<ModalFooter>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button onclick={back} class="button button-link hidden md:flex">
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
2024-12-16 20:54:17 +00:00
|
|
|
Go back
|
|
|
|
|
</Button>
|
|
|
|
|
<div class="flex gap-2">
|
2026-06-18 10:52:04 +00:00
|
|
|
<Button onclick={viewProfile} class="button button-primary">
|
|
|
|
|
<Icon icon={UserCircle} />
|
|
|
|
|
View Full Profile
|
2024-12-16 20:54:17 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</ModalFooter>
|
2026-01-30 22:14:12 +00:00
|
|
|
</Modal>
|