diff --git a/src/components/post-modal/index.tsx b/src/components/post-modal/index.tsx index c48d48cd0..13b4448bc 100644 --- a/src/components/post-modal/index.tsx +++ b/src/components/post-modal/index.tsx @@ -32,7 +32,7 @@ import dayjs from "dayjs"; import { useForm } from "react-hook-form"; import { kinds, UnsignedEvent } from "nostr-tools"; import { useThrottle } from "react-use"; -import { useObservable } from "applesauce-react/hooks"; +import { useEventFactory, useObservable } from "applesauce-react/hooks"; import { ChevronDownIcon, ChevronUpIcon, UploadImageIcon } from "../icons"; import PublishAction from "../../classes/nostr-publish-action"; @@ -64,6 +64,7 @@ import localSettings from "../../services/local-settings"; import useLocalStorageDisclosure from "../../hooks/use-localstorage-disclosure"; import InsertGifButton from "../gif/insert-gif-button"; import InsertImageButton from "./insert-image-button"; +import { unixNow } from "applesauce-core/helpers"; type FormValues = { subject: string; @@ -101,6 +102,7 @@ export default function PostModal({ const emojis = useContextEmojis(); const moreOptions = useDisclosure(); + const factory = useEventFactory(); const [draft, setDraft] = useState(); const { getValues, setValue, watch, register, handleSubmit, formState, reset } = useForm({ defaultValues: { @@ -131,10 +133,10 @@ export default function PostModal({ const { content, nsfw, nsfwReason, community, split, subject } = values; let draft = finalizeNote({ - content: correctContentMentions(content), kind: kinds.ShortTextNote, + content, tags: [], - created_at: dayjs().unix(), + created_at: unixNow(), }); if (nsfw) draft.tags.push(nsfwReason ? ["content-warning", nsfwReason] : ["content-warning"]); @@ -152,7 +154,7 @@ export default function PostModal({ setDraft(unsigned); return unsigned; }, - [getValues, emojis, finalizeDraft, setDraft], + [getValues, emojis, finalizeDraft, setDraft, factory], ); // throttle update the draft every 500ms diff --git a/src/helpers/nostr/post.ts b/src/helpers/nostr/post.ts index 406184a5b..7ed03bdf1 100644 --- a/src/helpers/nostr/post.ts +++ b/src/helpers/nostr/post.ts @@ -86,7 +86,7 @@ export function ensureNotifyPubkeys(draft: EventTemplate, pubkeys: string[]) { } export function correctContentMentions(content: string) { - return content.replace(/(\s|^)(?:@)?(npub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58})/gi, "$1nostr:$2"); + return content.replaceAll(/(\s|^)(?:@)?(npub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58})/gi, "$1nostr:$2"); } export function getPubkeysMentionedInContent(content: string, direct = false) { @@ -219,7 +219,6 @@ export function addPubkeyRelayHints(draft: EventTemplate) { export function finalizeNote(draft: EventTemplate) { let updated: EventTemplate = { ...draft, tags: Array.from(draft.tags) }; updated.content = correctContentMentions(updated.content); - updated = createHashtagTags(updated); updated = addPubkeyRelayHints(updated); updated = ensureTagContentMentions(updated); return updated; diff --git a/src/services/event-factory.ts b/src/services/event-factory.ts index e3504af4a..741ea0d1e 100644 --- a/src/services/event-factory.ts +++ b/src/services/event-factory.ts @@ -1,7 +1,7 @@ import { BehaviorSubject, Observable } from "rxjs"; import { EventFactory } from "applesauce-factory"; import { Account } from "../classes/accounts/account"; -import { getEventRelayHints } from "./event-relay-hint"; +import { getEventRelayHint, getPubkeyRelayHint } from "./event-relay-hint"; import { NIP_89_CLIENT_APP } from "../const"; import accountService from "./account"; @@ -19,7 +19,8 @@ class EventFactoryService { this.subject.next( new EventFactory({ signer: current.signer, - getRelayHint: (event) => getEventRelayHints(event, 1)[0], + getRelayHint: getEventRelayHint, + getPubkeyRelayHint: getPubkeyRelayHint, client: NIP_89_CLIENT_APP, }), ); diff --git a/src/services/event-relay-hint.ts b/src/services/event-relay-hint.ts index 9d543fc9b..009430286 100644 --- a/src/services/event-relay-hint.ts +++ b/src/services/event-relay-hint.ts @@ -63,6 +63,11 @@ export function getEventRelayHint(event: NostrEvent): string | undefined { return getEventRelayHints(event, 1)[0]; } +/** Returns a relay hint for a single pubkey */ +export function getPubkeyRelayHint(pubkey: string): string | undefined { + return getAuthorHints(pubkey)[0]; +} + /** Returns a nevent or naddr for an event */ export function getSharableEventAddress(event: NostrEvent, relays?: Iterable) { relays = relays || getEventRelayHints(event, 2);