From 892637db0457d53e1b3fbece6d8f6457449f963c Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 23 May 2024 22:35:34 +0200 Subject: [PATCH] feat(web): allow filtering replies --- web/src/components/activity.rs | 50 +++++++++++++++++++--------------- web/src/config.rs | 3 ++ web/src/page/config.rs | 1 + 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/web/src/components/activity.rs b/web/src/components/activity.rs index bccf1f8..d38ced9 100644 --- a/web/src/components/activity.rs +++ b/web/src/components/activity.rs @@ -43,7 +43,9 @@ pub fn Item( match item.object_type() { // special case for placeholder activities Some(apb::ObjectType::Note) | Some(apb::ObjectType::Document(_)) => (move || { - if config.get().filters.orphans { + if !config.get().filters.replies && item.in_reply_to().id().is_some() { + None + } else if config.get().filters.orphans { Some(view! { {sep.clone()} }) } else { None @@ -53,27 +55,31 @@ pub fn Item( Some(apb::ObjectType::Activity(t)) => (move || { if config.get().filters.visible(apb::ObjectType::Activity(t)) { let object_id = item.object().id().unwrap_or_default(); - let object = match t { - apb::ActivityType::Create | apb::ActivityType::Announce => - CACHE.get(&object_id).map(|obj| { - view! { } - }.into_view()), - apb::ActivityType::Follow => - CACHE.get(&object_id).map(|obj| { - view! { -
- - -
- } - }.into_view()), - _ => None, - }; - Some(view! { - - {object} - {sep.clone()} - }) + if !config.get().filters.replies && CACHE.get(&object_id).map(|x| x.in_reply_to().id().is_some()).unwrap_or(false) { + None + } else { + let object = match t { + apb::ActivityType::Create | apb::ActivityType::Announce => + CACHE.get(&object_id).map(|obj| { + view! { } + }.into_view()), + apb::ActivityType::Follow => + CACHE.get(&object_id).map(|obj| { + view! { +
+ + +
+ } + }.into_view()), + _ => None, + }; + Some(view! { + + {object} + {sep.clone()} + }) + } } else { None } diff --git a/web/src/config.rs b/web/src/config.rs index 1fcb389..68cf97a 100644 --- a/web/src/config.rs +++ b/web/src/config.rs @@ -21,6 +21,9 @@ pub struct Config { #[serde_inline_default::serde_inline_default] #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, serde_default::DefaultFromSerde)] pub struct FiltersConfig { + #[serde_inline_default(false)] + pub replies: bool, + #[serde_inline_default(false)] pub likes: bool, diff --git a/web/src/page/config.rs b/web/src/page/config.rs index f7abfb2..20ffb0a 100644 --- a/web/src/page/config.rs +++ b/web/src/page/config.rs @@ -85,6 +85,7 @@ pub fn ConfigPage(setter: WriteSignal) -> impl IntoView {

filters

    +
  • " replies"
  • " likes"
  • " creates"
  • " announces"