Skip to content

Commit

Permalink
cleanup relay hints
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Dec 11, 2024
1 parent 73aa6ad commit 3583373
Show file tree
Hide file tree
Showing 45 changed files with 254 additions and 217 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"rxjs": "^7.8.1",
"three": "^0.170.0",
"three-spritetext": "^1.9.2",
"three-stdlib": "^2.34.0",
"three-stdlib": "^2.34.1",
"tiny-lru": "^11.2.11",
"unified": "^11.0.5",
"vite-plugin-funding": "^0.1.0",
Expand All @@ -133,8 +133,8 @@
"@types/leaflet.locatecontrol": "^0.74.6",
"@types/lodash.throttle": "^4.1.9",
"@types/ngeohash": "^0.6.8",
"@types/react": "^18.3.14",
"@types/react-dom": "^18.3.3",
"@types/react": "^18.3.16",
"@types/react-dom": "^18.3.5",
"@types/react-window": "^1.8.8",
"@types/three": "^0.160.0",
"@types/webscopeio__react-textarea-autocomplete": "^4.7.5",
Expand Down
335 changes: 193 additions & 142 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/common-menu-items/copy-embed-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MenuItem } from "@chakra-ui/react";

import { NostrEvent } from "../../types/nostr-event";
import { CopyToClipboardIcon } from "../icons";
import { getSharableEventAddress } from "../../services/event-relay-hint";
import { getSharableEventAddress } from "../../services/relay-hints";

export default function CopyEmbedCodeMenuItem({ event }: { event: NostrEvent }) {
const address = getSharableEventAddress(event);
Expand Down
2 changes: 1 addition & 1 deletion src/components/common-menu-items/open-in-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MenuItem } from "@chakra-ui/react";
import { NostrEvent } from "../../types/nostr-event";
import { ExternalLinkIcon } from "../icons";
import { AppHandlerContext } from "../../providers/route/app-handler-provider";
import { getSharableEventAddress } from "../../services/event-relay-hint";
import { getSharableEventAddress } from "../../services/relay-hints";

