only take events within the last hour into account
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/pr/woodpecker Pipeline was successful Details

reduce-duplicates
OFF0 2 years ago
parent 0fecfc837c
commit 3b99dfac79
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -88,7 +88,7 @@
<input type="checkbox" name="dropDuplicate" id="duplicates"> <input type="checkbox" name="dropDuplicate" id="duplicates">
<span> <span>
drop duplicate events<br> drop duplicate events<br>
<small>ignore events that have already been rendered 5&nbsp;times</small> <small>ignore events that have already been rendered 5&nbsp;times within the last hour</small>
</span> </span>
</label> </label>
</form> </form>

@ -257,6 +257,8 @@ document.body.addEventListener('click', (e) => {
const textNoteList = []; // could use indexDB const textNoteList = []; // could use indexDB
const eventRelayMap = {}; // eventId: [relay1, relay2] const eventRelayMap = {}; // eventId: [relay1, relay2]
const replyList = [];
const reactionMap = {};
const hasEventTag = tag => tag[0] === 'e'; const hasEventTag = tag => tag[0] === 'e';
const dropDuplicateToggle = document.querySelector('#duplicates'); const dropDuplicateToggle = document.querySelector('#duplicates');
@ -269,9 +271,12 @@ dropDuplicateToggle.checked = dropDuplicate;
function isValidNote(evt) { function isValidNote(evt) {
if (dropDuplicate) { if (dropDuplicate) {
const similarEvents = textNoteList.filter(({content}) => content === evt.content); const similarEvents = [
...textNoteList.filter(({content}) => content === evt.content),
...replyList.filter(({content}) => content === evt.content),
].filter(({created_at}) => ((created_at + 3600) > evt.created_at));
if (similarEvents?.length >= 5) { if (similarEvents?.length >= 5) {
console.info(`DROP event ${evt.id} already got ${similarEvents.length}`, similarEvents); console.info(`DROP event with content: "${evt.content.trim()}" already got ${similarEvents.length} similar events withing the last hour`, similarEvents, `\n dropped event id: ${evt.id}`);
return false; return false;
} }
} }
@ -295,9 +300,6 @@ function handleTextNote(evt, relay) {
} }
} }
const replyList = [];
const reactionMap = {};
const getReactionList = (id) => { const getReactionList = (id) => {
return reactionMap[id]?.map(({content}) => content) || []; return reactionMap[id]?.map(({content}) => content) || [];
}; };
@ -379,6 +381,7 @@ setInterval(() => {
}, 10000); }, 10000);
const getNoxyUrl = (type, url, id, relay) => { const getNoxyUrl = (type, url, id, relay) => {
return false;
if (!isHttpUrl(url)) { if (!isHttpUrl(url)) {
return false; return false;
} }
@ -393,6 +396,9 @@ const fetchQue = [];
let fetchPending; let fetchPending;
const fetchNext = (href, id, relay) => { const fetchNext = (href, id, relay) => {
const noxy = getNoxyUrl('meta', href, id, relay); const noxy = getNoxyUrl('meta', href, id, relay);
if (!noxy) {
return;
}
const previewId = noxy.searchParams.toString(); const previewId = noxy.searchParams.toString();
if (fetchPending) { if (fetchPending) {
fetchQue.push({href, id, relay}); fetchQue.push({href, id, relay});

Loading…
Cancel
Save