Skip to content

Commit

Permalink
FeedKind::Followed(replies) changed to more general FeedKind::List(li…
Browse files Browse the repository at this point in the history
…st, replies)
  • Loading branch information
mikedilger committed Oct 15, 2023
1 parent 5d6a45a commit 243bb2f
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 50 deletions.
15 changes: 10 additions & 5 deletions gossip-bin/src/ui/feed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,20 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
let feed_kind = GLOBALS.feed.get_feed_kind();

match feed_kind {
FeedKind::Followed(with_replies) => {
FeedKind::List(list, with_replies) => {
let feed = GLOBALS.feed.get_followed();
let id = if with_replies { "main" } else { "general" };
let id = format!(
"{} {}",
Into::<u8>::into(list),
if with_replies { "main" } else { "general" }
);
ui.add_space(10.0);
ui.allocate_ui_with_layout(
Vec2::new(ui.available_width(), ui.spacing().interact_size.y),
egui::Layout::left_to_right(egui::Align::Center),
|ui| {
add_left_space(ui);
ui.heading("Main feed");
ui.heading(list.name());
recompute_btn(app, ui);

ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
Expand All @@ -75,7 +79,8 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
)
.clicked()
{
app.set_page(Page::Feed(FeedKind::Followed(
app.set_page(Page::Feed(FeedKind::List(
list,
app.mainfeed_include_nonroot,
)));
ctx.data_mut(|d| {
Expand All @@ -90,7 +95,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
},
);
ui.add_space(6.0);
render_a_feed(app, ctx, frame, ui, feed, false, id);
render_a_feed(app, ctx, frame, ui, feed, false, &id);
}
FeedKind::Inbox(indirect) => {
if app.settings.public_key.is_none() {
Expand Down
6 changes: 3 additions & 3 deletions gossip-bin/src/ui/help/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{GossipUi, Page};
use eframe::egui;
use egui::{Context, Ui};
use gossip_lib::FeedKind;
use gossip_lib::{FeedKind, PersonList};

mod about;
mod stats;
Expand Down Expand Up @@ -103,7 +103,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::Followed(app.mainfeed_include_nonroot)));
app.set_page(Page::Feed(FeedKind::List(PersonList::Followed, app.mainfeed_include_nonroot)));
}
ui.label("page, enjoy the feed.");
});
Expand Down Expand Up @@ -199,7 +199,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::Followed(app.mainfeed_include_nonroot)));
app.set_page(Page::Feed(FeedKind::List(PersonList::Followed, app.mainfeed_include_nonroot)));
}
ui.label("page, enjoy the feed.");
});
Expand Down
10 changes: 5 additions & 5 deletions gossip-bin/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl GossipUi {
None => (false, dpi),
};

let mut start_page = Page::Feed(FeedKind::Followed(false));
let mut start_page = Page::Feed(FeedKind::List(PersonList::Followed, false));

