Support kind 16 generic reposts

This commit is contained in:
hzrd149 2024-01-14 16:24:21 +00:00
parent fd6ce3ec31
commit aaa62088a1
17 changed files with 40 additions and 16 deletions

View File

@ -0,0 +1,5 @@
---
"nostrudel": minor
---
Support kind 16 generic reposts

View File

@ -11,7 +11,10 @@ import Timestamp from "../timestamp";
export default function RepostDetails({ event }: { event: NostrEvent }) {
const readRelays = useReadRelayUrls();
const timeline = useTimelineLoader(`${event.id}-reposts`, readRelays, { kinds: [kinds.Repost], "#e": [event.id] });
const timeline = useTimelineLoader(`${event.id}-reposts`, readRelays, {
kinds: [kinds.Repost, kinds.GenericRepost],
"#e": [event.id],
});
const reposts = useSubject(timeline.timeline);

View File

@ -23,6 +23,7 @@ const kindColors: Record<number, FlexProps["bg"]> = {
[kinds.RecommendRelay]: "pink",
[kinds.EncryptedDirectMessage]: "orange.500",
[kinds.Repost]: "yellow",
[kinds.GenericRepost]: "yellow",
[kinds.Reaction]: "green.500",
[kinds.LongFormArticle]: "purple.500",
};

View File

@ -24,7 +24,7 @@ export default function LoadingNostrLink({ link }: { link: nip19.DecodeResult })
Pubkey: <UserLink pubkey={link.data.author} />
</Text>
)}
{link.data.relays && <Text>Relays: {link.data.relays.join(", ")}</Text>}
{link.data.relays && link.data.relays.length > 0 && <Text>Relays: {link.data.relays.join(", ")}</Text>}
</>
);
case "npub":
@ -33,7 +33,7 @@ export default function LoadingNostrLink({ link }: { link: nip19.DecodeResult })
return (
<>
<Text>Pubkey: {link.data.pubkey}</Text>
{link.data.relays && <Text>Relays: {link.data.relays.join(", ")}</Text>}
{link.data.relays && link.data.relays.length > 0 && <Text>Relays: {link.data.relays.join(", ")}</Text>}
</>
);
case "naddr":

View File

