From 0fecfc837c12a44a43d0a95e251e422d3b65d5a3 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Fri, 23 Dec 2022 09:42:22 +0100 Subject: [PATCH 1/2] feed: enable ignoring duplicate textnotes option This option drops textNotes with exactly the same content after, it was already shown 5 times. --- src/cards.css | 2 +- src/form.css | 10 ++++++++++ src/index.html | 9 +++++++++ src/main.css | 1 + src/main.js | 22 ++++++++++++++++++++++ src/tabs.css | 2 +- 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/cards.css b/src/cards.css index 2a407b4..207fabc 100644 --- a/src/cards.css +++ b/src/cards.css @@ -10,7 +10,7 @@ } @media (orientation: portrait) { .mbox { - padding: 0 calc(.5 * var(--gap)); + padding: 0 var(--gap-half); } } .mbox:last-child { diff --git a/src/form.css b/src/form.css index 5a0151b..ad97eba 100644 --- a/src/form.css +++ b/src/form.css @@ -187,6 +187,16 @@ button:disabled { flex-grow: 0; } + +input[type="checkbox"] { + margin: 0; +} +label.checkbox { + align-items: baseline; + display: flex; + gap: var(--gap-half); +} + button#publish { align-self: end; order: 2; diff --git a/src/index.html b/src/index.html index 23f0f3e..74a180b 100644 --- a/src/index.html +++ b/src/index.html @@ -83,6 +83,15 @@ +
+ +
diff --git a/src/main.css b/src/main.css index a60d2f1..e30552c 100644 --- a/src/main.css +++ b/src/main.css @@ -14,6 +14,7 @@ --focus-outline: var(--focus-outline-width) var(--focus-outline-style) var(--focus-outline-color); --font-small: 1.2rem; --gap: 2.4rem; + --gap-half: 1.2rem; } ::selection { diff --git a/src/main.js b/src/main.js index e223e7c..832976d 100644 --- a/src/main.js +++ b/src/main.js @@ -259,7 +259,29 @@ const textNoteList = []; // could use indexDB const eventRelayMap = {}; // eventId: [relay1, relay2] const hasEventTag = tag => tag[0] === 'e'; +const dropDuplicateToggle = document.querySelector('#duplicates'); +let dropDuplicate = JSON.parse(localStorage.getItem('filter_duplicates')) ?? true; +dropDuplicateToggle.addEventListener('click', (e) => { + localStorage.setItem('filter_duplicates', e.target.checked); + dropDuplicate = e.target.checked; +}); +dropDuplicateToggle.checked = dropDuplicate; + +function isValidNote(evt) { + if (dropDuplicate) { + const similarEvents = textNoteList.filter(({content}) => content === evt.content); + if (similarEvents?.length >= 5) { + console.info(`DROP event ${evt.id} already got ${similarEvents.length}`, similarEvents); + return false; + } + } + return true; +} + function handleTextNote(evt, relay) { + if (!isValidNote(evt)) { + return; + } if (eventRelayMap[evt.id]) { eventRelayMap[evt.id] = [relay, ...(eventRelayMap[evt.id])]; } else { diff --git a/src/tabs.css b/src/tabs.css index 57a0c07..cac828e 100644 --- a/src/tabs.css +++ b/src/tabs.css @@ -45,7 +45,7 @@ input[type="radio"]:checked + label { .tab-content { max-width: 96ch; min-height: 200px; - padding: calc(.5 * var(--gap)) 0 100px 0; + padding: var(--gap-half) 0 100px 0; } .tabbed { align-items: start; -- 2.41.0 From 3b99dfac79092b83c2707993319f2b90468fbd76 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Fri, 23 Dec 2022 11:12:52 +0100 Subject: [PATCH 2/2] only take events within the last hour into account --- src/index.html | 2 +- src/main.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/index.html b/src/index.html index 74a180b..3c83865 100644 --- a/src/index.html +++ b/src/index.html @@ -88,7 +88,7 @@ drop duplicate events
- ignore events that have already been rendered 5 times + ignore events that have already been rendered 5 times within the last hour
diff --git a/src/main.js b/src/main.js index 832976d..879d506 100644 --- a/src/main.js +++ b/src/main.js @@ -257,6 +257,8 @@ document.body.addEventListener('click', (e) => { const textNoteList = []; // could use indexDB const eventRelayMap = {}; // eventId: [relay1, relay2] +const replyList = []; +const reactionMap = {}; const hasEventTag = tag => tag[0] === 'e'; const dropDuplicateToggle = document.querySelector('#duplicates'); @@ -269,9 +271,12 @@ dropDuplicateToggle.checked = dropDuplicate; function isValidNote(evt) { 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) { - 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; } } @@ -295,9 +300,6 @@ function handleTextNote(evt, relay) { } } -const replyList = []; -const reactionMap = {}; - const getReactionList = (id) => { return reactionMap[id]?.map(({content}) => content) || []; }; @@ -379,6 +381,7 @@ setInterval(() => { }, 10000); const getNoxyUrl = (type, url, id, relay) => { + return false; if (!isHttpUrl(url)) { return false; } @@ -393,6 +396,9 @@ const fetchQue = []; let fetchPending; const fetchNext = (href, id, relay) => { const noxy = getNoxyUrl('meta', href, id, relay); + if (!noxy) { + return; + } const previewId = noxy.searchParams.toString(); if (fetchPending) { fetchQue.push({href, id, relay}); -- 2.41.0