2024-10-16 18:27:27 +00:00
|
|
|
<script lang="ts">
|
2025-10-06 18:23:19 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {tagSpec, tagValue} from "@welshman/util"
|
2025-10-06 18:23:19 +00:00
|
|
|
import Code2 from "@assets/icons/code-2.svg?dataurl"
|
2026-07-02 18:36:05 +00:00
|
|
|
import GalleryWide from "@assets/icons/gallery-wide.svg?dataurl"
|
2025-10-06 18:23:19 +00:00
|
|
|
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
|
|
|
|
|
import Danger from "@assets/icons/danger.svg?dataurl"
|
2026-07-15 21:23:43 +00:00
|
|
|
import Pin from "@assets/icons/pin.svg?dataurl"
|
2026-08-17 18:13:37 +00:00
|
|
|
import NotesMinimalistic from "@assets/icons/notes-minimalistic.svg?dataurl"
|
2024-10-16 18:27:27 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2025-11-14 00:39:44 +00:00
|
|
|
import Confirm from "@lib/components/Confirm.svelte"
|
2024-10-16 18:27:27 +00:00
|
|
|
import EventInfo from "@app/components/EventInfo.svelte"
|
2025-11-14 19:35:19 +00:00
|
|
|
import Report from "@app/components/Report.svelte"
|
2026-07-02 18:36:05 +00:00
|
|
|
import PinboardSelect from "@app/components/PinboardSelect.svelte"
|
2025-02-18 17:03:10 +00:00
|
|
|
import EventDeleteConfirm from "@app/components/EventDeleteConfirm.svelte"
|
2026-08-17 18:13:37 +00:00
|
|
|
import ThreadCreate from "@app/components/ThreadCreate.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {app, relayManagement, roomPinLists, user} from "@app/core"
|
|
|
|
|
import {deriveUserIsSpaceAdmin} from "@app/management"
|
|
|
|
|
import {ROOM, deriveUserIsRoomAdmin} from "@app/rooms"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
|
|
|
|
import {pushToast} from "@app/toast"
|
2024-10-16 18:27:27 +00:00
|
|
|
|
2025-10-06 18:23:19 +00:00
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
event: TrustedEvent
|
|
|
|
|
onClick: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, event, onClick}: Props = $props()
|
2024-10-16 18:27:27 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const h = tagValue(tagSpec(ROOM), event.tags) ?? ""
|
|
|
|
|
const pinIds = $roomPinLists.pins(url, h).$
|
2025-11-14 00:39:44 +00:00
|
|
|
const userIsAdmin = deriveUserIsSpaceAdmin(url)
|
2026-07-15 21:23:43 +00:00
|
|
|
const userIsRoomAdmin = deriveUserIsRoomAdmin(url, h)
|
|
|
|
|
const isPinned = $derived($pinIds.includes(event.id))
|
2025-11-14 00:39:44 +00:00
|
|
|
|
2026-07-02 18:36:05 +00:00
|
|
|
const addToLibrary = () => {
|
|
|
|
|
onClick()
|
2026-07-27 22:16:21 +00:00
|
|
|
pushModal(PinboardSelect, {url, event})
|
2026-07-02 18:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-17 18:13:37 +00:00
|
|
|
const createThread = () => {
|
|
|
|
|
onClick()
|
|
|
|
|
pushModal(ThreadCreate, {url, h, parent: event})
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-15 01:23:27 +00:00
|
|
|
const report = () => {
|
|
|
|
|
onClick()
|
2025-11-14 19:35:19 +00:00
|
|
|
pushModal(Report, {url, event})
|
2025-01-15 01:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-16 18:27:27 +00:00
|
|
|
const showInfo = () => {
|
|
|
|
|
onClick()
|
2025-03-03 20:10:47 +00:00
|
|
|
pushModal(EventInfo, {url, event})
|
2024-10-16 18:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const showDelete = () => {
|
|
|
|
|
onClick()
|
2025-02-18 17:03:10 +00:00
|
|
|
pushModal(EventDeleteConfirm, {url, event})
|
2024-10-16 18:27:27 +00:00
|
|
|
}
|
2025-11-14 00:39:44 +00:00
|
|
|
|
|
|
|
|
const showAdminDelete = () =>
|
|
|
|
|
pushModal(Confirm, {
|
|
|
|
|
title: `Delete Message`,
|
|
|
|
|
message: `Are you sure you want to delete this message from the space?`,
|
|
|
|
|
confirm: async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement.forUrl(url).banEvent(event.id)
|
2025-11-14 00:39:44 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "Event has successfully been deleted!"})
|
2026-07-28 16:16:26 +00:00
|
|
|
$app.repository.removeEvent(event.id)
|
2025-11-14 00:39:44 +00:00
|
|
|
history.back()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
2026-07-15 21:23:43 +00:00
|
|
|
|
|
|
|
|
const togglePin = async () => {
|
|
|
|
|
onClick()
|
|
|
|
|
|
|
|
|
|
if (!h) return
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const pins = isPinned ? $pinIds.filter(pin => pin !== event.id) : [...$pinIds, event.id]
|
|
|
|
|
const command = await $roomPinLists.setPins(url, h, pins)
|
|
|
|
|
const error = await command.publishToRelays([url]).waitForError()
|
2026-07-15 21:23:43 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: isPinned ? "Message unpinned" : "Message pinned"})
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-16 18:27:27 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-06-24 20:56:53 +00:00
|
|
|
<ul class="menu bg-surface whitespace-nowrap rounded-2xl p-2">
|
2024-10-16 18:27:27 +00:00
|
|
|
<li>
|
2025-02-04 01:21:46 +00:00
|
|
|
<Button onclick={showInfo}>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon size={4} icon={Code2} />
|
2026-07-02 18:36:05 +00:00
|
|
|
Message Details
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={addToLibrary}>
|
|
|
|
|
<Icon size={4} icon={GalleryWide} />
|
|
|
|
|
Add to Library
|
2024-10-16 18:27:27 +00:00
|
|
|
</Button>
|
|
|
|
|
</li>
|
2026-08-17 18:13:37 +00:00
|
|
|
{#if h}
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={createThread}>
|
|
|
|
|
<Icon size={4} icon={NotesMinimalistic} />
|
|
|
|
|
Create a Thread
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2026-07-15 21:23:43 +00:00
|
|
|
{#if h && $userIsRoomAdmin}
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={togglePin}>
|
|
|
|
|
<Icon size={4} icon={Pin} />
|
|
|
|
|
{isPinned ? "Unpin Message" : "Pin Message"}
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2026-07-28 16:16:26 +00:00
|
|
|
{#if event.pubkey === $user.pubkey}
|
2024-10-16 18:27:27 +00:00
|
|
|
<li>
|
2025-02-04 01:21:46 +00:00
|
|
|
<Button onclick={showDelete} class="text-error">
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon size={4} icon={TrashBin2} />
|
2024-10-16 18:27:27 +00:00
|
|
|
Delete Message
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
2025-01-15 01:23:27 +00:00
|
|
|
{:else}
|
|
|
|
|
<li>
|
2025-02-04 01:21:46 +00:00
|
|
|
<Button class="text-error" onclick={report}>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon size={4} icon={Danger} />
|
2025-01-15 01:23:27 +00:00
|
|
|
Report Content
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
2025-11-14 00:39:44 +00:00
|
|
|
{#if $userIsAdmin}
|
|
|
|
|
<li>
|
|
|
|
|
<Button class="text-error" onclick={showAdminDelete}>
|
|
|
|
|
<Icon size={4} icon={TrashBin2} />
|
|
|
|
|
Delete Message
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2024-10-16 18:27:27 +00:00
|
|
|
{/if}
|
|
|
|
|
</ul>
|