// Possibly enter the wizard instead
let mut wizard_state: WizardState = Default::default();
Expand Down Expand Up @@ -683,8 +683,8 @@ impl GossipUi {
fn set_page_inner(&mut self, page: Page) {
// Setting the page often requires some associated actions:
match &page {
Page::Feed(FeedKind::Followed(with_replies)) => {
GLOBALS.feed.set_feed_to_followed(*with_replies);
Page::Feed(FeedKind::List(list, with_replies)) => {
GLOBALS.feed.set_feed_to_main(*list, *with_replies);
}
Page::Feed(FeedKind::Inbox(indirect)) => {
GLOBALS.feed.set_feed_to_inbox(*indirect);
Expand Down Expand Up @@ -763,8 +763,8 @@ impl GossipUi {
ui.separator();
ui.add_space(4.0);

if self.add_selected_label(ui, matches!(self.page, Page::Feed(FeedKind::Followed(_))), "Main Feed").clicked() {
self.set_page(Page::Feed(FeedKind::Followed(self.mainfeed_include_nonroot)));
if self.add_selected_label(ui, matches!(self.page, Page::Feed(FeedKind::List(PersonList::Followed, _))), "Main Feed").clicked() {
self.set_page(Page::Feed(FeedKind::List(PersonList::Followed, self.mainfeed_include_nonroot)));
}
if let Some(pubkey) = GLOBALS.signer.public_key() {
if self.add_selected_label(ui, matches!(&self.page, Page::Feed(FeedKind::Person(key)) if *key == pubkey), "My Notes").clicked() {
Expand Down
6 changes: 2 additions & 4 deletions gossip-bin/src/ui/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ pub(super) fn set_important_button_visuals(ui: &mut Ui, app: &GossipUi) {
let visuals = ui.visuals_mut();
visuals.widgets.inactive.weak_bg_fill = app.theme.accent_color();
visuals.widgets.inactive.fg_stroke.width = 1.0;
visuals.widgets.inactive.fg_stroke.color =
app.theme.get_style().visuals.extreme_bg_color;
visuals.widgets.inactive.fg_stroke.color = app.theme.get_style().visuals.extreme_bg_color;
visuals.widgets.hovered.weak_bg_fill = app.theme.navigation_text_color();
visuals.widgets.hovered.fg_stroke.color = app.theme.accent_color();
visuals.widgets.inactive.fg_stroke.color =
app.theme.get_style().visuals.extreme_bg_color;
visuals.widgets.inactive.fg_stroke.color = app.theme.get_style().visuals.extreme_bg_color;
}

// /// UTF-8 safe truncate (String::truncate() can panic)
Expand Down
21 changes: 11 additions & 10 deletions gossip-bin/src/ui/widgets/relay_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,15 @@ impl RelayEntry {
let is_personal = self.relay.usage_bits != 0;
let id = self.make_id("remove_link");
let text = "Remove from personal list";
let response = draw_link_at(ui, id, pos, text.into(), Align::Min, self.enabled && is_personal, true);
let response = draw_link_at(
ui,
id,
pos,
text.into(),
Align::Min,
self.enabled && is_personal,
true,
);
if response.clicked() {
let _ = GLOBALS.storage.modify_relay(
&self.relay.url,
Expand All @@ -379,15 +387,8 @@ impl RelayEntry {
let id = self.make_id("disconnect_link");
let text = "Force disconnect";
let can_disconnect = self.enabled && self.connected;
let disconnect_response = draw_link_at(
ui,
id,
pos,
text.into(),
Align::Min,
can_disconnect,
true,
);
let disconnect_response =
draw_link_at(ui, id, pos, text.into(), Align::Min, can_disconnect, true);
if can_disconnect && disconnect_response.clicked() {
let _ = GLOBALS
.to_overlord
Expand Down
10 changes: 4 additions & 6 deletions gossip-bin/src/ui/wizard/follow_people.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use crate::ui::{GossipUi, Page};
use eframe::egui;
use egui::{Context, RichText, Ui};
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::FeedKind;
use gossip_lib::Person;
use gossip_lib::GLOBALS;
use gossip_lib::{FeedKind, Person, PersonList, GLOBALS};
use gossip_relay_picker::Direction;
use nostr_types::{Profile, PublicKey};

Expand Down Expand Up @@ -143,7 +141,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::PushFollow);

let _ = GLOBALS.storage.write_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::Followed(false));
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
}

ui.add_space(20.0);
Expand All @@ -153,15 +151,15 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
}
if ui.button(label).clicked() {
let _ = GLOBALS.storage.write_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::Followed(false));
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
}
} else {
ui.add_space(20.0);
let mut label = RichText::new(" > Finish");
label = label.color(app.theme.accent_color());
if ui.button(label).clicked() {
let _ = GLOBALS.storage.write_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::Followed(false));
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
}
}
}
6 changes: 2 additions & 4 deletions gossip-bin/src/ui/wizard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::ui::{GossipUi, Page};
use eframe::egui;
use egui::widgets::{Button, Slider};
use egui::{Align, Context, Layout};
use gossip_lib::FeedKind;
use gossip_lib::Relay;
use gossip_lib::GLOBALS;
use gossip_lib::{FeedKind, PersonList, Relay, GLOBALS};

mod follow_people;
mod import_keys;
Expand Down Expand Up @@ -201,7 +199,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
if wp != WizardPage::FollowPeople {
if ui.button(" X Exit this Wizard").clicked() {
let _ = GLOBALS.storage.write_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::Followed(false));
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
}
}

Expand Down
27 changes: 14 additions & 13 deletions gossip-lib/src/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::comms::{ToMinionMessage, ToMinionPayload, ToMinionPayloadDetail, ToOv
use crate::dm_channel::DmChannel;
use crate::error::Error;
use crate::globals::GLOBALS;
use crate::people::PersonList;
use nostr_types::{Event, EventKind, Id, PublicKey, PublicKeyHex, RelayUrl, Unixtime};
use parking_lot::RwLock;
use std::collections::HashSet;
Expand All @@ -12,8 +13,8 @@ use tokio::task;
/// Kinds of feeds, with configuration parameteers
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FeedKind {
Followed(bool), // with replies
Inbox(bool), // indirect
List(PersonList, bool), // with replies
Inbox(bool), // indirect
Thread {
id: Id,
referenced_by: Id,
Expand All @@ -27,7 +28,7 @@ impl std::fmt::Display for FeedKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FeedKind::DmChat(channel) => write!(f, "{}", channel.name()),
FeedKind::Followed(_) => write!(f, "Following"),
FeedKind::List(pl, _) => write!(f, "{}", pl.name()),
FeedKind::Inbox(_) => write!(f, "Inbox"),
FeedKind::Thread {
id: _,
Expand Down Expand Up @@ -69,7 +70,7 @@ impl Feed {
pub(crate) fn new() -> Feed {
Feed {
recompute_lock: AtomicBool::new(false),
current_feed_kind: RwLock::new(FeedKind::Followed(false)),
current_feed_kind: RwLock::new(FeedKind::List(PersonList::Followed, false)),
followed_feed: RwLock::new(Vec::new()),
inbox_feed: RwLock::new(Vec::new()),
person_feed: RwLock::new(Vec::new()),
Expand Down Expand Up @@ -108,12 +109,12 @@ impl Feed {
}
}

/// Change the feed to the main `followed` feed
pub fn set_feed_to_followed(&self, with_replies: bool) {
/// Change the feed to the main feed
pub fn set_feed_to_main(&self, list: PersonList, with_replies: bool) {
// 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::Followed(with_replies);
*self.current_feed_kind.write() = FeedKind::List(list, with_replies);
*self.thread_parent.write() = None;

// Recompute as they switch
Expand Down Expand Up @@ -301,23 +302,23 @@ impl Feed {

let current_feed_kind = self.current_feed_kind.read().to_owned();
match current_feed_kind {
FeedKind::Followed(with_replies) => {
let mut followed_pubkeys: Vec<PublicKey> = GLOBALS.people.get_followed_pubkeys();
FeedKind::List(list, with_replies) => {
let mut pubkeys: Vec<PublicKey> = GLOBALS.storage.get_people_in_list(list)?;

if let Some(pubkey) = GLOBALS.signer.public_key() {
followed_pubkeys.push(pubkey); // add the user
pubkeys.push(pubkey); // add the user
}

let since = now - Duration::from_secs(GLOBALS.storage.read_setting_feed_chunk());

// FIXME we don't include delegated events. We should look for all events
// delegated to people we follow and include those in the feed too.

let followed_events: Vec<Id> = GLOBALS
let events: Vec<Id> = GLOBALS
.storage
.find_events(
&kinds_without_dms,
&followed_pubkeys, // pubkeys
&pubkeys, // pubkeys
Some(since),
|e| {
e.created_at <= now // no future events
Expand All @@ -336,7 +337,7 @@ impl Feed {
.map(|e| e.id)
.collect();

*self.followed_feed.write() = followed_events;
*self.followed_feed.write() = events;
}
FeedKind::Inbox(indirect) => {
if let Some(my_pubkey) = GLOBALS.signer.public_key() {
Expand Down
13 changes: 13 additions & 0 deletions gossip-lib/src/storage/types/person_list1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub enum PersonList1 {
Muted = 0,
Followed = 1,
Priority = 2,

// custom starts at 10 to leave space
Custom(u8),
}

Expand All @@ -29,3 +31,14 @@ impl From<PersonList1> for u8 {
}
}
}

impl PersonList1 {
pub fn name(&self) -> String {
match *self {
PersonList1::Muted => "Muted".to_string(),
PersonList1::Followed => "Followed".to_string(),
PersonList1::Priority => "Priority".to_string(),
PersonList1::Custom(u) => format!("Custom {}", u - 9),
}
}
}

0 comments on commit 243bb2f

Please sign in to comment.