2024-10-24 22:48:45 +00:00
|
|
|
<script lang="ts">
|
2025-02-18 01:33:21 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2026-08-17 18:18:38 +00:00
|
|
|
import * as nip19 from "nostr-tools/nip19"
|
|
|
|
|
import {getIdOrAddress, tagSpec, tagValue, toNostrURI} from "@welshman/util"
|
2025-10-06 18:23:19 +00:00
|
|
|
import Bolt from "@assets/icons/bolt.svg?dataurl"
|
2026-09-02 15:12:31 +00:00
|
|
|
import Pen from "@assets/icons/pen.svg?dataurl"
|
2025-10-06 18:23:19 +00:00
|
|
|
import Reply from "@assets/icons/reply-2.svg?dataurl"
|
2026-08-21 15:31:53 +00:00
|
|
|
import ShareCircle from "@assets/icons/share-circle.svg?dataurl"
|
2025-10-06 18:23:19 +00:00
|
|
|
import Code2 from "@assets/icons/code-2.svg?dataurl"
|
|
|
|
|
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
|
2026-09-25 22:48:55 +00:00
|
|
|
import Danger from "@assets/icons/danger.svg?dataurl"
|
|
|
|
|
import GalleryWide from "@assets/icons/gallery-wide.svg?dataurl"
|
2025-10-06 18:23:19 +00:00
|
|
|
import SmileCircle from "@assets/icons/smile-circle.svg?dataurl"
|
|
|
|
|
import MenuDots from "@assets/icons/menu-dots.svg?dataurl"
|
2026-09-02 15:12:31 +00:00
|
|
|
import AltArrowDown from "@assets/icons/alt-arrow-down.svg?dataurl"
|
|
|
|
|
import AltArrowUp from "@assets/icons/alt-arrow-up.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"
|
2026-09-09 14:43:55 +00:00
|
|
|
import VolumeLoud from "@assets/icons/volume-loud.svg?dataurl"
|
2026-09-02 15:12:31 +00:00
|
|
|
import {slideAndFade} from "@lib/transition"
|
2024-10-24 22:48:45 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
2025-10-06 18:23:19 +00:00
|
|
|
import Link from "@lib/components/Link.svelte"
|
2024-10-24 22:48:45 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2026-02-09 16:49:55 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
2024-10-24 22:48:45 +00:00
|
|
|
import EmojiPicker from "@lib/components/EmojiPicker.svelte"
|
2025-07-17 22:29:26 +00:00
|
|
|
import ZapButton from "@app/components/ZapButton.svelte"
|
2024-10-24 22:48:45 +00:00
|
|
|
import EventInfo from "@app/components/EventInfo.svelte"
|
2026-09-25 22:48:55 +00:00
|
|
|
import Report from "@app/components/Report.svelte"
|
|
|
|
|
import PinboardSelect from "@app/components/PinboardSelect.svelte"
|
2026-09-19 18:43:01 +00:00
|
|
|
import EventAdminDeleteConfirm from "@app/components/EventAdminDeleteConfirm.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-09-26 04:37:45 +00:00
|
|
|
import {roomPinLists, user} from "@app/core"
|
2026-09-19 18:43:01 +00:00
|
|
|
import {deriveUserAdminDelete, deriveUserIsRoomAdmin} from "@app/rooms"
|
2026-09-26 04:37:45 +00:00
|
|
|
import {toggleRoomPin} from "@app/roomPins"
|
|
|
|
|
import {publishReaction} from "@app/reactions"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {ENABLE_ZAPS} from "@app/env"
|
2026-08-14 15:47:36 +00:00
|
|
|
import {makeContentPath} from "@app/routes"
|
2026-08-21 15:31:53 +00:00
|
|
|
import {shareEvent} from "@app/share"
|
2026-09-09 14:43:55 +00:00
|
|
|
import {readAloud} from "@app/speech"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2024-10-24 22:48:45 +00:00
|
|
|
|
2025-02-19 01:15:41 +00:00
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
event: TrustedEvent
|
|
|
|
|
reply: () => void
|
2026-09-02 15:12:31 +00:00
|
|
|
edit?: () => void
|
2025-02-19 01:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
2026-09-02 15:12:31 +00:00
|
|
|
const {url, event, reply, edit}: Props = $props()
|
2024-10-24 22:48:45 +00:00
|
|
|
|
2026-09-18 18:08:00 +00:00
|
|
|
const h = tagValue(tagSpec("h"), event.tags) ?? ""
|
2026-08-14 15:47:36 +00:00
|
|
|
const path = makeContentPath(url, event.kind, getIdOrAddress(event))
|
2026-07-28 16:16:26 +00:00
|
|
|
const pinIds = $roomPinLists.pins(url, h).$
|
2026-07-15 21:23:43 +00:00
|
|
|
const userIsRoomAdmin = deriveUserIsRoomAdmin(url, h)
|
2026-09-19 18:43:01 +00:00
|
|
|
const adminDelete = deriveUserAdminDelete(url, event)
|
2026-07-15 21:23:43 +00:00
|
|
|
const isPinned = $derived($pinIds.includes(event.id))
|
2026-09-02 15:12:31 +00:00
|
|
|
const tile = "button h-auto flex-col gap-1.5 py-4 text-xs"
|
2025-10-06 18:23:19 +00:00
|
|
|
|
2026-09-26 04:37:45 +00:00
|
|
|
const onEmoji = (emoji: string) => {
|
2024-10-24 22:48:45 +00:00
|
|
|
history.back()
|
2026-09-26 04:37:45 +00:00
|
|
|
publishReaction(event, {content: emoji, tags: []}, {url})
|
2026-07-28 16:16:26 +00:00
|
|
|
}
|
2024-10-24 22:48:45 +00:00
|
|
|
|
|
|
|
|
const showEmojiPicker = () => pushModal(EmojiPicker, {onClick: onEmoji}, {replaceState: true})
|
|
|
|
|
|
2026-08-17 18:18:38 +00:00
|
|
|
const createThread = () =>
|
|
|
|
|
pushModal(
|
|
|
|
|
ThreadCreate,
|
2026-09-09 08:32:14 +00:00
|
|
|
{
|
|
|
|
|
url,
|
|
|
|
|
h,
|
|
|
|
|
initialValues: {content: toNostrURI(nip19.neventEncode({...event, relays: [url]}))},
|
|
|
|
|
},
|
2026-08-17 18:18:38 +00:00
|
|
|
{replaceState: true},
|
|
|
|
|
)
|
2026-08-17 18:13:37 +00:00
|
|
|
|
2025-01-28 17:47:11 +00:00
|
|
|
const sendReply = () => {
|
|
|
|
|
history.back()
|
|
|
|
|
reply()
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-02 15:12:31 +00:00
|
|
|
const sendEdit = () => {
|
|
|
|
|
history.back()
|
|
|
|
|
edit?.()
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-21 15:31:53 +00:00
|
|
|
const share = () => {
|
|
|
|
|
history.back()
|
|
|
|
|
shareEvent(url, "Message", event)
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-09 14:43:55 +00:00
|
|
|
const read = () => {
|
|
|
|
|
history.back()
|
|
|
|
|
readAloud(event)
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-03 20:10:47 +00:00
|
|
|
const showInfo = () => pushModal(EventInfo, {url, event}, {replaceState: true})
|
2024-10-24 22:48:45 +00:00
|
|
|
|
2026-09-25 22:48:55 +00:00
|
|
|
const addToLibrary = () => pushModal(PinboardSelect, {url, event}, {replaceState: true})
|
|
|
|
|
|
|
|
|
|
const report = () => pushModal(Report, {url, event}, {replaceState: true})
|
|
|
|
|
|
2025-02-18 17:03:10 +00:00
|
|
|
const showDelete = () => pushModal(EventDeleteConfirm, {url, event})
|
2026-07-15 21:23:43 +00:00
|
|
|
|
2026-09-19 18:43:01 +00:00
|
|
|
const showAdminDelete = () => pushModal(EventAdminDeleteConfirm, {url, noun: "Message", event})
|
|
|
|
|
|
2026-09-02 15:12:31 +00:00
|
|
|
const toggleMore = () => {
|
|
|
|
|
showMore = !showMore
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-26 04:37:45 +00:00
|
|
|
const togglePin = () => {
|
2026-07-15 21:23:43 +00:00
|
|
|
history.back()
|
2026-09-30 20:51:08 +00:00
|
|
|
toggleRoomPin(url, h, event)
|
2026-07-15 21:23:43 +00:00
|
|
|
}
|
2026-09-02 15:12:31 +00:00
|
|
|
|
|
|
|
|
let showMore = $state(false)
|
2024-10-24 22:48:45 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-09-12 17:03:24 +00:00
|
|
|
<Modal label="Message actions">
|
2026-02-09 16:49:55 +00:00
|
|
|
<ModalBody>
|
2026-09-02 15:12:31 +00:00
|
|
|
<div class="grid gap-2 {ENABLE_ZAPS ? 'grid-cols-3' : 'grid-cols-2'}">
|
2026-02-10 19:39:29 +00:00
|
|
|
{#if ENABLE_ZAPS}
|
2026-09-02 15:12:31 +00:00
|
|
|
<ZapButton replaceState {url} {event} class="{tile} button-outline button-secondary">
|
|
|
|
|
<Icon size={6} icon={Bolt} />
|
|
|
|
|
Zap
|
2026-02-10 19:39:29 +00:00
|
|
|
</ZapButton>
|
|
|
|
|
{/if}
|
2026-09-02 15:12:31 +00:00
|
|
|
<Button class="{tile} button-outline button-primary" onclick={showEmojiPicker}>
|
|
|
|
|
<Icon size={6} icon={SmileCircle} />
|
|
|
|
|
React
|
2026-02-10 19:39:29 +00:00
|
|
|
</Button>
|
2026-09-02 15:12:31 +00:00
|
|
|
<Button class="{tile} button-neutral" onclick={sendReply}>
|
|
|
|
|
<Icon size={6} icon={Reply} />
|
|
|
|
|
Reply
|
2026-02-10 19:39:29 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
2026-09-02 15:12:31 +00:00
|
|
|
<div class="flex flex-col">
|
|
|
|
|
<Button class="button button-neutral w-full" onclick={toggleMore}>
|
|
|
|
|
<Icon size={4} icon={showMore ? AltArrowUp : AltArrowDown} />
|
|
|
|
|
{showMore ? "Fewer Options" : "More Options"}
|
|
|
|
|
</Button>
|
|
|
|
|
{#if showMore}
|
|
|
|
|
<div transition:slideAndFade class="flex flex-col gap-2 pt-2">
|
|
|
|
|
{#if edit}
|
|
|
|
|
<Button class="button button-neutral w-full" onclick={sendEdit}>
|
|
|
|
|
<Icon size={4} icon={Pen} />
|
|
|
|
|
Edit Message
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
|
|
|
|
<Button class="button button-neutral w-full" onclick={share}>
|
|
|
|
|
<Icon size={4} icon={ShareCircle} />
|
2026-09-18 18:22:51 +00:00
|
|
|
Share Message
|
2026-09-02 15:12:31 +00:00
|
|
|
</Button>
|
2026-09-25 22:48:55 +00:00
|
|
|
<Button class="button button-neutral w-full" onclick={addToLibrary}>
|
|
|
|
|
<Icon size={4} icon={GalleryWide} />
|
|
|
|
|
Add to Library
|
|
|
|
|
</Button>
|
2026-09-09 14:43:55 +00:00
|
|
|
<Button class="button button-neutral w-full" onclick={read}>
|
|
|
|
|
<Icon size={4} icon={VolumeLoud} />
|
|
|
|
|
Read Out Loud
|
|
|
|
|
</Button>
|
2026-09-02 15:12:31 +00:00
|
|
|
{#if h}
|
|
|
|
|
<Button class="button button-neutral w-full" onclick={createThread}>
|
|
|
|
|
<Icon size={4} icon={NotesMinimalistic} />
|
|
|
|
|
Create a Thread
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if h && $userIsRoomAdmin}
|
|
|
|
|
<Button class="button button-neutral w-full" onclick={togglePin}>
|
|
|
|
|
<Icon size={4} icon={Pin} />
|
|
|
|
|
{isPinned ? "Unpin Message" : "Pin Message"}
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if path}
|
|
|
|
|
<Link class="button button-neutral w-full" href={path}>
|
|
|
|
|
<Icon size={4} icon={MenuDots} />
|
|
|
|
|
View Details
|
|
|
|
|
</Link>
|
|
|
|
|
{/if}
|
|
|
|
|
<Button class="button button-neutral w-full" onclick={showInfo}>
|
|
|
|
|
<Icon size={4} icon={Code2} />
|
|
|
|
|
Message Info
|
|
|
|
|
</Button>
|
|
|
|
|
{#if event.pubkey === $user.pubkey}
|
|
|
|
|
<Button class="button button-neutral w-full text-error" onclick={showDelete}>
|
|
|
|
|
<Icon size={4} icon={TrashBin2} />
|
|
|
|
|
Delete Message
|
|
|
|
|
</Button>
|
2026-09-25 22:48:55 +00:00
|
|
|
{:else}
|
|
|
|
|
<Button class="button button-neutral w-full text-error" onclick={report}>
|
|
|
|
|
<Icon size={4} icon={Danger} />
|
|
|
|
|
Report Content
|
2026-09-19 18:43:01 +00:00
|
|
|
</Button>
|
2026-09-25 22:48:55 +00:00
|
|
|
{#if $adminDelete}
|
|
|
|
|
<Button class="button button-neutral w-full text-error" onclick={showAdminDelete}>
|
|
|
|
|
<Icon size={4} icon={TrashBin2} />
|
|
|
|
|
Delete Message
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
2026-09-02 15:12:31 +00:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2026-02-09 16:49:55 +00:00
|
|
|
</ModalBody>
|
|
|
|
|
</Modal>
|