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)
};
let enable_reactions = GLOBALS.settings.read().await.reactions;
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
filters.push(Filter {
authors: vec![pubkey.into()],
kinds: vec![
EventKind::TextNote,
EventKind::Repost,
EventKind::Reaction,
EventKind::EventDeletion,
],
kinds,
since: Some(feed_since),
..Default::default()
});
// Any mentions of me
// (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 {
p: vec![pubkey.into()],
kinds: vec![EventKind::TextNote, EventKind::Repost, EventKind::Reaction],
kinds: vec![EventKind::TextNote, EventKind::Repost],
since: Some(special_since),
..Default::default()
});
@ -359,15 +369,18 @@ impl Minion {
}
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
filters.push(Filter {
authors: followed_pubkeys.clone(),
kinds: vec![
EventKind::TextNote,
EventKind::Repost,
EventKind::Reaction,
EventKind::EventDeletion,
],
kinds,
since: Some(feed_since),
..Default::default()
});
@ -473,6 +486,8 @@ impl Minion {
let mut filters: Vec<Filter> = Vec::new();
let enable_reactions = GLOBALS.settings.read().await.reactions;
if !vec_ids.is_empty() {
// Get ancestors we know of so far
filters.push(Filter {
@ -481,22 +496,29 @@ impl Minion {
});
// Get reactions to ancestors, but not replies
let mut kinds = vec![EventKind::EventDeletion];
if enable_reactions {
kinds.push(EventKind::Reaction);
}
filters.push(Filter {
e: vec_ids,
kinds: vec![EventKind::Reaction, EventKind::EventDeletion],
kinds,
..Default::default()
});
}
// 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 {
e: vec![main],
kinds: vec![
EventKind::TextNote,
EventKind::Repost,
EventKind::Reaction,
EventKind::EventDeletion,
],
kinds,
..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_SET_CLIENT_TAG: bool = false;
pub const DEFAULT_OVERRIDE_DPI: Option<u32> = None;
pub const DEFAULT_REACTIONS: bool = true;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Settings {
@ -34,6 +35,7 @@ pub struct Settings {
pub light_mode: bool,
pub set_client_tag: bool,
pub override_dpi: Option<u32>,
pub reactions: bool,
}
impl Default for Settings {
@ -54,6 +56,7 @@ impl Default for Settings {
light_mode: DEFAULT_LIGHT_MODE,
set_client_tag: DEFAULT_SET_CLIENT_TAG,
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', ?),\
('offline', ?),\
('light_mode', ?),\
('set_client_tag', ?)",
('set_client_tag', ?),\
('reactions', ?)",
)?;
stmt.execute((
self.feed_chunk,
@ -167,6 +172,7 @@ impl Settings {
bool_to_numstr(self.offline),
bool_to_numstr(self.light_mode),
bool_to_numstr(self.set_client_tag),
bool_to_numstr(self.reactions),
))?;
// Save override dpi

View File

@ -551,23 +551,27 @@ fn render_post_actual(
ui.add_space(24.0);
if ui
.add(Label::new(RichText::new("").size(20.0)).sense(Sense::click()))
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::Like(event.id, event.pubkey));
}
for (ch, count) in reactions.iter() {
if *ch == '+' {
ui.label(format!("{}", count));
if app.settings.reactions {
if ui
.add(
Label::new(RichText::new("").size(20.0)).sense(Sense::click()),
)
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::Like(event.id, event.pubkey));
}
}
ui.add_space(12.0);
for (ch, count) in reactions.iter() {
if *ch != '+' {
ui.label(RichText::new(format!("{} {}", ch, count)).strong());
for (ch, count) in reactions.iter() {
if *ch == '+' {
ui.label(format!("{}", count));
}
}
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)",
);
ui.checkbox(
&mut app.settings.reactions,
"Enable reactions (show and react)",
);
ui.add_space(12.0);
ui.separator();
ui.add_space(12.0);