Make reactions optional

This commit is contained in:
Mike Dilger 2023-01-17 07:45:09 +13:00
parent 8e6028c36a
commit dd4446f6a8
4 changed files with 74 additions and 37 deletions

View File

@ -323,25 +323,35 @@ impl Minion {
(feed_since, special_since) (feed_since, special_since)
}; };
let enable_reactions = GLOBALS.settings.read().await.reactions;
if let Some(pubkey) = GLOBALS.signer.read().await.public_key() { if let Some(pubkey) = GLOBALS.signer.read().await.public_key() {
let mut kinds = vec![
EventKind::TextNote,
EventKind::Repost,
EventKind::EventDeletion,
];
if enable_reactions {
kinds.push(EventKind::Reaction);
}
// feed related by me // feed related by me
filters.push(Filter { filters.push(Filter {
authors: vec![pubkey.into()], authors: vec![pubkey.into()],
kinds: vec![ kinds,
EventKind::TextNote,
EventKind::Repost,
EventKind::Reaction,
EventKind::EventDeletion,
],
since: Some(feed_since), since: Some(feed_since),
..Default::default() ..Default::default()
}); });
// Any mentions of me // Any mentions of me
// (but not in peoples contact lists, for example) // (but not in peoples contact lists, for example)
let mut kinds = vec![EventKind::TextNote, EventKind::Repost];
if enable_reactions {
kinds.push(EventKind::Reaction);
}
filters.push(Filter { filters.push(Filter {
p: vec![pubkey.into()], p: vec![pubkey.into()],
kinds: vec![EventKind::TextNote, EventKind::Repost, EventKind::Reaction], kinds: vec![EventKind::TextNote, EventKind::Repost],
since: Some(special_since), since: Some(special_since),
..Default::default() ..Default::default()
}); });
@ -359,15 +369,18 @@ impl Minion {
} }
if !followed_pubkeys.is_empty() { if !followed_pubkeys.is_empty() {
let mut kinds = vec![
EventKind::TextNote,
EventKind::Repost,
EventKind::EventDeletion,
];
if enable_reactions {
kinds.push(EventKind::Reaction);
}
// feed related by people followed // feed related by people followed
filters.push(Filter { filters.push(Filter {
authors: followed_pubkeys.clone(), authors: followed_pubkeys.clone(),
kinds: vec![ kinds,
EventKind::TextNote,
EventKind::Repost,
EventKind::Reaction,
EventKind::EventDeletion,
],
since: Some(feed_since), since: Some(feed_since),
..Default::default() ..Default::default()
}); });
@ -473,6 +486,8 @@ impl Minion {
let mut filters: Vec<Filter> = Vec::new(); let mut filters: Vec<Filter> = Vec::new();
let enable_reactions = GLOBALS.settings.read().await.reactions;
if !vec_ids.is_empty() { if !vec_ids.is_empty() {
// Get ancestors we know of so far // Get ancestors we know of so far
filters.push(Filter { filters.push(Filter {
@ -481,22 +496,29 @@ impl Minion {
}); });
// Get reactions to ancestors, but not replies // Get reactions to ancestors, but not replies
let mut kinds = vec![EventKind::EventDeletion];
if enable_reactions {
kinds.push(EventKind::Reaction);
}
filters.push(Filter { filters.push(Filter {
e: vec_ids, e: vec_ids,
kinds: vec![EventKind::Reaction, EventKind::EventDeletion], kinds,
..Default::default() ..Default::default()
}); });
} }
// Get replies to main event // Get replies to main event
let mut kinds = vec![
EventKind::TextNote,
EventKind::Repost,
EventKind::EventDeletion,
];
if enable_reactions {
kinds.push(EventKind::Reaction);
}
filters.push(Filter { filters.push(Filter {
e: vec![main], e: vec![main],
kinds: vec![ kinds,
EventKind::TextNote,
EventKind::Repost,
EventKind::Reaction,
EventKind::EventDeletion,
],
..Default::default() ..Default::default()
}); });

View File

@ -16,6 +16,7 @@ pub const DEFAULT_OFFLINE: bool = false;
pub const DEFAULT_LIGHT_MODE: bool = true; // true = light false = dark pub const DEFAULT_LIGHT_MODE: bool = true; // true = light false = dark
pub const DEFAULT_SET_CLIENT_TAG: bool = false; pub const DEFAULT_SET_CLIENT_TAG: bool = false;
pub const DEFAULT_OVERRIDE_DPI: Option<u32> = None; pub const DEFAULT_OVERRIDE_DPI: Option<u32> = None;
pub const DEFAULT_REACTIONS: bool = true;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Settings { pub struct Settings {
@ -34,6 +35,7 @@ pub struct Settings {
pub light_mode: bool, pub light_mode: bool,
pub set_client_tag: bool, pub set_client_tag: bool,
pub override_dpi: Option<u32>, pub override_dpi: Option<u32>,
pub reactions: bool,
} }
impl Default for Settings { impl Default for Settings {
@ -54,6 +56,7 @@ impl Default for Settings {
light_mode: DEFAULT_LIGHT_MODE, light_mode: DEFAULT_LIGHT_MODE,
set_client_tag: DEFAULT_SET_CLIENT_TAG, set_client_tag: DEFAULT_SET_CLIENT_TAG,
override_dpi: DEFAULT_OVERRIDE_DPI, override_dpi: DEFAULT_OVERRIDE_DPI,
reactions: DEFAULT_REACTIONS,
} }
} }
} }
@ -120,6 +123,7 @@ impl Settings {
}; };
} }
} }
"reactions" => settings.reactions = numstr_to_bool(row.1),
_ => {} _ => {}
} }
} }
@ -152,7 +156,8 @@ impl Settings {
('pow', ?),\ ('pow', ?),\
('offline', ?),\ ('offline', ?),\
('light_mode', ?),\ ('light_mode', ?),\
('set_client_tag', ?)", ('set_client_tag', ?),\
('reactions', ?)",
)?; )?;
stmt.execute(( stmt.execute((
self.feed_chunk, self.feed_chunk,
@ -167,6 +172,7 @@ impl Settings {
bool_to_numstr(self.offline), bool_to_numstr(self.offline),
bool_to_numstr(self.light_mode), bool_to_numstr(self.light_mode),
bool_to_numstr(self.set_client_tag), bool_to_numstr(self.set_client_tag),
bool_to_numstr(self.reactions),
))?; ))?;
// Save override dpi // Save override dpi

View File

@ -551,23 +551,27 @@ fn render_post_actual(
ui.add_space(24.0); ui.add_space(24.0);
if ui if app.settings.reactions {
.add(Label::new(RichText::new("").size(20.0)).sense(Sense::click())) if ui
.clicked() .add(
{ Label::new(RichText::new("").size(20.0)).sense(Sense::click()),
let _ = GLOBALS )
.to_overlord .clicked()
.send(ToOverlordMessage::Like(event.id, event.pubkey)); {
} let _ = GLOBALS
for (ch, count) in reactions.iter() { .to_overlord
if *ch == '+' { .send(ToOverlordMessage::Like(event.id, event.pubkey));
ui.label(format!("{}", count));
} }
} for (ch, count) in reactions.iter() {
ui.add_space(12.0); if *ch == '+' {
for (ch, count) in reactions.iter() { ui.label(format!("{}", count));
if *ch != '+' { }
ui.label(RichText::new(format!("{} {}", ch, count)).strong()); }
ui.add_space(12.0);
for (ch, count) in reactions.iter() {
if *ch != '+' {
ui.label(RichText::new(format!("{} {}", ch, count)).strong());
}
} }
} }
}); });

View File

@ -76,6 +76,11 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
"In thread view, view all replies to a post recursively on down (not yet implemented)", "In thread view, view all replies to a post recursively on down (not yet implemented)",
); );
ui.checkbox(
&mut app.settings.reactions,
"Enable reactions (show and react)",
);
ui.add_space(12.0); ui.add_space(12.0);
ui.separator(); ui.separator();
ui.add_space(12.0); ui.add_space(12.0);