2024-10-24 22:48:45 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import type {NativeEmoji} from "emoji-picker-element/shared"
|
2025-02-18 01:33:21 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2026-07-15 21:23:43 +00:00
|
|
|
import {getTagValue} from "@welshman/util"
|
2024-10-24 22:48:45 +00:00
|
|
|
import {pubkey} from "@welshman/app"
|
2025-10-06 18:23:19 +00:00
|
|
|
import Bolt from "@assets/icons/bolt.svg?dataurl"
|
|
|
|
|
import Reply from "@assets/icons/reply-2.svg?dataurl"
|
|
|
|
|
import Code2 from "@assets/icons/code-2.svg?dataurl"
|
|
|
|
|
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
|
|
|
|
|
import SmileCircle from "@assets/icons/smile-circle.svg?dataurl"
|
|
|
|
|
import MenuDots from "@assets/icons/menu-dots.svg?dataurl"
|
2026-07-15 21:23:43 +00:00
|
|
|
import Pin from "@assets/icons/pin.svg?dataurl"
|
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"
|
2025-02-18 17:03:10 +00:00
|
|
|
import EventDeleteConfirm from "@app/components/EventDeleteConfirm.svelte"
|
2026-07-15 21:23:43 +00:00
|
|
|
import {ROOM} from "@app/groups"
|
|
|
|
|
import {deriveUserIsRoomAdmin} from "@app/members"
|
|
|
|
|
import {deriveRoomPinIds, pinRoomMessage, unpinRoomMessage} from "@app/pins"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {ENABLE_ZAPS} from "@app/env"
|
|
|
|
|
import {publishReaction} from "@app/reactions"
|
|
|
|
|
import {canEnforceNip70} from "@app/relays"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {getRoomItemPath} from "@app/routes"
|
|
|
|
|
import {pushModal} from "@app/modal"
|
2026-07-15 21:23:43 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
2024-10-24 22:48:45 +00:00
|
|
|
|
2025-02-19 01:15:41 +00:00
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
event: TrustedEvent
|
|
|
|
|
reply: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, event, reply}: Props = $props()
|
2024-10-24 22:48:45 +00:00
|
|
|
|
2026-07-15 21:23:43 +00:00
|
|
|
const h = getTagValue(ROOM, event.tags) ?? ""
|
2025-10-30 22:36:14 +00:00
|
|
|
const path = getRoomItemPath(url, event)
|
2026-07-15 21:23:43 +00:00
|
|
|
const pinIds = deriveRoomPinIds(url, h)
|
|
|
|
|
const userIsRoomAdmin = deriveUserIsRoomAdmin(url, h)
|
|
|
|
|
const isPinned = $derived($pinIds.includes(event.id))
|
2025-10-06 18:23:19 +00:00
|
|
|
|
2025-08-19 21:03:04 +00:00
|
|
|
const shouldProtect = canEnforceNip70(url)
|
|
|
|
|
|
2025-07-30 23:30:03 +00:00
|
|
|
const onEmoji = (async (event: TrustedEvent, url: string, emoji: NativeEmoji) => {
|
2024-10-24 22:48:45 +00:00
|
|
|
history.back()
|
2025-07-30 23:30:03 +00:00
|
|
|
publishReaction({
|
|
|
|
|
event,
|
|
|
|
|
relays: [url],
|
|
|
|
|
content: emoji.unicode,
|
2025-08-19 21:03:04 +00:00
|
|
|
protect: await shouldProtect,
|
2025-07-30 23:30:03 +00:00
|
|
|
})
|
2025-02-19 01:15:41 +00:00
|
|
|
}).bind(undefined, event, url)
|
2024-10-24 22:48:45 +00:00
|
|
|
|
|
|
|
|
const showEmojiPicker = () => pushModal(EmojiPicker, {onClick: onEmoji}, {replaceState: true})
|
|
|
|
|
|
2025-01-28 17:47:11 +00:00
|
|
|
const sendReply = () => {
|
|
|
|
|
history.back()
|
|
|
|
|
reply()
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-03 20:10:47 +00:00
|
|
|
const showInfo = () => pushModal(EventInfo, {url, event}, {replaceState: true})
|
2024-10-24 22:48:45 +00:00
|
|
|
|
2025-02-18 17:03:10 +00:00
|
|
|
const showDelete = () => pushModal(EventDeleteConfirm, {url, event})
|
2026-07-15 21:23:43 +00:00
|
|
|
|
|
|
|
|
const togglePin = async () => {
|
|
|
|
|
if (!h) return
|
|
|
|
|
|
|
|
|
|
history.back()
|
|
|
|
|
|
|
|
|
|
const error = isPinned
|
|
|
|
|
? await unpinRoomMessage(url, h, event.id, $pinIds)
|
|
|
|
|
: await pinRoomMessage(url, h, event.id, $pinIds)
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: isPinned ? "Message unpinned" : "Message pinned"})
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-24 22:48:45 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-02-09 16:49:55 +00:00
|
|
|
<Modal>
|
|
|
|
|
<ModalBody>
|
2026-02-10 19:39:29 +00:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
{#if event.pubkey === $pubkey}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-neutral text-error" onclick={showDelete}>
|
2026-02-10 19:39:29 +00:00
|
|
|
<Icon size={4} icon={TrashBin2} />
|
|
|
|
|
Delete Message
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-neutral" onclick={showInfo}>
|
2026-02-10 19:39:29 +00:00
|
|
|
<Icon size={4} icon={Code2} />
|
|
|
|
|
Message Info
|
2026-02-09 16:49:55 +00:00
|
|
|
</Button>
|
2026-02-10 19:39:29 +00:00
|
|
|
{#if path}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Link class="button button-neutral" href={path}>
|
2026-02-10 19:39:29 +00:00
|
|
|
<Icon size={4} icon={MenuDots} />
|
|
|
|
|
View Details
|
|
|
|
|
</Link>
|
|
|
|
|
{/if}
|
2026-07-15 21:23:43 +00:00
|
|
|
{#if h && $userIsRoomAdmin}
|
|
|
|
|
<Button class="button button-neutral w-full" onclick={togglePin}>
|
|
|
|
|
<Icon size={4} icon={Pin} />
|
|
|
|
|
{isPinned ? "Unpin Message" : "Pin Message"}
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
2026-02-10 19:39:29 +00:00
|
|
|
{#if ENABLE_ZAPS}
|
2026-06-24 20:56:53 +00:00
|
|
|
<ZapButton replaceState {url} {event} class="button button-neutral w-full">
|
2026-02-10 19:39:29 +00:00
|
|
|
<Icon size={4} icon={Bolt} />
|
|
|
|
|
Send Zap
|
|
|
|
|
</ZapButton>
|
|
|
|
|
{/if}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-neutral w-full" onclick={sendReply}>
|
2026-02-10 19:39:29 +00:00
|
|
|
<Icon size={4} icon={Reply} />
|
|
|
|
|
Send Reply
|
|
|
|
|
</Button>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-neutral w-full" onclick={showEmojiPicker}>
|
2026-02-10 19:39:29 +00:00
|
|
|
<Icon size={4} icon={SmileCircle} />
|
|
|
|
|
Send Reaction
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2026-02-09 16:49:55 +00:00
|
|
|
</ModalBody>
|
|
|
|
|
</Modal>
|