Merge remote-tracking branch 'dtonon/features/split_following'

This commit is contained in:
Mike Dilger 2023-03-03 10:16:45 +13:00
commit ed8b54e664
6 changed files with 62 additions and 31 deletions

View File

@ -10,6 +10,7 @@ use tokio::task;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FeedKind {
General,
Main,
Replies,
Thread { id: Id, referenced_by: Id },
Person(PublicKeyHex),
@ -19,6 +20,7 @@ pub struct Feed {
current_feed_kind: RwLock<FeedKind>,
general_feed: RwLock<Vec<Id>>,
main_feed: RwLock<Vec<Id>>,
replies_feed: RwLock<Vec<Id>>,
// We only recompute the feed at specified intervals
@ -35,8 +37,9 @@ pub struct Feed {
impl Feed {
pub fn new() -> Feed {
Feed {
current_feed_kind: RwLock::new(FeedKind::General),
current_feed_kind: RwLock::new(FeedKind::Main),
general_feed: RwLock::new(Vec::new()),
main_feed: RwLock::new(Vec::new()),
replies_feed: RwLock::new(Vec::new()),
interval_ms: RwLock::new(1000), // Every second, until we load from settings
last_computed: RwLock::new(Instant::now()),
@ -63,6 +66,23 @@ impl Feed {
});
}
pub fn set_feed_to_main(&self) {
// We are always subscribed to the general feed. Don't resubscribe here
// because it won't have changed, but the relays will shower you with
// all those events again.
*self.current_feed_kind.write() = FeedKind::Main;
*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_replies(&self) {
*self.current_feed_kind.write() = FeedKind::Replies;
*self.thread_parent.write() = None;
@ -115,6 +135,11 @@ impl Feed {
self.general_feed.read().clone()
}
pub fn get_main(&self) -> Vec<Id> {
self.maybe_recompute();
self.main_feed.read().clone()
}
pub fn get_replies(&self) -> Vec<Id> {
self.maybe_recompute();
self.replies_feed.read().clone()
@ -212,25 +237,26 @@ impl Feed {
let now = Unixtime::now().unwrap();
let dismissed = GLOBALS.dismissed.read().await.clone();
// Filter out replies if the user doesn't want them
let replies_in_follows = GLOBALS.settings.read().replies_in_follows;
let mut fevents: Vec<Event> = events
let mut gevents: Vec<Event> = events
.iter()
.filter(|e| !dismissed.contains(&e.id))
.filter(|e| {
if replies_in_follows {
true
} else {
!matches!(e.replies_to(), Some((_id, _)))
}
})
.filter(|e| followed_pubkeys.contains(&e.pubkey.into())) // something we follow
.filter(|e| e.created_at <= now)
.cloned()
.collect();
fevents.sort_by(|a, b| b.created_at.cmp(&a.created_at));
*self.general_feed.write() = fevents.iter().map(|e| e.id).collect();
gevents.sort_by(|a, b| b.created_at.cmp(&a.created_at));
*self.general_feed.write() = gevents.iter().map(|e| e.id).collect();
let mut mevents: Vec<Event> = events
.iter()
.filter(|e| !dismissed.contains(&e.id))
.filter(|e| { !matches!(e.replies_to(), Some((_id, _))) })
.filter(|e| followed_pubkeys.contains(&e.pubkey.into())) // something we follow
.filter(|e| e.created_at <= now)
.cloned()
.collect();
mevents.sort_by(|a, b| b.created_at.cmp(&a.created_at));
*self.main_feed.write() = mevents.iter().map(|e| e.id).collect();
// Filter differently for the replies feed
let direct_only = GLOBALS.settings.read().direct_replies_only;

View File

@ -26,7 +26,6 @@ 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_REPLIES_IN_FOLLOWS: bool = true;
pub const DEFAULT_DIRECT_MESSAGES: bool = true;
pub const DEFAULT_AUTOMATICALLY_FETCH_METADATA: bool = true;
@ -51,7 +50,6 @@ pub struct Settings {
pub load_avatars: bool,
pub check_nip05: bool,
pub direct_replies_only: bool,
pub replies_in_follows: bool,
pub direct_messages: bool,
pub automatically_fetch_metadata: bool,
pub delegatee_tag: String,
@ -79,7 +77,6 @@ impl Default for Settings {
load_avatars: DEFAULT_LOAD_AVATARS,
check_nip05: DEFAULT_CHECK_NIP05,
direct_replies_only: DEFAULT_DIRECT_REPLIES_ONLY,
replies_in_follows: DEFAULT_REPLIES_IN_FOLLOWS,
direct_messages: DEFAULT_DIRECT_MESSAGES,
automatically_fetch_metadata: DEFAULT_AUTOMATICALLY_FETCH_METADATA,
delegatee_tag: String::new(),
@ -161,7 +158,6 @@ impl Settings {
"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),
"replies_in_follows" => settings.replies_in_follows = 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)
@ -206,7 +202,6 @@ impl Settings {
('load_avatars', ?),\
('check_nip05', ?),\
('direct_replies_only', ?),\
('replies_in_follows', ?),\
('direct_messages', ?),\
('automatically_fetch_metadata', ?),\
('delegatee_tag', ?)",
@ -230,7 +225,6 @@ impl Settings {
bool_to_numstr(self.load_avatars),
bool_to_numstr(self.check_nip05),
bool_to_numstr(self.direct_replies_only),
bool_to_numstr(self.replies_in_follows),
bool_to_numstr(self.direct_messages),
bool_to_numstr(self.automatically_fetch_metadata),
self.delegatee_tag,

View File

@ -28,10 +28,20 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
// Feed Page Selection
ui.horizontal(|ui| {
if ui
.add(SelectableLabel::new(
app.page == Page::Feed(FeedKind::Main),
"Main feed",
))
.clicked()
{
app.set_page(Page::Feed(FeedKind::Main));
}
ui.separator();
if ui
.add(SelectableLabel::new(
app.page == Page::Feed(FeedKind::General),
"Following",
"Conversations",
))
.clicked()
{
@ -80,6 +90,10 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
ui.add_space(10.0);
match feed_kind {
FeedKind::Main => {
let feed = GLOBALS.feed.get_main();
render_a_feed(app, ctx, frame, ui, feed, false, "main");
}
FeedKind::General => {
let feed = GLOBALS.feed.get_general();
render_a_feed(app, ctx, frame, ui, feed, false, "general");

View File

@ -133,7 +133,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.horizontal_wrapped(|ui| {
ui.label("On the");
if ui.link("Feed > Following").clicked() {
app.set_page(Page::Feed(FeedKind::General));
app.set_page(Page::Feed(FeedKind::Main));
}
ui.label("page, enjoy the feed.");
});
@ -229,7 +229,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.horizontal_wrapped(|ui| {
ui.label("On the");
if ui.link("Feed > Following").clicked() {
app.set_page(Page::Feed(FeedKind::General));
app.set_page(Page::Feed(FeedKind::Main));
}
ui.label("page, enjoy the feed.");
});

View File

@ -224,7 +224,7 @@ impl GossipUi {
let start_page = if GLOBALS.first_run.load(Ordering::Relaxed) {
Page::HelpHelp
} else {
Page::Feed(FeedKind::General)
Page::Feed(FeedKind::Main)
};
// Apply current theme
@ -305,6 +305,9 @@ impl GossipUi {
Page::Feed(FeedKind::General) => {
GLOBALS.feed.set_feed_to_general();
}
Page::Feed(FeedKind::Main) => {
GLOBALS.feed.set_feed_to_main();
}
Page::Feed(FeedKind::Replies) => {
GLOBALS.feed.set_feed_to_replies();
}
@ -388,7 +391,7 @@ impl eframe::App for GossipUi {
))
.clicked()
{
self.set_page(Page::Feed(FeedKind::General));
self.set_page(Page::Feed(FeedKind::Main));
}
ui.separator();
if ui

View File

@ -109,12 +109,6 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.add_space(12.0);
ui.checkbox(
&mut app.settings.replies_in_follows,
"Include Replies in Following Feed",
)
.on_hover_text("Takes effect when the feed refreshes.");
ui.add_space(12.0);