From 28337e5915671d1b3f53dfe11b24fbe24f069b96 Mon Sep 17 00:00:00 2001 From: reya <123083837+reyamir@users.noreply.github.com> Date: Sat, 4 May 2024 08:29:52 +0700 Subject: [PATCH] feat: improve dedup events --- packages/ark/src/ark.ts | 43 ++++++++++++++++---------------- packages/ui/src/note/content.tsx | 11 +++----- src-tauri/src/nostr/keys.rs | 16 ------------ 3 files changed, 25 insertions(+), 45 deletions(-) diff --git a/packages/ark/src/ark.ts b/packages/ark/src/ark.ts index 16114ec8..e15f4804 100644 --- a/packages/ark/src/ark.ts +++ b/packages/ark/src/ark.ts @@ -1,13 +1,14 @@ -import type { - Account, - Contact, - Event, - EventWithReplies, - Interests, - Keys, - LumeColumn, - Metadata, - Settings, +import { + Kind, + type Account, + type Contact, + type Event, + type EventWithReplies, + type Interests, + type Keys, + type LumeColumn, + type Metadata, + type Settings, } from "@lume/types"; import { generateContentTags } from "@lume/utils"; import { invoke } from "@tauri-apps/api/core"; @@ -169,8 +170,6 @@ export class Ark { if (asOf && asOf > 0) until = asOf.toString(); const seenIds = new Set(); - const dedupQueue = new Set(); - const nostrEvents: Event[] = await invoke("get_events", { limit, until, @@ -178,24 +177,24 @@ export class Ark { global: isGlobal, }); + // remove duplicate event for (const event of nostrEvents) { + if (event.kind === Kind.Repost) { + const repostId = event.tags.find((tag) => tag[0] === "e")?.[1]; + seenIds.add(repostId); + } + const eventIds = event.tags - .filter((el) => el[3] === "root" || el[3] === "reply") + .filter((el) => el[0] === "e") ?.map((item) => item[1]); - if (eventIds.length) { - for (const id of eventIds) { - if (seenIds.has(id)) { - dedupQueue.add(event.id); - break; - } - seenIds.add(id); - } + if (eventIds && eventIds.length) { + eventIds.forEach((id) => seenIds.add(id)); } } const events = nostrEvents - .filter((event) => !dedupQueue.has(event.id)) + .filter((event) => !seenIds.has(event.id)) .sort((a, b) => b.created_at - a.created_at); if (this.settings?.nsfw) { diff --git a/packages/ui/src/note/content.tsx b/packages/ui/src/note/content.tsx index f4dd7f80..5db2ff9b 100644 --- a/packages/ui/src/note/content.tsx +++ b/packages/ui/src/note/content.tsx @@ -7,7 +7,7 @@ import { MentionUser } from "./mentions/user"; import { Images } from "./preview/images"; import { Videos } from "./preview/videos"; import { useNoteContext } from "./provider"; -import { useRouteContext } from "@tanstack/react-router"; +import { nanoid } from "nanoid"; export function NoteContent({ quote = true, @@ -20,7 +20,6 @@ export function NoteContent({ clean?: boolean; className?: string; }) { - const { ark } = useRouteContext({ strict: false }); const event = useNoteContext(); const data = useMemo(() => { const { content, images, videos } = parser(event.content); @@ -90,11 +89,9 @@ export function NoteContent({ ), ); - richContent = reactStringReplace( - richContent, - /(\r\n|\r|\n)+/g, - (_, index) =>
, - ); + richContent = reactStringReplace(richContent, /(\r\n|\r|\n)+/g, () => ( +
+ )); return { content: richContent, images, videos }; } catch (e) { diff --git a/src-tauri/src/nostr/keys.rs b/src-tauri/src/nostr/keys.rs index 92790acb..383cbf39 100644 --- a/src-tauri/src/nostr/keys.rs +++ b/src-tauri/src/nostr/keys.rs @@ -172,22 +172,6 @@ pub async fn load_selected_account(npub: &str, state: State<'_, Nostr>) -> Resul client.set_signer(Some(signer)).await; } - // Verify signer - let signer = client.signer().await.unwrap(); - - // Get public key - let public_key = signer.public_key().await.unwrap(); - let filter = Filter::new().pubkey(public_key).limit(200).kinds(vec![ - Kind::TextNote, - Kind::Repost, - Kind::ZapReceipt, - Kind::EncryptedDirectMessage, - Kind::SealedDirect, - ]); - - // Setup negentropy for user's activity - let _ = client.reconcile(filter, NegentropyOptions::default()).await; - Ok(true) } Err(err) => Err(err.to_string()),