feat(web): allow filtering replies

This commit is contained in:
əlemi 2024-05-23 22:35:34 +02:00
parent a6227a6679
commit 892637db04
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 32 additions and 22 deletions

View file

@ -43,7 +43,9 @@ pub fn Item(
match item.object_type() { match item.object_type() {
// special case for placeholder activities // special case for placeholder activities
Some(apb::ObjectType::Note) | Some(apb::ObjectType::Document(_)) => (move || { 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! { <Object object=item.clone() />{sep.clone()} }) Some(view! { <Object object=item.clone() />{sep.clone()} })
} else { } else {
None None
@ -53,27 +55,31 @@ pub fn Item(
Some(apb::ObjectType::Activity(t)) => (move || { Some(apb::ObjectType::Activity(t)) => (move || {
if config.get().filters.visible(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();
let object = match t { if !config.get().filters.replies && CACHE.get(&object_id).map(|x| x.in_reply_to().id().is_some()).unwrap_or(false) {
apb::ActivityType::Create | apb::ActivityType::Announce => None
CACHE.get(&object_id).map(|obj| { } else {
view! { <Object object=obj /> } let object = match t {
}.into_view()), apb::ActivityType::Create | apb::ActivityType::Announce =>
apb::ActivityType::Follow => CACHE.get(&object_id).map(|obj| {
CACHE.get(&object_id).map(|obj| { view! { <Object object=obj /> }
view! { }.into_view()),
<div class="ml-1"> apb::ActivityType::Follow =>
<ActorBanner object=obj /> CACHE.get(&object_id).map(|obj| {
<FollowRequestButtons activity_id=id.clone() actor_id=object_id /> view! {
</div> <div class="ml-1">
} <ActorBanner object=obj />
}.into_view()), <FollowRequestButtons activity_id=id.clone() actor_id=object_id />
_ => None, </div>
}; }
Some(view! { }.into_view()),
<ActivityLine activity=item.clone() /> _ => None,
{object} };
{sep.clone()} Some(view! {
}) <ActivityLine activity=item.clone() />
{object}
{sep.clone()}
})
}
} else { } else {
None None
} }

View file

@ -21,6 +21,9 @@ pub struct Config {
#[serde_inline_default::serde_inline_default] #[serde_inline_default::serde_inline_default]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, serde_default::DefaultFromSerde)] #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, serde_default::DefaultFromSerde)]
pub struct FiltersConfig { pub struct FiltersConfig {
#[serde_inline_default(false)]
pub replies: bool,
#[serde_inline_default(false)] #[serde_inline_default(false)]
pub likes: bool, pub likes: bool,

View file

@ -85,6 +85,7 @@ pub fn ConfigPage(setter: WriteSignal<crate::Config>) -> impl IntoView {
<hr /> <hr />
<p><code title="unchecked elements won't show in timelines">filters</code></p> <p><code title="unchecked elements won't show in timelines">filters</code></p>
<ul> <ul>
<li><span title="replies to other posts"><input type="checkbox" prop:checked=get_cfg!(filter replies) on:input=set_cfg!(filter replies) />" replies"</span></li>
<li><span title="like activities"><input type="checkbox" prop:checked=get_cfg!(filter likes) on:input=set_cfg!(filter likes) />" likes"</span></li> <li><span title="like activities"><input type="checkbox" prop:checked=get_cfg!(filter likes) on:input=set_cfg!(filter likes) />" likes"</span></li>
<li><span title="create activities with object"><input type="checkbox" prop:checked=get_cfg!(filter creates) on:input=set_cfg!(filter creates)/>" creates"</span></li> <li><span title="create activities with object"><input type="checkbox" prop:checked=get_cfg!(filter creates) on:input=set_cfg!(filter creates)/>" creates"</span></li>
<li><span title="announce activities with object"><input type="checkbox" prop:checked=get_cfg!(filter announces) on:input=set_cfg!(filter announces) />" announces"</span></li> <li><span title="announce activities with object"><input type="checkbox" prop:checked=get_cfg!(filter announces) on:input=set_cfg!(filter announces) />" announces"</span></li>