damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README | LICENSE

commit 804020806ae274a20c9e7035a9dbb04531f4a539
parent fe4d295a4dce68e46d9b0eb7207d02e817f11674
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 15 Nov 2022 09:17:09 -0800

web: render notification timeline

- hide ourselves from notification timeline
- add spam guard (fof + pow like on explore)

Diffstat:
Mweb/js/damus.js | 48+++++++++++++++++++++++++++++++++++++++++++-----
Mweb/js/ui/render.js | 2+-
2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/web/js/damus.js b/web/js/damus.js @@ -332,18 +332,32 @@ function should_add_to_timeline(ev) return ev.kind === 1 || ev.kind === 42 || ev.kind === 6 } -function should_add_to_explore_timeline(contacts, view, ev) +function should_add_to_notification_timeline(our_pk, contacts, ev) { if (!should_add_to_timeline(ev)) return false - if (view.seen.has(ev.pubkey)) + if (our_pk === ev.pubkey) return false - if (contacts.friend_of_friends.has(ev.pubkey)) + if (our_pk !== ev.pubkey && contacts.friends.has(ev.pubkey)) return true - return ev.pow >= view.pow + // TODO: add items that don't pass spam filter to "message requests" + // Then we will need a way to whitelist people as an alternative to + // following them + return passes_spam_filter(contacts, ev) +} + +function should_add_to_explore_timeline(contacts, view, ev) +{ + if (!should_add_to_timeline(ev)) + return false + + if (view.seen.has(ev.pubkey)) + return false + + return passes_spam_filter(contacts, ev) } function get_current_view() @@ -389,6 +403,14 @@ function handle_home_event(ids, model, relay, sub_id, ev) { handle_redraw_logic(model, 'explore') break; + case ids.notifications: + if (should_add_to_notification_timeline(model.pubkey, model.contacts, ev)) + is_new = insert_event_sorted(model.views.notifications.events, ev) + + if (is_new) + handle_redraw_logic(model, 'notifications') + break; + case ids.home: if (should_add_to_timeline(ev)) is_new = insert_event_sorted(model.views.home.events, ev) @@ -440,6 +462,8 @@ function send_home_filters(ids, model, relay) { const standard_kinds = [1,42,5,6,7] const home_filter = {kinds: standard_kinds, authors: friends, limit: 500} + + // TODO: include pow+fof spam filtering in notifications query const notifications_filter = {kinds: standard_kinds, "#p": [model.pubkey], limit: 100} let home_filters = [home_filter] @@ -961,7 +985,13 @@ function delete_post_confirm(evid) { delete_post(evid, reason) } -function shouldnt_render_event(view, ev, opts) { +function shouldnt_render_event(our_pk, view, ev, opts) { + if (view.name === 'notifications') { + // never show our stuff on the notifications tab + if (our_pk === ev.pubkey) + return true + } + return !opts.is_boost_event && !opts.is_composing && !view.expanded.has(ev.id) && @@ -1419,3 +1449,11 @@ function time_delta(current, previous) { } } +function passes_spam_filter(contacts, ev) +{ + if (contacts.friend_of_friends.has(ev.pubkey)) + return true + + return ev.pow >= view.pow +} + diff --git a/web/js/ui/render.js b/web/js/ui/render.js @@ -157,7 +157,7 @@ function render_deleted_comment_body(ev, deleted) { function render_event(damus, view, ev, opts={}) { if (ev.kind === 6) return render_boost(damus, view, ev, opts) - if (shouldnt_render_event(view, ev, opts)) + if (shouldnt_render_event(damus.pubkey, view, ev, opts)) return "" view.rendered.add(ev.id)