feat: improve dedup events
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
import type {
|
import {
|
||||||
Account,
|
Kind,
|
||||||
Contact,
|
type Account,
|
||||||
Event,
|
type Contact,
|
||||||
EventWithReplies,
|
type Event,
|
||||||
Interests,
|
type EventWithReplies,
|
||||||
Keys,
|
type Interests,
|
||||||
LumeColumn,
|
type Keys,
|
||||||
Metadata,
|
type LumeColumn,
|
||||||
Settings,
|
type Metadata,
|
||||||
|
type Settings,
|
||||||
} from "@lume/types";
|
} from "@lume/types";
|
||||||
import { generateContentTags } from "@lume/utils";
|
import { generateContentTags } from "@lume/utils";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
@@ -169,8 +170,6 @@ export class Ark {
|
|||||||
if (asOf && asOf > 0) until = asOf.toString();
|
if (asOf && asOf > 0) until = asOf.toString();
|
||||||
|
|
||||||
const seenIds = new Set<string>();
|
const seenIds = new Set<string>();
|
||||||
const dedupQueue = new Set<string>();
|
|
||||||
|
|
||||||
const nostrEvents: Event[] = await invoke("get_events", {
|
const nostrEvents: Event[] = await invoke("get_events", {
|
||||||
limit,
|
limit,
|
||||||
until,
|
until,
|
||||||
@@ -178,24 +177,24 @@ export class Ark {
|
|||||||
global: isGlobal,
|
global: isGlobal,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// remove duplicate event
|
||||||
for (const event of nostrEvents) {
|
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
|
const eventIds = event.tags
|
||||||
.filter((el) => el[3] === "root" || el[3] === "reply")
|
.filter((el) => el[0] === "e")
|
||||||
?.map((item) => item[1]);
|
?.map((item) => item[1]);
|
||||||
|
|
||||||
if (eventIds.length) {
|
if (eventIds && eventIds.length) {
|
||||||
for (const id of eventIds) {
|
eventIds.forEach((id) => seenIds.add(id));
|
||||||
if (seenIds.has(id)) {
|
|
||||||
dedupQueue.add(event.id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
seenIds.add(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const events = nostrEvents
|
const events = nostrEvents
|
||||||
.filter((event) => !dedupQueue.has(event.id))
|
.filter((event) => !seenIds.has(event.id))
|
||||||
.sort((a, b) => b.created_at - a.created_at);
|
.sort((a, b) => b.created_at - a.created_at);
|
||||||
|
|
||||||
if (this.settings?.nsfw) {
|
if (this.settings?.nsfw) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { MentionUser } from "./mentions/user";
|
|||||||
import { Images } from "./preview/images";
|
import { Images } from "./preview/images";
|
||||||
import { Videos } from "./preview/videos";
|
import { Videos } from "./preview/videos";
|
||||||
import { useNoteContext } from "./provider";
|
import { useNoteContext } from "./provider";
|
||||||
import { useRouteContext } from "@tanstack/react-router";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
export function NoteContent({
|
export function NoteContent({
|
||||||
quote = true,
|
quote = true,
|
||||||
@@ -20,7 +20,6 @@ export function NoteContent({
|
|||||||
clean?: boolean;
|
clean?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
}) {
|
}) {
|
||||||
const { ark } = useRouteContext({ strict: false });
|
|
||||||
const event = useNoteContext();
|
const event = useNoteContext();
|
||||||
const data = useMemo(() => {
|
const data = useMemo(() => {
|
||||||
const { content, images, videos } = parser(event.content);
|
const { content, images, videos } = parser(event.content);
|
||||||
@@ -90,11 +89,9 @@ export function NoteContent({
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
richContent = reactStringReplace(
|
richContent = reactStringReplace(richContent, /(\r\n|\r|\n)+/g, () => (
|
||||||
richContent,
|
<div key={nanoid()} className="h-3" />
|
||||||
/(\r\n|\r|\n)+/g,
|
));
|
||||||
(_, index) => <div key={`${event.id}_div_${index}`} className="h-3" />,
|
|
||||||
);
|
|
||||||
|
|
||||||
return { content: richContent, images, videos };
|
return { content: richContent, images, videos };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -172,22 +172,6 @@ pub async fn load_selected_account(npub: &str, state: State<'_, Nostr>) -> Resul
|
|||||||
client.set_signer(Some(signer)).await;
|
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)
|
Ok(true)
|
||||||
}
|
}
|
||||||
Err(err) => Err(err.to_string()),
|
Err(err) => Err(err.to_string()),
|
||||||
|
|||||||
Reference in New Issue
Block a user