From a7b755ff21a6e2a74fe7a8d9457f1ff0ef2aa583 Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Fri, 3 Mar 2023 12:03:07 +0100 Subject: [PATCH] Split Inbox section in Inbox and Activity And remove the "Show Direct Replies Only in your Inbox" option from the settings --- src/feed.rs | 63 +++++++++++++++++++++++++++++++++++++++++----- src/settings.rs | 6 ----- src/ui/feed/mod.rs | 23 +++++++++++++++++ src/ui/mod.rs | 3 +++ src/ui/settings.rs | 6 ----- 5 files changed, 83 insertions(+), 18 deletions(-) diff --git a/src/feed.rs b/src/feed.rs index 2647c43d..5c76acbb 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -12,6 +12,7 @@ pub enum FeedKind { General, Main, Replies, + Activity, Thread { id: Id, referenced_by: Id }, Person(PublicKeyHex), } @@ -22,6 +23,7 @@ pub struct Feed { general_feed: RwLock>, main_feed: RwLock>, replies_feed: RwLock>, + activity_feed: RwLock>, // We only recompute the feed at specified intervals interval_ms: RwLock, @@ -41,6 +43,7 @@ impl Feed { general_feed: RwLock::new(Vec::new()), main_feed: RwLock::new(Vec::new()), replies_feed: RwLock::new(Vec::new()), + activity_feed: RwLock::new(Vec::new()), interval_ms: RwLock::new(1000), // Every second, until we load from settings last_computed: RwLock::new(Instant::now()), my_event_ids: RwLock::new(Vec::new()), @@ -97,6 +100,20 @@ impl Feed { }); } + pub fn set_feed_to_activity(&self) { + *self.current_feed_kind.write() = FeedKind::Activity; + *self.thread_parent.write() = None; + + let _ = GLOBALS.to_minions.send(ToMinionMessage { + target: "all".to_string(), + payload: ToMinionPayload::UnsubscribeThreadFeed, + }); + let _ = GLOBALS.to_minions.send(ToMinionMessage { + target: "all".to_string(), + payload: ToMinionPayload::UnsubscribePersonFeed, + }); + } + pub fn set_feed_to_thread(&self, id: Id, referenced_by: Id) { *self.current_feed_kind.write() = FeedKind::Thread { id, referenced_by }; @@ -145,6 +162,11 @@ impl Feed { self.replies_feed.read().clone() } + pub fn get_activity(&self) -> Vec { + self.maybe_recompute(); + self.activity_feed.read().clone() + } + pub fn get_person_feed(&self, person: PublicKeyHex) -> Vec { let enable_reposts = GLOBALS.settings.read().reposts; @@ -247,6 +269,7 @@ impl Feed { gevents.sort_by(|a, b| b.0.cmp(&a.0)); *self.general_feed.write() = gevents.iter().map(|e| e.1).collect(); + // Filter the main feed with only main posts let mut mevents: Vec<(Unixtime, Id)> = events .iter() .filter(|e| !dismissed.contains(&e.id)) @@ -258,9 +281,7 @@ impl Feed { mevents.sort_by(|a, b| b.0.cmp(&a.0)); *self.main_feed.write() = mevents.iter().map(|e| e.1).collect(); - // Filter differently for the replies feed - let direct_only = GLOBALS.settings.read().direct_replies_only; - + // Filter direct replies for the inbox feed if let Some(my_pubkey) = GLOBALS.signer.public_key() { let my_events: HashSet = self.my_event_ids.read().iter().copied().collect(); let mut revents: Vec = events @@ -280,14 +301,13 @@ impl Feed { } } - if direct_only && e.kind != EventKind::EncryptedDirectMessage { + if e.kind != EventKind::EncryptedDirectMessage { // Include if it directly references me in the content e.referenced_people() .iter() .any(|(p, _, _)| *p == my_pubkey.into()) } else { - // Include if it tags me - e.people().iter().any(|(p, _, _)| *p == my_pubkey.into()) + false } }) .cloned() @@ -297,6 +317,37 @@ impl Feed { *self.replies_feed.write() = revents.iter().map(|e| e.id).collect(); } + + // Filter all post where user is tagged for the activity feed + if let Some(my_pubkey) = GLOBALS.signer.public_key() { + let my_events: HashSet = self.my_event_ids.read().iter().copied().collect(); + let mut aevents: Vec = events + .iter() + .filter(|e| !dismissed.contains(&e.id)) + .filter(|e| { + // Don't include my own posts + if e.pubkey == my_pubkey { + return false; + } + + // Include if it directly replies to one of my events + // FIXME: maybe try replies_to_ancestors to go deeper + if let Some((id, _)) = e.replies_to() { + if my_events.contains(&id) { + return true; + } + } + + // Include if it tags me + e.people().iter().any(|(p, _, _)| *p == my_pubkey.into()) + }) + .cloned() + .collect(); + + aevents.sort_by(|a, b| b.created_at.cmp(&a.created_at)); + *self.activity_feed.write() = aevents.iter().map(|e| e.id).collect(); + } + // Potentially update thread parent to a higher parent let maybe_tp = *self.thread_parent.read(); if let Some(tp) = maybe_tp { diff --git a/src/settings.rs b/src/settings.rs index 805c0a4f..23fc9314 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -25,7 +25,6 @@ pub const DEFAULT_REACTIONS: bool = true; pub const DEFAULT_REPOSTS: bool = true; pub const DEFAULT_LOAD_AVATARS: bool = true; pub const DEFAULT_CHECK_NIP05: bool = true; -pub const DEFAULT_DIRECT_REPLIES_ONLY: bool = true; pub const DEFAULT_DIRECT_MESSAGES: bool = true; pub const DEFAULT_AUTOMATICALLY_FETCH_METADATA: bool = true; @@ -49,7 +48,6 @@ pub struct Settings { pub reposts: bool, pub load_avatars: bool, pub check_nip05: bool, - pub direct_replies_only: bool, pub direct_messages: bool, pub automatically_fetch_metadata: bool, pub delegatee_tag: String, @@ -76,7 +74,6 @@ impl Default for Settings { reposts: DEFAULT_REPOSTS, load_avatars: DEFAULT_LOAD_AVATARS, check_nip05: DEFAULT_CHECK_NIP05, - direct_replies_only: DEFAULT_DIRECT_REPLIES_ONLY, direct_messages: DEFAULT_DIRECT_MESSAGES, automatically_fetch_metadata: DEFAULT_AUTOMATICALLY_FETCH_METADATA, delegatee_tag: String::new(), @@ -157,7 +154,6 @@ impl Settings { "reposts" => settings.reposts = numstr_to_bool(row.1), "load_avatars" => settings.load_avatars = numstr_to_bool(row.1), "check_nip05" => settings.check_nip05 = numstr_to_bool(row.1), - "direct_replies_only" => settings.direct_replies_only = numstr_to_bool(row.1), "direct_messages" => settings.direct_messages = numstr_to_bool(row.1), "automatically_fetch_metadata" => { settings.automatically_fetch_metadata = numstr_to_bool(row.1) @@ -201,7 +197,6 @@ impl Settings { ('reposts', ?),\ ('load_avatars', ?),\ ('check_nip05', ?),\ - ('direct_replies_only', ?),\ ('direct_messages', ?),\ ('automatically_fetch_metadata', ?),\ ('delegatee_tag', ?)", @@ -224,7 +219,6 @@ impl Settings { bool_to_numstr(self.reposts), bool_to_numstr(self.load_avatars), bool_to_numstr(self.check_nip05), - bool_to_numstr(self.direct_replies_only), bool_to_numstr(self.direct_messages), bool_to_numstr(self.automatically_fetch_metadata), self.delegatee_tag, diff --git a/src/ui/feed/mod.rs b/src/ui/feed/mod.rs index c7065c30..1712af85 100644 --- a/src/ui/feed/mod.rs +++ b/src/ui/feed/mod.rs @@ -57,6 +57,16 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram { app.set_page(Page::Feed(FeedKind::Replies)); } + ui.separator(); + if ui + .add(SelectableLabel::new( + app.page == Page::Feed(FeedKind::Activity), + "Activity", + )) + .clicked() + { + app.set_page(Page::Feed(FeedKind::Activity)); + } if matches!(feed_kind.clone(), FeedKind::Thread { .. }) { ui.separator(); if ui @@ -111,6 +121,19 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram let feed = GLOBALS.feed.get_replies(); render_a_feed(app, ctx, frame, ui, feed, false, "replies"); } + FeedKind::Activity => { + if GLOBALS.signer.public_key().is_none() { + ui.horizontal_wrapped(|ui| { + ui.label("You need to "); + if ui.link("setup an identity").clicked() { + app.set_page(Page::YourKeys); + } + ui.label(" to see any replies to that identity."); + }); + } + let feed = GLOBALS.feed.get_activity(); + render_a_feed(app, ctx, frame, ui, feed, false, "activity"); + } FeedKind::Thread { id, .. } => { if let Some(parent) = GLOBALS.feed.get_thread_parent() { render_a_feed(app, ctx, frame, ui, vec![parent], true, &id.as_hex_string()); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index f70d1424..207a92dd 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -311,6 +311,9 @@ impl GossipUi { Page::Feed(FeedKind::Replies) => { GLOBALS.feed.set_feed_to_replies(); } + Page::Feed(FeedKind::Activity) => { + GLOBALS.feed.set_feed_to_activity(); + } Page::Feed(FeedKind::Thread { id, referenced_by }) => { GLOBALS.feed.set_feed_to_thread(*id, *referenced_by); } diff --git a/src/ui/settings.rs b/src/ui/settings.rs index 7c864edc..5bb15af9 100644 --- a/src/ui/settings.rs +++ b/src/ui/settings.rs @@ -99,12 +99,6 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra "Enable reposts (show)", ); - ui.checkbox( - &mut app.settings.direct_replies_only, - "Show Direct Replies Only in your Inbox", - ) - .on_hover_text("Takes effect when the feed refreshes."); - ui.checkbox( &mut app.settings.direct_messages, "Show Direct Messages",