forked from Kieran/snort
refactor: extract repost filter to Util.isTextRepost
resolve https://github.com/v0l/snort/pull/314\#discussion_r1108279333
This commit is contained in:
parent
dfa2bf5873
commit
615c2a974a
@ -11,7 +11,7 @@ import Pin from "Icons/Pin";
|
|||||||
import { parseZap } from "Element/Zap";
|
import { parseZap } from "Element/Zap";
|
||||||
import ProfileImage from "Element/ProfileImage";
|
import ProfileImage from "Element/ProfileImage";
|
||||||
import Text from "Element/Text";
|
import Text from "Element/Text";
|
||||||
import { eventLink, getReactions, dedupeByPubkey, hexToBech32, normalizeReaction, Reaction } from "Util";
|
import { eventLink, getReactions, dedupeByPubkey, isTextRepost, hexToBech32, normalizeReaction, Reaction } from "Util";
|
||||||
import NoteFooter, { Translation } from "Element/NoteFooter";
|
import NoteFooter, { Translation } from "Element/NoteFooter";
|
||||||
import NoteTime from "Element/NoteTime";
|
import NoteTime from "Element/NoteTime";
|
||||||
import { useUserProfiles } from "Feed/ProfileFeed";
|
import { useUserProfiles } from "Feed/ProfileFeed";
|
||||||
@ -108,9 +108,7 @@ export default function Note(props: NoteProps) {
|
|||||||
const reposts = useMemo(
|
const reposts = useMemo(
|
||||||
() =>
|
() =>
|
||||||
dedupeByPubkey([
|
dedupeByPubkey([
|
||||||
...getReactions(related, ev.Id, EventKind.TextNote).filter(e =>
|
...getReactions(related, ev.Id, EventKind.TextNote).filter(e => e.tags.some(isTextRepost(e, ev.Id))),
|
||||||
e.tags.some((a, i) => a[0] === "e" && a[1] === ev.Id && a[3] === "mention" && e.content === `#[${i}]`)
|
|
||||||
),
|
|
||||||
...getReactions(related, ev.Id, EventKind.Repost),
|
...getReactions(related, ev.Id, EventKind.Repost),
|
||||||
]),
|
]),
|
||||||
[related, ev]
|
[related, ev]
|
||||||
|
@ -4,7 +4,7 @@ import { useCallback, useMemo } from "react";
|
|||||||
import { useInView } from "react-intersection-observer";
|
import { useInView } from "react-intersection-observer";
|
||||||
|
|
||||||
import ArrowUp from "Icons/ArrowUp";
|
import ArrowUp from "Icons/ArrowUp";
|
||||||
import { dedupeByPubkey } from "Util";
|
import { dedupeByPubkey, isTextRepost } from "Util";
|
||||||
import ProfileImage from "Element/ProfileImage";
|
import ProfileImage from "Element/ProfileImage";
|
||||||
import useTimelineFeed, { TimelineSubject } from "Feed/TimelineFeed";
|
import useTimelineFeed, { TimelineSubject } from "Feed/TimelineFeed";
|
||||||
import { TaggedRawEvent } from "@snort/nostr";
|
import { TaggedRawEvent } from "@snort/nostr";
|
||||||
@ -72,7 +72,7 @@ export default function Timeline({
|
|||||||
return <ProfilePreview actions={<></>} pubkey={e.pubkey} className="card" />;
|
return <ProfilePreview actions={<></>} pubkey={e.pubkey} className="card" />;
|
||||||
}
|
}
|
||||||
case EventKind.TextNote: {
|
case EventKind.TextNote: {
|
||||||
const eRef = e.tags.find((a, i) => a[0] === "e" && a[3] === "mention" && e.content === `#[${i}]`)?.at(1);
|
const eRef = e.tags.find(isTextRepost(e))?.at(1);
|
||||||
if (eRef) {
|
if (eRef) {
|
||||||
return <NoteReaction data={e} key={e.id} root={parent.notes.find(a => a.id === eRef)} />;
|
return <NoteReaction data={e} key={e.id} root={parent.notes.find(a => a.id === eRef)} />;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { u256 } from "@snort/nostr";
|
import { u256 } from "@snort/nostr";
|
||||||
import { EventKind, Subscriptions } from "@snort/nostr";
|
import { EventKind, Subscriptions } from "@snort/nostr";
|
||||||
import { unixNow, unwrap } from "Util";
|
import { unixNow, unwrap, isTextRepost } from "Util";
|
||||||
import useSubscription from "Feed/Subscription";
|
import useSubscription from "Feed/Subscription";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { RootState } from "State/Store";
|
import { RootState } from "State/Store";
|
||||||
@ -153,12 +153,8 @@ export default function useTimelineFeed(subject: TimelineSubject, options: Timel
|
|||||||
.filter(a => a)
|
.filter(a => a)
|
||||||
.map(a => unwrap(a)[1]);
|
.map(a => unwrap(a)[1]);
|
||||||
const repostsByKind1 = main.store.notes
|
const repostsByKind1 = main.store.notes
|
||||||
.filter(
|
.filter(a => (a.kind === EventKind.Repost || a.kind === EventKind.TextNote) && a.tags.some(isTextRepost(a)))
|
||||||
a =>
|
.map(a => a.tags.find(isTextRepost(a)))
|
||||||
(a.kind === EventKind.Repost || a.kind === EventKind.TextNote) &&
|
|
||||||
a.tags.some(b => b[0] === "e" && b[3] === "mention")
|
|
||||||
)
|
|
||||||
.map(a => a.tags.find((b, i) => b[0] === "e" && b[3] === "mention" && a.content === `#[${i}]`))
|
|
||||||
.filter(a => a)
|
.filter(a => a)
|
||||||
.map(a => unwrap(a)[1]);
|
.map(a => unwrap(a)[1]);
|
||||||
const reposts = [...repostsByKind6, ...repostsByKind1];
|
const reposts = [...repostsByKind6, ...repostsByKind1];
|
||||||
|
@ -6,12 +6,12 @@ import type { NotificationRequest } from "State/Login";
|
|||||||
import { MetadataCache, UsersDb } from "State/Users";
|
import { MetadataCache, UsersDb } from "State/Users";
|
||||||
import { getDisplayName } from "Element/ProfileImage";
|
import { getDisplayName } from "Element/ProfileImage";
|
||||||
import { MentionRegex } from "Const";
|
import { MentionRegex } from "Const";
|
||||||
|
import { isTextRepost } from "Util";
|
||||||
|
|
||||||
export async function makeNotification(db: UsersDb, ev: TaggedRawEvent): Promise<NotificationRequest | null> {
|
export async function makeNotification(db: UsersDb, ev: TaggedRawEvent): Promise<NotificationRequest | null> {
|
||||||
switch (ev.kind) {
|
switch (ev.kind) {
|
||||||
case EventKind.TextNote: {
|
case EventKind.TextNote: {
|
||||||
const isRepost = ev.tags.some((a, i) => a[0] === "e" && a[3] === "mention" && ev.content === `#[${i}]`);
|
if (ev.tags.some(isTextRepost(ev))) {
|
||||||
if (isRepost) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const pubkeys = new Set([ev.pubkey, ...ev.tags.filter(a => a[0] === "p").map(a => a[1])]);
|
const pubkeys = new Set([ev.pubkey, ...ev.tags.filter(a => a[0] === "p").map(a => a[1])]);
|
||||||
|
@ -191,3 +191,8 @@ export function getNewest(rawNotes: TaggedRawEvent[]) {
|
|||||||
return notes[0];
|
return notes[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isTextRepost(note: TaggedRawEvent, id?: u256): (tag: string[], i: number) => boolean {
|
||||||
|
return (tag, i) =>
|
||||||
|
tag[0] === "e" && tag[3] === "mention" && note.content === `#[${i}]` && (id ? tag[1] === id : true);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user