export default function OpenInAppMenuItem({ event }: { event: NostrEvent }) {
const address = useMemo(() => getSharableEventAddress(event), [event]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/common-menu-items/quote-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NostrEvent } from "../../types/nostr-event";
import { QuoteEventIcon } from "../icons";
import useUserProfile from "../../hooks/use-user-profile";
import { PostModalContext } from "../../providers/route/post-modal-provider";
import { getSharableEventAddress } from "../../services/event-relay-hint";
import { getSharableEventAddress } from "../../services/relay-hints";

export default function QuoteEventMenuItem({ event }: { event: NostrEvent }) {
const toast = useToast();
Expand Down
2 changes: 1 addition & 1 deletion src/components/debug-modal/event-debug-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ModalProps } from "@chakra-ui/react";

import { NostrEvent } from "../../types/nostr-event";
import RawValue from "./raw-value";
import { getSharableEventAddress } from "../../services/event-relay-hint";
import { getSharableEventAddress } from "../../services/relay-hints";
import { CodeIcon, RelayIcon, ThreadIcon } from "../icons";
import RawJsonPage from "./pages/raw";
import PenTool01 from "../icons/pen-tool-01";
Expand Down
2 changes: 1 addition & 1 deletion src/components/embed-event/event-types/embedded-badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import UserAvatarLink from "../../user/user-avatar-link";
import UserLink from "../../user/user-link";
import { NostrEvent } from "../../../types/nostr-event";
import { getBadgeDescription, getBadgeImage, getBadgeName } from "../../../helpers/nostr/badges";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

export default function EmbeddedBadge({ badge, ...props }: Omit<CardProps, "children"> & { badge: NostrEvent }) {
const naddr = useMemo(() => getSharableEventAddress(badge), [badge]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import EmojiPackFavoriteButton from "../../../views/emoji-packs/components/emoji
import EmojiPackMenu from "../../../views/emoji-packs/components/emoji-pack-menu";
import { NostrEvent } from "../../../types/nostr-event";
import Timestamp from "../../timestamp";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

export default function EmbeddedEmojiPack({ pack, ...props }: Omit<CardProps, "children"> & { pack: NostrEvent }) {
const emojis = getEmojis(pack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UserLink from "../../user/user-link";
import UserAvatar from "../../user/user-avatar";
import { useBreakpointValue } from "../../../providers/global/breakpoint-provider";
import { getVideoDuration, getVideoImages, getVideoSummary, getVideoTitle } from "../../../helpers/nostr/video";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

export default function EmbeddedFlareVideo({ video, ...props }: Omit<CardProps, "children"> & { video: NostrEvent }) {
const navigate = useNavigate();
Expand Down
2 changes: 1 addition & 1 deletion src/components/embed-event/event-types/embedded-goal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UserLink from "../../user/user-link";
import GoalProgress from "../../../views/goals/components/goal-progress";
import GoalZapButton from "../../../views/goals/components/goal-zap-button";
import GoalTopZappers from "../../../views/goals/components/goal-top-zappers";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

export type EmbeddedGoalOptions = {
showActions?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/embed-event/event-types/embedded-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UserLink from "../../user/user-link";
import ListFeedButton from "../../../views/lists/components/list-feed-button";
import { ListCardContent } from "../../../views/lists/components/list-card";
import { createCoordinate } from "../../../classes/batch-kind-pubkey-loader";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

export default function EmbeddedSetOrList({ list, ...props }: Omit<CardProps, "children"> & { list: NostrEvent }) {
const link = isSpecialListKind(list.kind) ? createCoordinate(list.kind, list.pubkey) : getSharableEventAddress(list);
Expand Down
2 changes: 1 addition & 1 deletion src/components/embed-event/event-types/embedded-note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { CompactNoteContent } from "../../compact-note-content";
import { useNavigateInDrawer } from "../../../providers/drawer-sub-view-provider";
import HoverLinkOverlay from "../../hover-link-overlay";
import singleEventService from "../../../services/single-event";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";
import localSettings from "../../../services/local-settings";
import useAppSettings from "../../../hooks/use-app-settings";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UserAvatar from "../../user/user-avatar";
import ChatMessageContent from "../../../views/streams/stream/stream-chat/chat-message-content";
import useReplaceableEvent from "../../../hooks/use-replaceable-event";
import StreamStatusBadge from "../../../views/streams/components/status-badge";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";
import { getStreamTitle } from "../../../helpers/nostr/stream";

export default function EmbeddedStreamMessage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getTorrentMagnetLink, getTorrentSize, getTorrentTitle } from "../../../
import { formatBytes } from "../../../helpers/number";
import { useNavigateInDrawer } from "../../../providers/drawer-sub-view-provider";
import HoverLinkOverlay from "../../hover-link-overlay";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";
import localSettings from "../../../services/local-settings";

export default function EmbeddedTorrent({ torrent, ...props }: Omit<CardProps, "children"> & { torrent: NostrEvent }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { renderAudioUrl } from "../../content/links/audio";
import DebugEventButton from "../../debug-modal/debug-event-button";
import DebugEventTags from "../../debug-modal/event-tags";
import { AppHandlerContext } from "../../../providers/route/app-handler-provider";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

export default function EmbeddedUnknown({ event, ...props }: Omit<CardProps, "children"> & { event: NostrEvent }) {
const address = useMemo(() => getSharableEventAddress(event), [event]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import HoverLinkOverlay from "../../hover-link-overlay";
import Timestamp from "../../timestamp";
import GitBranch01 from "../../icons/git-branch-01";
import UserName from "../../user/user-name";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

export default function EmbeddedWikiPage({ page: page, ...props }: Omit<CardProps, "children"> & { page: NostrEvent }) {
const { address } = useMemo(() => getPageForks(page), [page]);
Expand Down
17 changes: 11 additions & 6 deletions src/components/event-reactions/common-hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { useCallback } from "react";
import { Emoji } from "applesauce-core/helpers";

import { ReactionGroup, draftEventReaction } from "../../helpers/nostr/reactions";
import { ReactionGroup } from "../../helpers/nostr/reactions";
import useCurrentAccount from "../../hooks/use-current-account";
import { NostrEvent } from "../../types/nostr-event";
import { usePublishEvent } from "../../providers/global/publish-provider";
import { useEventFactory } from "applesauce-react/hooks";
import { useSigningContext } from "../../providers/global/signing-provider";

export function useAddReaction(event: NostrEvent, grouped: ReactionGroup[]) {
const account = useCurrentAccount();
const publish = usePublishEvent();
const factory = useEventFactory()!;
const { requestSignature } = useSigningContext();

return useCallback(
async (emoji = "+", url?: string) => {
async (emoji: string | Emoji = "+") => {
const group = grouped.find((g) => g.emoji === emoji);
if (account && group && group.pubkeys.includes(account?.pubkey)) return;

const draft = draftEventReaction(event, emoji, url);

await publish("Reaction", draft);
const draft = await factory.reaction(event, emoji);
const signed = await requestSignature(draft);
await publish("Reaction", signed);
},
[grouped, account, publish],
[grouped, account, publish, event, factory, requestSignature],
);
}
6 changes: 5 additions & 1 deletion src/components/event-reactions/event-reactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export default function EventReactionButtons({ event, max }: { event: NostrEvent
isLoading={loading === group.emoji}
onClick={() => {
setLoading(group.emoji);
addReaction(group.emoji, group.url).finally(() => setLoading(undefined));
if (group.url) {
addReaction({ name: group.emoji, url: group.url }).finally(() => setLoading(undefined));
} else {
addReaction(group.emoji).finally(() => setLoading(undefined));
}
}}
colorScheme={account && group.pubkeys.includes(account?.pubkey) ? "primary" : undefined}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/event-zap-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import signingService from "../../services/signing";
import accountService from "../../services/account";
import PayStep from "./pay-step";
import UserLink from "../user/user-link";
import { getEventRelayHints } from "../../services/event-relay-hint";
import { getEventRelayHints } from "../../services/relay-hints";
import { eventStore, queryStore } from "../../services/event-store";

export type PayRequest = { invoice?: string; pubkey: string; error?: any };
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/ghost/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getDMRecipient, getDMSender } from "../../../helpers/nostr/dms";
import UserName from "../../user/user-name";
import HoverLinkOverlay from "../../hover-link-overlay";
import useEventIntersectionRef from "../../../hooks/use-event-intersection-ref";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

const kindColors: Record<number, FlexProps["bg"]> = {
[kinds.ShortTextNote]: "blue.500",
Expand Down
2 changes: 1 addition & 1 deletion src/components/lightbox-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare module "yet-another-react-lightbox" {
import { NostrEvent } from "../types/nostr-event";
import UserAvatarLink from "./user/user-avatar-link";
import UserLink from "./user/user-link";
import { getSharableEventAddress } from "../services/event-relay-hint";
import { getSharableEventAddress } from "../services/relay-hints";

type RefType = MutableRefObject<HTMLElement | null>;

Expand Down
2 changes: 1 addition & 1 deletion src/components/media-post/media-post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import RepostButton from "../note/timeline-note/components/repost-button";
import QuoteEventButton from "../note/quote-event-button";
import MediaPostSlides from "./media-slides";
import MediaPostContents from "./media-post-content";
import { getSharableEventAddress } from "../../services/event-relay-hint";
import { getSharableEventAddress } from "../../services/relay-hints";
import { ThreadIcon } from "../icons";
import EventZapIconButton from "../zap/event-zap-icon-button";
import Timestamp from "../timestamp";
Expand Down
2 changes: 1 addition & 1 deletion src/components/note/note-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link as RouterLink } from "react-router-dom";
import { nip19 } from "nostr-tools";

import { truncatedId } from "../../helpers/nostr/event";
import { getEventPointerRelayHints } from "../../services/event-relay-hint";
import { getEventPointerRelayHints } from "../../services/relay-hints";

export type NoteLinkProps = LinkProps & {
noteId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/note/note-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import CopyEmbedCodeMenuItem from "../common-menu-items/copy-embed-code";
import Recording02 from "../icons/recording-02";
import { usePublishEvent } from "../../providers/global/publish-provider";
import DebugEventMenuItem from "../debug-modal/debug-event-menu-item";
import { getSharableEventAddress } from "../../services/event-relay-hint";
import { getSharableEventAddress } from "../../services/relay-hints";

export default function NoteMenu({ event, ...props }: { event: NostrEvent } & Omit<MenuIconButtonProps, "children">) {
const translationsModal = useDisclosure();
Expand Down
2 changes: 1 addition & 1 deletion src/components/note/quote-event-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NostrEvent } from "nostr-tools";

import { QuoteEventIcon } from "../icons";
import { PostModalContext } from "../../providers/route/post-modal-provider";
import { getSharableEventAddress } from "../../services/event-relay-hint";
import { getSharableEventAddress } from "../../services/relay-hints";

export default function QuoteEventButton({
event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import dayjs from "dayjs";
import type { AddressPointer } from "nostr-tools/nip19";

import { ChevronDownIcon, ChevronUpIcon, ExternalLinkIcon } from "../../../icons";
import { getAddressPointerRelayHints, getEventRelayHint } from "../../../../services/event-relay-hint";
import { getAddressPointerRelayHints, getEventRelayHint } from "../../../../services/relay-hints";
import { usePublishEvent } from "../../../../providers/global/publish-provider";
import useCurrentAccount from "../../../../hooks/use-current-account";
import useUserCommunitiesList from "../../../../hooks/use-user-communities-list";
Expand Down
2 changes: 1 addition & 1 deletion src/components/note/timeline-note/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import POWIcon from "../../pow/pow-icon";
import ReplyContext from "./components/reply-context";
import ZapBubbles from "./components/zap-bubbles";
import useEventIntersectionRef from "../../../hooks/use-event-intersection-ref";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";
import localSettings from "../../../services/local-settings";
import NotePublishedUsing from "../note-published-using";
import useAppSettings from "../../../hooks/use-app-settings";
Expand Down
24 changes: 2 additions & 22 deletions src/helpers/nostr/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Emoji } from "../../providers/global/emoji-provider";
import { EventSplit } from "./zaps";
import { unique } from "../array";

import { getEventPointerRelayHint } from "../../services/event-relay-hint";
import { getEventPointerRelayHint } from "../../services/relay-hints";
import { eventStore } from "../../services/event-store";

function addTag(tags: Tag[], tag: Tag, overwrite = false) {
Expand Down Expand Up @@ -86,7 +86,7 @@ export function ensureNotifyPubkeys(draft: EventTemplate, pubkeys: string[]) {
}

export function correctContentMentions(content: string) {
return content.replaceAll(/(\s|^)(?:@)?(npub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58})/gi, "$1nostr:$2");
return content.replaceAll(/(?<=^|\s)(?:@)?(npub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58})/gi, "nostr:$1");
}

export function getPubkeysMentionedInContent(content: string, direct = false) {
Expand Down Expand Up @@ -196,30 +196,10 @@ export function setZapSplit(draft: EventTemplate, split: EventSplit) {
return updatedDraft;
}

export function addPubkeyRelayHints(draft: EventTemplate) {
return {
...draft,
tags: draft.tags.map((t) => {
if (isPTag(t) && !t[2]) {
const mailboxes = eventStore.getReplaceable(kinds.RelayList, t[1]);
const inbox = mailboxes && getInboxes(mailboxes);
if (inbox && inbox.length > 0) {
const newTag = [...t];
// TODO: Pick the best mailbox for the user
newTag[2] = inbox[0];
return newTag;
} else return t;
}
return t;
}),
};
}

/** @deprecated use event factory instead */
export function finalizeNote(draft: EventTemplate) {
let updated: EventTemplate = { ...draft, tags: Array.from(draft.tags) };
updated.content = correctContentMentions(updated.content);
updated = addPubkeyRelayHints(updated);
updated = ensureTagContentMentions(updated);
return updated;
}
3 changes: 2 additions & 1 deletion src/helpers/nostr/reactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { kinds } from "nostr-tools";
import { DraftNostrEvent, NostrEvent, Tag } from "../../types/nostr-event";
import dayjs from "dayjs";

import { DraftNostrEvent, NostrEvent, Tag } from "../../types/nostr-event";
import { getEventCoordinate, isReplaceable } from "./event";

export type ReactionGroup = { emoji: string; url?: string; name?: string; count: number; pubkeys: string[] };
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-shareable-event-address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from "react";
import { NostrEvent } from "../types/nostr-event";
import { getSharableEventAddress } from "../services/event-relay-hint";
import { getSharableEventAddress } from "../services/relay-hints";
import useUserMailboxes from "./use-user-mailboxes";

export default function useShareableEventAddress(event: NostrEvent, overrideRelays?: string[]) {
Expand Down
6 changes: 1 addition & 5 deletions src/providers/global/publish-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PropsWithChildren, createContext, useCallback, useContext, useMemo, use
import { useToast } from "@chakra-ui/react";
import { EventTemplate, NostrEvent, UnsignedEvent, kinds } from "nostr-tools";
import { includeClientTag } from "applesauce-factory/operations";
import { addSeenRelay } from "applesauce-core/helpers";

import { useSigningContext } from "./signing-provider";
import { DraftNostrEvent } from "../../types/nostr-event";
Expand All @@ -15,10 +16,8 @@ import deleteEventService from "../../services/delete-events";
import localSettings from "../../services/local-settings";
import { NEVER_ATTACH_CLIENT_TAG, NIP_89_CLIENT_APP } from "../../const";
import { eventStore } from "../../services/event-store";
import { addPubkeyRelayHints } from "../../helpers/nostr/post";
import useCurrentAccount from "../../hooks/use-current-account";
import { useUserOutbox } from "../../hooks/use-user-mailboxes";
import { addSeenRelay } from "applesauce-core/helpers";

type PublishContextType = {
log: PublishAction[];
Expand Down Expand Up @@ -73,9 +72,6 @@ export default function PublishProvider({ children }: PropsWithChildren) {
async (event: EventTemplate | NostrEvent) => {
let draft = cloneEvent(event.kind, event);

// add pubkey relay hints
draft = addPubkeyRelayHints(draft);

// add client tag
if (
localSettings.addClientTag.value &&
Expand Down
2 changes: 1 addition & 1 deletion src/services/event-factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BehaviorSubject, Observable } from "rxjs";
import { EventFactory } from "applesauce-factory";
import { Account } from "../classes/accounts/account";
import { getEventRelayHint, getPubkeyRelayHint } from "./event-relay-hint";
import { getEventRelayHint, getPubkeyRelayHint } from "./relay-hints";
import { NIP_89_CLIENT_APP } from "../const";
import accountService from "./account";

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/views/emoji-packs/components/create-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import dayjs from "dayjs";

import { DraftNostrEvent } from "../../../types/nostr-event";
import { usePublishEvent } from "../../../providers/global/publish-provider";
import { getSharableEventAddress } from "../../../services/event-relay-hint";
import { getSharableEventAddress } from "../../../services/relay-hints";

export default function EmojiPackCreateModal({ onClose, ...props }: Omit<ModalProps, "children">) {
const publish = usePublishEvent();
Expand Down
Loading

0 comments on commit 3583373

Please sign in to comment.