mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 16:31:18 +00:00
Split Inbox section in Inbox and Activity
And remove the "Show Direct Replies Only in your Inbox" option from the settings
This commit is contained in:
parent
10b56ff28b
commit
a7b755ff21
63
src/feed.rs
63
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<Vec<Id>>,
|
||||
main_feed: RwLock<Vec<Id>>,
|
||||
replies_feed: RwLock<Vec<Id>>,
|
||||
activity_feed: RwLock<Vec<Id>>,
|
||||
|
||||
// We only recompute the feed at specified intervals
|
||||
interval_ms: RwLock<u32>,
|
||||
@ -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<Id> {
|
||||
self.maybe_recompute();
|
||||
self.activity_feed.read().clone()
|
||||
}
|
||||
|
||||
pub fn get_person_feed(&self, person: PublicKeyHex) -> Vec<Id> {
|
||||
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<Id> = self.my_event_ids.read().iter().copied().collect();
|
||||
let mut revents: Vec<Event> = 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<Id> = self.my_event_ids.read().iter().copied().collect();
|
||||
let mut aevents: Vec<Event> = 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 {
|
||||
|
@ -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,
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user