mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-28 16:00:48 +00:00
feat: improve dedup events
This commit is contained in:
parent
a4aef25adb
commit
28337e5915
@ -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<string>();
|
||||
const dedupQueue = new Set<string>();
|
||||
|
||||
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) {
|
||||
|
@ -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) => <div key={`${event.id}_div_${index}`} className="h-3" />,
|
||||
);
|
||||
richContent = reactStringReplace(richContent, /(\r\n|\r|\n)+/g, () => (
|
||||
<div key={nanoid()} className="h-3" />
|
||||
));
|
||||
|
||||
return { content: richContent, images, videos };
|
||||
} catch (e) {
|
||||
|
@ -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()),
|
||||
|
Loading…
Reference in New Issue
Block a user