@ -32,9 +32,10 @@ function buildRepost(event: NostrEvent): DraftNostrEvent {
const hint = relayHintService.getEventRelayHint(event);
const tags: NostrEvent["tags"] = [];
tags.push(["e", event.id, hint ?? ""]);
tags.push(["k", String(event.kind)]);
return {
kind: kinds.Repost,
kind: event.kind === kinds.ShortTextNote ? kinds.Repost : kinds.GenericRepost,
tags,
content: JSON.stringify(event),
created_at: dayjs().unix(),

View File

@ -18,7 +18,7 @@ import { parseHardcodedNoteContent } from "../../../helpers/nostr/events";
import { getEventCommunityPointer } from "../../../helpers/nostr/communities";
import LoadingNostrLink from "../../loading-nostr-link";
export default function RepostNote({ event }: { event: NostrEvent }) {
export default function RepostEvent({ event }: { event: NostrEvent }) {
const muteFilter = useUserMuteFilter();
const hardCodedNote = parseHardcodedNoteContent(event);

View File

@ -5,7 +5,7 @@ import { Box, Text } from "@chakra-ui/react";
import { ErrorBoundary } from "../../error-boundary";
import ReplyNote from "./reply-note";
import Note from "../../note";
import RepostNote from "./repost-note";
import RepostEvent from "./repost-event";
import ArticleNote from "./article-note";
import StreamNote from "./stream-note";
import RelayRecommendation from "./relay-recommendation";
@ -27,7 +27,10 @@ function TimelineItem({ event, visible, minHeight }: { event: NostrEvent; visibl
content = isReply(event) ? <ReplyNote event={event} /> : <Note event={event} showReplyButton />;
break;
case kinds.Repost:
content = <RepostNote event={event} />;
content = <RepostEvent event={event} />;
break;
case kinds.GenericRepost:
content = <RepostEvent event={event} />;
break;
case kinds.LongFormArticle:
content = <ArticleNote article={event} />;

View File

@ -45,7 +45,7 @@ export default function MediaTimeline({ timeline }: { timeline: TimelineLoader }
var images: PhotoWithEvent[] = [];
for (const event of events) {
if (event.kind === kinds.Repost) continue;
if (event.kind === kinds.Repost || event.kind === kinds.GenericRepost) continue;
const urls = event.content.matchAll(getMatchLink());
let i = 0;

View File

@ -41,7 +41,7 @@ export function getEventUID(event: NostrEvent) {
}
export function isReply(event: NostrEvent | DraftNostrEvent) {
if (event.kind === kinds.Repost) return false;
if (event.kind === kinds.Repost || event.kind === kinds.GenericRepost) return false;
// TODO: update this to only look for a "root" or "reply" tag
return !!getReferences(event).reply;
}
@ -50,7 +50,7 @@ export function isMentionedInContent(event: NostrEvent | DraftNostrEvent, pubkey
}
export function isRepost(event: NostrEvent | DraftNostrEvent) {
if (event.kind === kinds.Repost) return true;
if (event.kind === kinds.Repost || event.kind === kinds.GenericRepost) return true;
const match = event.content.match(getMatchNostrLink());
return match && match[0].length === event.content.length;

View File

@ -44,6 +44,7 @@ export default function NotificationTimelineProvider({ children }: PropsWithChil
kinds: [
kinds.ShortTextNote,
kinds.Repost,
kinds.GenericRepost,
kinds.Reaction,
kinds.Zap,
TORRENT_COMMENT_KIND,

View File

@ -109,7 +109,7 @@ function CommunitiesHomePage() {
readRelays,
communityCoordinates.length > 0
? {
kinds: [kinds.ShortTextNote, kinds.Repost, COMMUNITY_APPROVAL_KIND],
kinds: [kinds.ShortTextNote, kinds.Repost, kinds.GenericRepost, COMMUNITY_APPROVAL_KIND],
"#a": communityCoordinates.map((p) => createCoordinate(p.kind, p.pubkey, p.identifier)),
}
: undefined,

View File

@ -52,7 +52,7 @@ export default function CommunityHomePage({ community }: { community: NostrEvent
const communityRelays = getCommunityRelays(community);
const readRelays = useReadRelayUrls(communityRelays);
const timeline = useTimelineLoader(`${getEventUID(community)}-timeline`, readRelays, {
kinds: [kinds.ShortTextNote, kinds.Repost, COMMUNITY_APPROVAL_KIND],
kinds: [kinds.ShortTextNote, kinds.Repost, kinds.GenericRepost, COMMUNITY_APPROVAL_KIND],
"#a": [communityCoordinate],
});

View File

@ -179,6 +179,8 @@ export default function CommunityPost({ event, ...props }: Omit<CardProps, "chil
return <CommunityTextPost event={event} {...props} />;
case kinds.Repost:
return <CommunityRepostPost event={event} {...props} />;
case kinds.GenericRepost:
return <CommunityRepostPost event={event} {...props} />;
}
return null;
}

View File

@ -15,7 +15,14 @@ import useClientSideMuteFilter from "../../hooks/use-client-side-mute-filter";
import NoteFilterTypeButtons from "../../components/note-filter-type-buttons";
import KindSelectionProvider, { useKindSelectionContext } from "../../providers/local/kind-selection-provider";
const defaultKinds = [kinds.ShortTextNote, kinds.Repost, kinds.LongFormArticle, kinds.RecommendRelay, kinds.BadgeAward];
const defaultKinds = [
kinds.ShortTextNote,
kinds.Repost,
kinds.GenericRepost,
kinds.LongFormArticle,
kinds.RecommendRelay,
kinds.BadgeAward,
];
function HomePage() {
const showReplies = useDisclosure({ defaultIsOpen: localStorage.getItem("show-replies") === "true" });

View File

@ -11,7 +11,7 @@ import IntersectionObserverProvider, {
import useSubject from "../../hooks/use-subject";
import { useTimelineCurserIntersectionCallback } from "../../hooks/use-timeline-cursor-intersection-callback";
import { useNotificationTimeline } from "../../providers/global/notification-timeline";
import { getEventUID, isReply } from "../../helpers/nostr/events";
import { getEventUID, isReply, isRepost } from "../../helpers/nostr/events";
import PeopleListProvider, { usePeopleListContext } from "../../providers/local/people-list-provider";
import PeopleListSelection from "../../components/people-list-selection/people-list-selection";
import VerticalPageLayout from "../../components/vertical-page-layout";
@ -68,7 +68,7 @@ const NotificationsTimeline = memo(
if (!showMentions && !isReply(e)) return false;
}
if (!showReactions && e.kind === kinds.Reaction) return false;
if (!showReposts && e.kind === kinds.Repost) return false;
if (!showReposts && (e.kind === kinds.Repost || e.kind === kinds.GenericRepost)) return false;
if (!showZaps && e.kind === kinds.Zap) return false;
return true;

View File

@ -45,6 +45,7 @@ const commonTimelineKinds = [
kinds.ShortTextNote,
kinds.LongFormArticle,
kinds.Repost,
kinds.GenericRepost,
kinds.Reaction,
kinds.BadgeAward,
kinds.BadgeDefinition,

View File

@ -35,7 +35,7 @@ export default function UserNotesTab() {
readRelays,
{
authors: [pubkey],
kinds: [kinds.ShortTextNote, kinds.Repost, kinds.LongFormArticle, STREAM_KIND, 2],
kinds: [kinds.ShortTextNote, kinds.Repost, kinds.GenericRepost, kinds.LongFormArticle, STREAM_KIND, 2],
},
{ eventFilter },
);