feat(web): filter updated, more readable filter code
This commit is contained in:
parent
b0f47de278
commit
6469dbe85e
2 changed files with 52 additions and 46 deletions
|
@ -45,24 +45,16 @@ pub fn Item(
|
||||||
let config = use_context::<Signal<crate::Config>>().expect("missing config context");
|
let config = use_context::<Signal<crate::Config>>().expect("missing config context");
|
||||||
let id = item.id().unwrap_or_default().to_string();
|
let id = item.id().unwrap_or_default().to_string();
|
||||||
let sep = if sep { Some(view! { <hr /> }) } else { None };
|
let sep = if sep { Some(view! { <hr /> }) } else { None };
|
||||||
match item.object_type() {
|
if !replies && !config.get().filters.visible(&item) {
|
||||||
// special case for placeholder activities
|
return None;
|
||||||
Some(apb::ObjectType::Note) | Some(apb::ObjectType::Document(_)) => (move || {
|
|
||||||
if !config.get().filters.replies && item.in_reply_to().id().is_some() {
|
|
||||||
None
|
|
||||||
} else if config.get().filters.orphans {
|
|
||||||
Some(view! { <Object object=item.clone() />{sep.clone()} })
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}).into_view(),
|
match item.object_type().unwrap_or(apb::ObjectType::Object) {
|
||||||
|
// special case for placeholder activities
|
||||||
|
apb::ObjectType::Note | apb::ObjectType::Document(_) =>
|
||||||
|
Some(view! { <Object object=item.clone() />{sep.clone()} }.into_view()),
|
||||||
// everything else
|
// everything else
|
||||||
Some(apb::ObjectType::Activity(t)) => (move || {
|
apb::ObjectType::Activity(t) => {
|
||||||
if config.get().filters.visible(apb::ObjectType::Activity(t)) {
|
|
||||||
let object_id = item.object().id().unwrap_or_default();
|
let object_id = item.object().id().unwrap_or_default();
|
||||||
if !replies && !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 {
|
let object = match t {
|
||||||
apb::ActivityType::Create | apb::ActivityType::Announce =>
|
apb::ActivityType::Create | apb::ActivityType::Announce =>
|
||||||
CACHE.get(&object_id).map(|obj| {
|
CACHE.get(&object_id).map(|obj| {
|
||||||
|
@ -83,13 +75,9 @@ pub fn Item(
|
||||||
<ActivityLine activity=item.clone() />
|
<ActivityLine activity=item.clone() />
|
||||||
{object}
|
{object}
|
||||||
{sep.clone()}
|
{sep.clone()}
|
||||||
})
|
}.into_view())
|
||||||
}
|
},
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}).into_view(),
|
|
||||||
// should never happen
|
// should never happen
|
||||||
_ => view! { <p><code>type not implemented</code></p> }.into_view(),
|
t => Some(view! { <p><code>type not implemented : {t.as_ref().to_string()}</code></p> }.into_view()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,21 +36,39 @@ pub struct FiltersConfig {
|
||||||
#[serde_inline_default(true)]
|
#[serde_inline_default(true)]
|
||||||
pub follows: bool,
|
pub follows: bool,
|
||||||
|
|
||||||
|
#[serde_inline_default(false)]
|
||||||
|
pub updates: bool,
|
||||||
|
|
||||||
#[serde_inline_default(true)]
|
#[serde_inline_default(true)]
|
||||||
pub orphans: bool,
|
pub orphans: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FiltersConfig {
|
impl FiltersConfig {
|
||||||
pub fn visible(&self, object_type: apb::ObjectType) -> bool {
|
pub fn visible(&self, item: &crate::Object) -> bool {
|
||||||
match object_type {
|
use apb::{Object, Activity};
|
||||||
|
|
||||||
|
let type_filter = match item.object_type().unwrap_or(apb::ObjectType::Object) {
|
||||||
apb::ObjectType::Note | apb::ObjectType::Document(_) => self.orphans,
|
apb::ObjectType::Note | apb::ObjectType::Document(_) => self.orphans,
|
||||||
apb::ObjectType::Activity(apb::ActivityType::Like | apb::ActivityType::EmojiReact) => self.likes,
|
apb::ObjectType::Activity(apb::ActivityType::Like | apb::ActivityType::EmojiReact) => self.likes,
|
||||||
apb::ObjectType::Activity(apb::ActivityType::Create) => self.creates,
|
apb::ObjectType::Activity(apb::ActivityType::Create) => self.creates,
|
||||||
apb::ObjectType::Activity(apb::ActivityType::Announce) => self.announces,
|
apb::ObjectType::Activity(apb::ActivityType::Announce) => self.announces,
|
||||||
|
apb::ObjectType::Activity(apb::ActivityType::Update) => self.updates,
|
||||||
apb::ObjectType::Activity(
|
apb::ObjectType::Activity(
|
||||||
apb::ActivityType::Follow | apb::ActivityType::Accept(_) | apb::ActivityType::Reject(_)
|
apb::ActivityType::Follow | apb::ActivityType::Accept(_) | apb::ActivityType::Reject(_)
|
||||||
) => self.follows,
|
) => self.follows,
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
};
|
||||||
|
let mut reply_filter = true;
|
||||||
|
|
||||||
|
if
|
||||||
|
item.in_reply_to().id().is_some() ||
|
||||||
|
item.object().get().map(|x|
|
||||||
|
x.in_reply_to().id().is_some()
|
||||||
|
).unwrap_or(false)
|
||||||
|
{
|
||||||
|
reply_filter = self.replies;
|
||||||
|
};
|
||||||
|
|
||||||
|
type_filter && reply_filter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue