fix bug with community "a" tags as root

This commit is contained in:
hzrd149
2023-12-13 07:38:25 -06:00
parent 2be85b012d
commit e15c2a9ce8
10 changed files with 18 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ import SettingsView from "./views/settings";
import NostrLinkView from "./views/link"; import NostrLinkView from "./views/link";
import ProfileView from "./views/profile"; import ProfileView from "./views/profile";
import HashTagView from "./views/hashtag"; import HashTagView from "./views/hashtag";
import ThreadView from "./views/note"; import ThreadView from "./views/thread";
import NotificationsView from "./views/notifications"; import NotificationsView from "./views/notifications";
import DirectMessagesView from "./views/dms"; import DirectMessagesView from "./views/dms";
import DirectMessageChatView from "./views/dms/chat"; import DirectMessageChatView from "./views/dms/chat";

View File

@@ -36,7 +36,7 @@ import { useRegisterIntersectionEntity } from "../../providers/intersection-obse
import BookmarkButton from "./components/bookmark-button"; import BookmarkButton from "./components/bookmark-button";
import useCurrentAccount from "../../hooks/use-current-account"; import useCurrentAccount from "../../hooks/use-current-account";
import NoteReactions from "./components/note-reactions"; 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 { getReferences } from "../../helpers/nostr/events";
import Timestamp from "../timestamp"; import Timestamp from "../timestamp";
import OpenInDrawerButton from "../open-in-drawer-button"; import OpenInDrawerButton from "../open-in-drawer-button";

View File

@@ -1,10 +1,11 @@
import { Kind, nip19, validateEvent } from "nostr-tools"; 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 { RelayConfig, RelayMode } from "../../classes/relay";
import { getMatchNostrLink } from "../regexp"; import { getMatchNostrLink } from "../regexp";
import { AddressPointer } from "nostr-tools/lib/types/nip19"; import { AddressPointer } from "nostr-tools/lib/types/nip19";
import { safeJson } from "../parse"; import { safeJson } from "../parse";
import { COMMUNITY_DEFINITION_KIND } from "./communities";
export function truncatedId(str: string, keep = 6) { export function truncatedId(str: string, keep = 6) {
if (str.length < keep * 2 + 3) return str; if (str.length < keep * 2 + 3) return str;
@@ -26,6 +27,7 @@ export function getEventUID(event: NostrEvent) {
export function isReply(event: NostrEvent | DraftNostrEvent) { export function isReply(event: NostrEvent | DraftNostrEvent) {
if (event.kind === Kind.Repost) return false; if (event.kind === Kind.Repost) return false;
// TODO: update this to only look for a "root" or "reply" tag
return !!getReferences(event).replyId; return !!getReferences(event).replyId;
} }
export function isMentionedInContent(event: NostrEvent | DraftNostrEvent, pubkey: string) { export function isMentionedInContent(event: NostrEvent | DraftNostrEvent, pubkey: string) {
@@ -96,12 +98,19 @@ export function filterTagsByContentRefs(content: string, tags: Tag[], referenced
return newTags; 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<typeof getReferences>; export type EventReferences = ReturnType<typeof getReferences>;
export function getReferences(event: NostrEvent | DraftNostrEvent) { export function getReferences(event: NostrEvent | DraftNostrEvent) {
const contentTagRefs = getContentTagRefs(event.content, event.tags); const contentTagRefs = getContentTagRefs(event.content, event.tags);
const replyTag = event.tags.find((t) => t[3] === "reply"); // find the root and reply tags.
const rootTag = event.tags.find((t) => t[3] === "root"); // 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"); const mentionTags = event.tags.find((t) => t[3] === "mention");
let replyId = replyTag?.[1]; let replyId = replyTag?.[1];

View File

@@ -26,7 +26,7 @@ import {
import { Location, RouteObject, RouterProvider, To, createMemoryRouter, useNavigate } from "react-router-dom"; import { Location, RouteObject, RouterProvider, To, createMemoryRouter, useNavigate } from "react-router-dom";
import { ErrorBoundary } from "../components/error-boundary"; import { ErrorBoundary } from "../components/error-boundary";
import ThreadView from "../views/note"; import ThreadView from "../views/thread";
import { ChevronLeftIcon, ChevronRightIcon, ExternalLinkIcon } from "../components/icons"; import { ChevronLeftIcon, ChevronRightIcon, ExternalLinkIcon } from "../components/icons";
import { PageProviders } from "."; import { PageProviders } from ".";
import { logger } from "../helpers/debug"; import { logger } from "../helpers/debug";

View File

@@ -1,6 +1,6 @@
import { RouteObject } from "react-router-dom"; import { RouteObject } from "react-router-dom";
import ThreadView from "./views/note"; import ThreadView from "./views/thread";
export const threadRoute: RouteObject = { export const threadRoute: RouteObject = {
path: "/n/:id", path: "/n/:id",

View File

@@ -30,7 +30,7 @@ import { TrustProvider } from "../../../providers/trust";
import { NoteContents } from "../../../components/note/text-note-contents"; import { NoteContents } from "../../../components/note/text-note-contents";
import NoteReactions from "../../../components/note/components/note-reactions"; import NoteReactions from "../../../components/note/components/note-reactions";
import { ReplyIcon } from "../../../components/icons"; 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 EventInteractionDetailsModal from "../../../components/event-interactions-modal";
import NoteZapButton from "../../../components/note/note-zap-button"; import NoteZapButton from "../../../components/note/note-zap-button";
import useThreadColorLevelProps from "../../../hooks/use-thread-color-level-props"; import useThreadColorLevelProps from "../../../hooks/use-thread-color-level-props";

View File

@@ -43,7 +43,7 @@ import NoteZapButton from "../../components/note/note-zap-button";
import TorrentMenu from "./components/torrent-menu"; import TorrentMenu from "./components/torrent-menu";
import { QuoteRepostButton } from "../../components/note/components/quote-repost-button"; import { QuoteRepostButton } from "../../components/note/components/quote-repost-button";
import TorrentComments from "./components/torrents-comments"; 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 { getReferences } from "../../helpers/nostr/events";
import MessageTextCircle01 from "../../components/icons/message-text-circle-01"; import MessageTextCircle01 from "../../components/icons/message-text-circle-01";