flotilla/src/app/components/RoomItemEmojiButton.svelte

41 lines
1.1 KiB
Svelte
Raw Normal View History

2024-09-25 20:46:10 +00:00
<script lang="ts">
2024-10-08 18:39:16 +00:00
import type {NativeEmoji} from "emoji-picker-element/shared"
2026-07-28 16:16:26 +00:00
import type {TrustedEvent} from "@welshman/util"
import {tagSpec, tagValue} from "@welshman/util"
2024-10-23 23:16:28 +00:00
import EmojiButton from "@lib/components/EmojiButton.svelte"
2025-09-10 22:26:39 +00:00
import SmileCircle from "@assets/icons/smile-circle.svg?dataurl"
2024-10-24 22:48:45 +00:00
import Icon from "@lib/components/Icon.svelte"
2026-07-28 16:16:26 +00:00
import {reactions, relays} from "@app/core"
2024-09-25 20:46:10 +00:00
2026-07-28 16:16:26 +00:00
type Props = {
url: string
event: TrustedEvent
}
2026-07-28 16:16:26 +00:00
const {url, event}: Props = $props()
2026-07-28 16:16:26 +00:00
const shouldProtect = $relays.hasNip(url, 70)
const onEmoji = async (emoji: NativeEmoji) => {
const protect = await shouldProtect
const room = tagValue(tagSpec("h"), event.tags)
const command = await $reactions.react(event, emoji.unicode, writer => {
writer.setProtected(protect)
if (room) {
writer.setRoom(url, room)
}
})
2026-07-28 16:16:26 +00:00
return command.publishToRelays([url])
}
2024-09-25 20:46:10 +00:00
</script>
<EmojiButton
{onEmoji}
class="button button-xs button-neutral join-item"
tippyParams={{placement: "bottom-end"}}>
2025-09-10 22:26:39 +00:00
<Icon icon={SmileCircle} size={4} />
2024-10-24 22:48:45 +00:00
</EmojiButton>