rm duplicate events by the same pubkey

This commit is contained in:
smolgrrr 2024-08-31 22:41:07 +10:00
parent 49d5c3d400
commit 2cf24b1f72
2 changed files with 19 additions and 1 deletions

View File

@ -122,6 +122,12 @@ const NewNoteCard = ({
const { handleSubmit: originalHandleSubmit, doingWorkProp, hashrate, bestPow, signedPoWEvent } = useSubmitForm(unsigned, difficulty); const { handleSubmit: originalHandleSubmit, doingWorkProp, hashrate, bestPow, signedPoWEvent } = useSubmitForm(unsigned, difficulty);
const handleSubmit = async (event: React.FormEvent) => { const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault(); // Prevent default form submission
if (comment.trim() === "") {
return; // Don't submit if comment is empty or just whitespace
}
// Check if tagType is 'Quote' and update comment // Check if tagType is 'Quote' and update comment
if (tagType === 'Quote' && refEvent) { if (tagType === 'Quote' && refEvent) {
setComment(prevComment => prevComment + '\nnostr:' + nip19.noteEncode(refEvent.id)); setComment(prevComment => prevComment + '\nnostr:' + nip19.noteEncode(refEvent.id));

View File

@ -30,10 +30,22 @@ const useProcessedEvents = (id?: string, filterDifficulty: number = 0) => {
}); });
}); });
// Create a Set to keep track of seen pubkeys
const seenPubkeys = new Set<string>();
return noteEvents return noteEvents
.filter(event => { .filter(event => {
const pow = verifyPow(event); const pow = verifyPow(event);
return (event.kind === 0 || pow >= filterDifficulty) && !(event.kind === 1 && event.tags.some(tag => tag[0] === 'e')); // Check if the pubkey has been seen before
if (seenPubkeys.has(event.pubkey)) {
return false;
}
// Add the pubkey to the set if it passes the filter
if ((event.kind === 0 || pow >= filterDifficulty) && !(event.kind === 1 && event.tags.some(tag => tag[0] === 'e'))) {
seenPubkeys.add(event.pubkey);
return true;
}
return false;
}) })
.map(event => { .map(event => {
const pow = verifyPow(event); // Calculate once and reuse const pow = verifyPow(event); // Calculate once and reuse