From e15c2a9ce861ff49af6e42481fb918f668eb1c34 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Wed, 13 Dec 2023 07:38:25 -0600 Subject: [PATCH] fix bug with community "a" tags as root --- src/app.tsx | 2 +- src/components/note/index.tsx | 2 +- src/helpers/nostr/events.ts | 15 ++++++++++++--- src/providers/drawer-sub-view-provider.tsx | 2 +- src/routes.tsx | 2 +- .../{note => thread}/components/reply-form.tsx | 0 .../{note => thread}/components/thread-post.tsx | 0 src/views/{note => thread}/index.tsx | 0 .../torrents/components/torrents-comments.tsx | 2 +- src/views/torrents/torrent.tsx | 2 +- 10 files changed, 18 insertions(+), 9 deletions(-) rename src/views/{note => thread}/components/reply-form.tsx (100%) rename src/views/{note => thread}/components/thread-post.tsx (100%) rename src/views/{note => thread}/index.tsx (100%) diff --git a/src/app.tsx b/src/app.tsx index 9c711466b..5876e923f 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -14,7 +14,7 @@ import SettingsView from "./views/settings"; import NostrLinkView from "./views/link"; import ProfileView from "./views/profile"; import HashTagView from "./views/hashtag"; -import ThreadView from "./views/note"; +import ThreadView from "./views/thread"; import NotificationsView from "./views/notifications"; import DirectMessagesView from "./views/dms"; import DirectMessageChatView from "./views/dms/chat"; diff --git a/src/components/note/index.tsx b/src/components/note/index.tsx index a6a750bbf..25a11d3a9 100644 --- a/src/components/note/index.tsx +++ b/src/components/note/index.tsx @@ -36,7 +36,7 @@ import { useRegisterIntersectionEntity } from "../../providers/intersection-obse import BookmarkButton from "./components/bookmark-button"; import useCurrentAccount from "../../hooks/use-current-account"; import NoteReactions from "./components/note-reactions"; -import ReplyForm from "../../views/note/components/reply-form"; +import ReplyForm from "../../views/thread/components/reply-form"; import { getReferences } from "../../helpers/nostr/events"; import Timestamp from "../timestamp"; import OpenInDrawerButton from "../open-in-drawer-button"; diff --git a/src/helpers/nostr/events.ts b/src/helpers/nostr/events.ts index a28da2539..8e0be2bd5 100644 --- a/src/helpers/nostr/events.ts +++ b/src/helpers/nostr/events.ts @@ -1,10 +1,11 @@ import { Kind, nip19, validateEvent } from "nostr-tools"; -import { ATag, DraftNostrEvent, isDTag, isETag, isPTag, NostrEvent, RTag, Tag } from "../../types/nostr-event"; +import { ATag, DraftNostrEvent, isDTag, isETag, NostrEvent, RTag, Tag } from "../../types/nostr-event"; import { RelayConfig, RelayMode } from "../../classes/relay"; import { getMatchNostrLink } from "../regexp"; import { AddressPointer } from "nostr-tools/lib/types/nip19"; import { safeJson } from "../parse"; +import { COMMUNITY_DEFINITION_KIND } from "./communities"; export function truncatedId(str: string, keep = 6) { if (str.length < keep * 2 + 3) return str; @@ -26,6 +27,7 @@ export function getEventUID(event: NostrEvent) { export function isReply(event: NostrEvent | DraftNostrEvent) { if (event.kind === Kind.Repost) return false; + // TODO: update this to only look for a "root" or "reply" tag return !!getReferences(event).replyId; } export function isMentionedInContent(event: NostrEvent | DraftNostrEvent, pubkey: string) { @@ -96,12 +98,19 @@ export function filterTagsByContentRefs(content: string, tags: Tag[], referenced return newTags; } +function isCommunityRefTag(t: Tag): t is ATag { + return t.length >= 2 && t[0] === "a" && t[1].startsWith(COMMUNITY_DEFINITION_KIND + ":"); +} + export type EventReferences = ReturnType; export function getReferences(event: NostrEvent | DraftNostrEvent) { const contentTagRefs = getContentTagRefs(event.content, event.tags); - const replyTag = event.tags.find((t) => t[3] === "reply"); - const rootTag = event.tags.find((t) => t[3] === "root"); + // find the root and reply tags. + // NOTE: Ignore community reference tags since there is another client out there that is marking them as "root" + // and it dose not make sense to "reply" to a community + const replyTag = event.tags.find((t) => !isCommunityRefTag(t) && t[3] === "reply"); + const rootTag = event.tags.find((t) => !isCommunityRefTag(t) && t[3] === "root"); const mentionTags = event.tags.find((t) => t[3] === "mention"); let replyId = replyTag?.[1]; diff --git a/src/providers/drawer-sub-view-provider.tsx b/src/providers/drawer-sub-view-provider.tsx index 8700dd9b6..2dde85453 100644 --- a/src/providers/drawer-sub-view-provider.tsx +++ b/src/providers/drawer-sub-view-provider.tsx @@ -26,7 +26,7 @@ import { import { Location, RouteObject, RouterProvider, To, createMemoryRouter, useNavigate } from "react-router-dom"; import { ErrorBoundary } from "../components/error-boundary"; -import ThreadView from "../views/note"; +import ThreadView from "../views/thread"; import { ChevronLeftIcon, ChevronRightIcon, ExternalLinkIcon } from "../components/icons"; import { PageProviders } from "."; import { logger } from "../helpers/debug"; diff --git a/src/routes.tsx b/src/routes.tsx index e6a4cb799..5411ebce9 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -1,6 +1,6 @@ import { RouteObject } from "react-router-dom"; -import ThreadView from "./views/note"; +import ThreadView from "./views/thread"; export const threadRoute: RouteObject = { path: "/n/:id", diff --git a/src/views/note/components/reply-form.tsx b/src/views/thread/components/reply-form.tsx similarity index 100% rename from src/views/note/components/reply-form.tsx rename to src/views/thread/components/reply-form.tsx diff --git a/src/views/note/components/thread-post.tsx b/src/views/thread/components/thread-post.tsx similarity index 100% rename from src/views/note/components/thread-post.tsx rename to src/views/thread/components/thread-post.tsx diff --git a/src/views/note/index.tsx b/src/views/thread/index.tsx similarity index 100% rename from src/views/note/index.tsx rename to src/views/thread/index.tsx diff --git a/src/views/torrents/components/torrents-comments.tsx b/src/views/torrents/components/torrents-comments.tsx index 1b76dd7de..ef8790a4c 100644 --- a/src/views/torrents/components/torrents-comments.tsx +++ b/src/views/torrents/components/torrents-comments.tsx @@ -30,7 +30,7 @@ import { TrustProvider } from "../../../providers/trust"; import { NoteContents } from "../../../components/note/text-note-contents"; import NoteReactions from "../../../components/note/components/note-reactions"; import { ReplyIcon } from "../../../components/icons"; -import ReplyForm from "../../note/components/reply-form"; +import ReplyForm from "../../thread/components/reply-form"; import EventInteractionDetailsModal from "../../../components/event-interactions-modal"; import NoteZapButton from "../../../components/note/note-zap-button"; import useThreadColorLevelProps from "../../../hooks/use-thread-color-level-props"; diff --git a/src/views/torrents/torrent.tsx b/src/views/torrents/torrent.tsx index f7a32c187..3c872937a 100644 --- a/src/views/torrents/torrent.tsx +++ b/src/views/torrents/torrent.tsx @@ -43,7 +43,7 @@ import NoteZapButton from "../../components/note/note-zap-button"; import TorrentMenu from "./components/torrent-menu"; import { QuoteRepostButton } from "../../components/note/components/quote-repost-button"; import TorrentComments from "./components/torrents-comments"; -import ReplyForm from "../note/components/reply-form"; +import ReplyForm from "../thread/components/reply-form"; import { getReferences } from "../../helpers/nostr/events"; import MessageTextCircle01 from "../../components/icons/message-text-circle-01";