2024-04-21 17:43:36 +02:00
|
|
|
use leptos::*;
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
2024-05-11 21:49:55 +02:00
|
|
|
use apb::{target::Addressed, Base, Activity, Object};
|
2024-04-21 17:43:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
#[component]
|
2024-05-01 16:06:46 +02:00
|
|
|
pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
|
2024-04-21 17:43:36 +02:00
|
|
|
let object_id = activity.object().id().unwrap_or_default();
|
|
|
|
let actor_id = activity.actor().id().unwrap_or_default();
|
2024-05-01 16:06:46 +02:00
|
|
|
let actor = CACHE.get_or(&actor_id, serde_json::Value::String(actor_id.clone()).into());
|
2024-04-21 17:43:36 +02:00
|
|
|
let kind = activity.activity_type().unwrap_or(apb::ActivityType::Activity);
|
2024-05-02 02:07:54 +02:00
|
|
|
let href = match kind {
|
2024-05-20 06:25:47 +02:00
|
|
|
apb::ActivityType::Follow => Uri::web(U::User, &object_id),
|
2024-05-02 02:07:54 +02:00
|
|
|
// TODO for update check what's being updated
|
2024-05-20 06:25:47 +02:00
|
|
|
_ => Uri::web(U::Object, &object_id),
|
2024-05-02 02:07:54 +02:00
|
|
|
};
|
2024-04-21 17:43:36 +02:00
|
|
|
view! {
|
|
|
|
<div>
|
2024-05-01 16:45:27 +02:00
|
|
|
<span class="ml-1-r">
|
|
|
|
<ActorStrip object=actor />
|
|
|
|
</span>
|
2024-04-22 03:31:51 +02:00
|
|
|
<span style="float:right">
|
2024-04-23 03:31:42 +02:00
|
|
|
<code class="color moreinfo" title={activity.published().map(|x| x.to_rfc2822())} >
|
2024-05-02 02:07:54 +02:00
|
|
|
<a class="upub-title clean" title={object_id} href={href} >
|
2024-04-23 03:31:42 +02:00
|
|
|
{kind.as_ref().to_string()}
|
|
|
|
</a>
|
|
|
|
<PrivacyMarker addressed=activity.addressed() />
|
|
|
|
</code>
|
2024-04-22 03:31:51 +02:00
|
|
|
</span>
|
2024-04-21 17:43:36 +02:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
2024-05-11 21:49:55 +02:00
|
|
|
|
|
|
|
#[component]
|
2024-05-12 00:12:07 +02:00
|
|
|
pub fn Item(
|
|
|
|
item: crate::Object,
|
|
|
|
#[prop(optional)] sep: bool,
|
|
|
|
) -> impl IntoView {
|
|
|
|
let config = use_context::<Signal<crate::Config>>().expect("missing config context");
|
2024-05-11 21:49:55 +02:00
|
|
|
let id = item.id().unwrap_or_default().to_string();
|
2024-05-12 00:12:07 +02:00
|
|
|
let sep = if sep { Some(view! { <hr /> }) } else { None };
|
2024-05-11 21:49:55 +02:00
|
|
|
match item.object_type() {
|
|
|
|
// special case for placeholder activities
|
2024-05-12 00:12:07 +02:00
|
|
|
Some(apb::ObjectType::Note) | Some(apb::ObjectType::Document(_)) => (move || {
|
2024-05-23 22:35:34 +02:00
|
|
|
if !config.get().filters.replies && item.in_reply_to().id().is_some() {
|
|
|
|
None
|
|
|
|
} else if config.get().filters.orphans {
|
2024-05-12 00:12:07 +02:00
|
|
|
Some(view! { <Object object=item.clone() />{sep.clone()} })
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}).into_view(),
|
2024-05-11 21:49:55 +02:00
|
|
|
// everything else
|
2024-05-12 00:12:07 +02:00
|
|
|
Some(apb::ObjectType::Activity(t)) => (move || {
|
|
|
|
if config.get().filters.visible(apb::ObjectType::Activity(t)) {
|
|
|
|
let object_id = item.object().id().unwrap_or_default();
|
2024-05-23 22:35:34 +02:00
|
|
|
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! { <Object object=obj /> }
|
|
|
|
}.into_view()),
|
|
|
|
apb::ActivityType::Follow =>
|
|
|
|
CACHE.get(&object_id).map(|obj| {
|
|
|
|
view! {
|
|
|
|
<div class="ml-1">
|
|
|
|
<ActorBanner object=obj />
|
|
|
|
<FollowRequestButtons activity_id=id.clone() actor_id=object_id />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}.into_view()),
|
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
Some(view! {
|
|
|
|
<ActivityLine activity=item.clone() />
|
|
|
|
{object}
|
|
|
|
{sep.clone()}
|
|
|
|
})
|
|
|
|
}
|
2024-05-12 00:12:07 +02:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}).into_view(),
|
2024-05-11 21:49:55 +02:00
|
|
|
// should never happen
|
|
|
|
_ => view! { <p><code>type not implemented</code></p> }.into_view(),
|
|
|
|
}
|
|
|
|
}
|