+ import {nip19} from "nostr-tools"
+ import {without, pluck, uniq} from "ramda"
+ import {slide} from "svelte/transition"
+ import {Tags, displayPerson} from "src/util/nostr"
+ import ImageInput from "src/partials/ImageInput.svelte"
+ import Media from "src/partials/Media.svelte"
+ import Compose from "src/partials/Compose.svelte"
+ import {getPersonWithFallback} from "src/agent/db"
+ import {getEventPublishRelays} from "src/agent/relays"
+ import user from "src/agent/user"
+ import cmd from "src/agent/cmd"
+ import {toast} from "src/app/ui"
+ import {publishWithToast} from "src/app"
+
+ export let note
+ export let borderColor
+
+ let data = null
+ let reply = null
+ let container = null
+
+ export const isActive = () => Boolean(reply)
+
+ export const start = () => {
+ data = {
+ image: null,
+ mentions: without(
+ [user.getPubkey()],
+ uniq(Tags.from(note).type("p").values().all().concat(note.pubkey))
+ ),
+ }
+ }
+
+ const reset = () => {
+ data = null
+ reply = null
+ }
+
+ const removeMention = pubkey => {
+ data.mentions = without([pubkey], data.mentions)
+ }
+
+ const send = async () => {
+ let {content, mentions, topics} = reply.parse()
+
+ if (data.image) {
+ content = (content + "\n" + data.image).trim()
+ }
+
+ if (content) {
+ mentions = uniq(mentions.concat(data.mentions))
+
+ const relays = getEventPublishRelays(note)
+ const thunk = cmd.createReply(note, content, mentions, topics)
+ const [event, promise] = await publishWithToast(relays, thunk)
+
+ promise.then(({succeeded}) => {
+ if (succeeded.size > 0) {
+ toast.show("info", {
+ text: `Your note has been created!`,
+ link: {
+ text: "View",
+ href:
+ "/" +
+ nip19.neventEncode({
+ id: event.id,
+ relays: pluck("url", relays.slice(0, 3)),
+ }),
+ },
+ })
+ }
+ })
+
+ reset()
+ }
+ }
+
+ const onBodyClick = e => {
+ const target = e.target as HTMLElement
+
+ if (container?.contains(target)) {
+ reset()
+ }
+ }
+
+
+
+
+{#if data}
+
+
+
+
+
+
+
+ {#if data.image}
+
+ {
+ data.image = null
+ }} />
+
+ {/if}
+
+
+
+
+ {#each data.mentions as p}
+
+
+ {:else}
+
No mentions
+ {/each}
+
+
+
+
+
+
+ Posting as @{displayPerson(getPersonWithFallback(user.getPubkey()))}
+
+
+
+{/if}