refactor: rename `isTextRepost` to `tagFilterOfTextRepost`

This commit is contained in:
kPherox 2023-02-16 23:11:29 +09:00
parent d911dc8da3
commit 188b599e85
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D
5 changed files with 10 additions and 10 deletions

View File

@ -11,7 +11,7 @@ import Pin from "Icons/Pin";
import { parseZap } from "Element/Zap";
import ProfileImage from "Element/ProfileImage";
import Text from "Element/Text";
import { eventLink, getReactions, dedupeByPubkey, isTextRepost, 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";
@ -101,7 +101,7 @@ export default function Note(props: NoteProps) {
const reposts = useMemo(
() =>
dedupeByPubkey([
...getReactions(related, ev.Id, EventKind.TextNote).filter(e => e.tags.some(isTextRepost(e, ev.Id))),
...getReactions(related, ev.Id, EventKind.TextNote).filter(e => e.tags.some(tagFilterOfTextRepost(e, ev.Id))),
...getReactions(related, ev.Id, EventKind.Repost),
]),
[related, ev]

View File

@ -4,7 +4,7 @@ import { useCallback, useMemo } from "react";
import { useInView } from "react-intersection-observer";
import ArrowUp from "Icons/ArrowUp";
import { dedupeByPubkey, isTextRepost } from "Util";
import { dedupeByPubkey, tagFilterOfTextRepost } from "Util";
import ProfileImage from "Element/ProfileImage";
import useTimelineFeed, { TimelineSubject } from "Feed/TimelineFeed";
import { TaggedRawEvent } from "@snort/nostr";
@ -72,7 +72,7 @@ export default function Timeline({
return <ProfilePreview actions={<></>} pubkey={e.pubkey} className="card" />;
}
case EventKind.TextNote: {
const eRef = e.tags.find(isTextRepost(e))?.at(1);
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)} />;
}

View File

@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import { u256 } from "@snort/nostr";
import { EventKind, Subscriptions } from "@snort/nostr";
import { unixNow, unwrap, isTextRepost } from "Util";
import { unixNow, unwrap, tagFilterOfTextRepost } from "Util";
import useSubscription from "Feed/Subscription";
import { useSelector } from "react-redux";
import { RootState } from "State/Store";
@ -153,8 +153,8 @@ export default function useTimelineFeed(subject: TimelineSubject, options: Timel
.filter(a => a)
.map(a => unwrap(a)[1]);
const repostsByKind1 = main.store.notes
.filter(a => (a.kind === EventKind.Repost || a.kind === EventKind.TextNote) && a.tags.some(isTextRepost(a)))
.map(a => a.tags.find(isTextRepost(a)))
.filter(a => (a.kind === EventKind.Repost || a.kind === EventKind.TextNote) && a.tags.some(tagFilterOfTextRepost(a)))
.map(a => a.tags.find(tagFilterOfTextRepost(a)))
.filter(a => a)
.map(a => unwrap(a)[1]);
const reposts = [...repostsByKind6, ...repostsByKind1];

View File

@ -6,12 +6,12 @@ import type { NotificationRequest } from "State/Login";
import { MetadataCache, UsersDb } from "State/Users";
import { getDisplayName } from "Element/ProfileImage";
import { MentionRegex } from "Const";
import { isTextRepost } from "Util";
import { tagFilterOfTextRepost } from "Util";
export async function makeNotification(db: UsersDb, ev: TaggedRawEvent): Promise<NotificationRequest | null> {
switch (ev.kind) {
case EventKind.TextNote: {
if (ev.tags.some(isTextRepost(ev))) {
if (ev.tags.some(tagFilterOfTextRepost(ev))) {
return null;
}
const pubkeys = new Set([ev.pubkey, ...ev.tags.filter(a => a[0] === "p").map(a => a[1])]);

View File

@ -192,7 +192,7 @@ export function getNewest(rawNotes: TaggedRawEvent[]) {
}
}
export function isTextRepost(note: TaggedRawEvent, id?: u256): (tag: string[], i: number) => boolean {
export function tagFilterOfTextRepost(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);
}