Merge pull request #314 from kphrx/feat/kind1-reposts

feat: render kind 1 reposts
This commit is contained in:
2023-02-18 23:01:28 +00:00
committed by GitHub
6 changed files with 48 additions and 7 deletions

View File

@ -11,7 +11,15 @@ import Pin from "Icons/Pin";
import { parseZap } from "Element/Zap";
import ProfileImage from "Element/ProfileImage";
import Text from "Element/Text";
import { eventLink, getReactions, dedupeByPubkey, hexToBech32, normalizeReaction, Reaction } from "Util";
import {
eventLink,
getReactions,
dedupeByPubkey,
tagFilterOfTextRepost,
hexToBech32,
normalizeReaction,
Reaction,
} from "Util";
import NoteFooter, { Translation } from "Element/NoteFooter";
import NoteTime from "Element/NoteTime";
import { useUserProfiles } from "Feed/ProfileFeed";
@ -98,7 +106,14 @@ export default function Note(props: NoteProps) {
}, [reactions]);
const positive = groupReactions[Reaction.Positive];
const negative = groupReactions[Reaction.Negative];
const reposts = useMemo(() => dedupeByPubkey(getReactions(related, ev.Id, EventKind.Repost)), [related, ev]);
const reposts = useMemo(
() =>
dedupeByPubkey([
...getReactions(related, ev.Id, EventKind.TextNote).filter(e => e.tags.some(tagFilterOfTextRepost(e, ev.Id))),
...getReactions(related, ev.Id, EventKind.Repost),
]),
[related, ev]
);
const zaps = useMemo(() => {
const sortedZaps = getReactions(related, ev.Id, EventKind.ZapReceipt)
.map(parseZap)

View File

@ -30,7 +30,12 @@ export default function NoteReaction(props: NoteReactionProps) {
return null;
}, [ev]);
if (ev.Kind !== EventKind.Reaction && ev.Kind !== EventKind.Repost) {
if (
ev.Kind !== EventKind.Reaction &&
ev.Kind !== EventKind.Repost &&
(ev.Kind !== EventKind.TextNote ||
ev.Tags.every((a, i) => a.Event !== refEvent || a.Marker !== "mention" || ev.Content !== `#[${i}]`))
) {
return null;
}
@ -52,7 +57,7 @@ export default function NoteReaction(props: NoteReactionProps) {
const root = extractRoot();
const isOpMuted = root && isMuted(root.pubkey);
const opt = {
showHeader: ev?.Kind === EventKind.Repost,
showHeader: ev?.Kind === EventKind.Repost || ev?.Kind === EventKind.TextNote,
showFooter: false,
};

View File

@ -4,7 +4,7 @@ import { useCallback, useMemo } from "react";
import { useInView } from "react-intersection-observer";
import ArrowUp from "Icons/ArrowUp";
import { dedupeByPubkey } from "Util";
import { dedupeByPubkey, tagFilterOfTextRepost } from "Util";
import ProfileImage from "Element/ProfileImage";
import useTimelineFeed, { TimelineSubject } from "Feed/TimelineFeed";
import { TaggedRawEvent } from "@snort/nostr";
@ -72,6 +72,10 @@ export default function Timeline({
return <ProfilePreview actions={<></>} pubkey={e.pubkey} className="card" />;
}
case EventKind.TextNote: {
const eRef = e.tags.find(tagFilterOfTextRepost(e))?.at(1);
if (eRef) {
return <NoteReaction data={e} key={e.id} root={parent.notes.find(a => a.id === eRef)} />;
}
return <Note key={e.id} data={e} related={related.notes} ignoreModeration={ignoreModeration} />;
}
case EventKind.ZapReceipt: {