Compare commits

...

2 commits

Author SHA1 Message Date
cfff8fb053
fix(apb): is_nothing -> is_empty 2024-11-11 01:19:51 +01:00
4b632faf2a
fix(apb): remove ambiguous Iterator impl for node 2024-11-11 01:19:33 +01:00
6 changed files with 22 additions and 35 deletions

View file

@ -308,7 +308,7 @@ pub(crate) use setter;
#[cfg(feature = "unstructured")] #[cfg(feature = "unstructured")]
pub fn set_maybe_node(obj: &mut serde_json::Value, key: &str, node: crate::Node<serde_json::Value>) { pub fn set_maybe_node(obj: &mut serde_json::Value, key: &str, node: crate::Node<serde_json::Value>) {
if node.is_nothing() { if node.is_empty() {
set_maybe_value(obj, key, None) set_maybe_value(obj, key, None)
} else { } else {
set_maybe_value(obj, key, Some(node.into_inner())) set_maybe_value(obj, key, Some(node.into_inner()))

View file

@ -41,32 +41,6 @@ impl<T : super::Base> From<Option<T>> for Node<T> {
} }
} }
impl<T : super::Base> Iterator for Node<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
match std::mem::replace(self, Self::Empty) {
Self::Empty => None,
Self::Object(res) => Some(*res),
Self::Link(lnk) => {
*self = Self::Link(lnk);
None
},
Self::Array(mut arr) => {
let mut out = None;
while let Some(res) = arr.pop_front() {
if let Some(inner) = res.extract() {
out = Some(inner);
break;
}
}
*self = Self::Array(arr);
out
}
}
}
}
impl<T : super::Base> Node<T> { impl<T : super::Base> Node<T> {
/// return reference to embedded object (or first if many are present) /// return reference to embedded object (or first if many are present)
pub fn get(&self) -> Option<&T> { pub fn get(&self) -> Option<&T> {
@ -87,7 +61,7 @@ impl<T : super::Base> Node<T> {
} }
/// true only if Node is empty /// true only if Node is empty
pub fn is_nothing(&self) -> bool { pub fn is_empty(&self) -> bool {
matches!(self, Node::Empty) matches!(self, Node::Empty)
} }
@ -106,12 +80,6 @@ impl<T : super::Base> Node<T> {
matches!(self, Node::Array(_)) matches!(self, Node::Array(_))
} }
/// true only if Node is empty
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// returns number of contained items (links count as items for len) /// returns number of contained items (links count as items for len)
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
match self { match self {

View file

@ -42,6 +42,9 @@ pub fn ActorHeader() -> impl IntoView {
Some(view! { <sup class="ml-s"><small>"["{actor_type.as_ref().to_lowercase()}"]"</small></sup> } ) Some(view! { <sup class="ml-s"><small>"["{actor_type.as_ref().to_lowercase()}"]"</small></sup> } )
}; };
let fields = actor.attachment() let fields = actor.attachment()
.flat()
.into_iter()
.filter_map(|x| x.extract())
.map(|x| view! { .map(|x| view! {
<tr> <tr>
<td class="w-25"><b class="color">{x.name().str().unwrap_or_default()}</b></td> <td class="w-25"><b class="color">{x.name().str().unwrap_or_default()}</b></td>

View file

@ -15,6 +15,9 @@ pub fn Object(object: crate::Object) -> impl IntoView {
let public = addressed.iter().any(|x| x.as_str() == apb::target::PUBLIC); let public = addressed.iter().any(|x| x.as_str() == apb::target::PUBLIC);
let external_url = object.url().id().str().unwrap_or_else(|| oid.clone()); let external_url = object.url().id().str().unwrap_or_else(|| oid.clone());
let attachments = object.attachment() let attachments = object.attachment()
.flat()
.into_iter()
.filter_map(|x| x.extract()) // TODO maybe show links?
.map(|x| view! { <Attachment object=x sensitive=sensitive /> }) .map(|x| view! { <Attachment object=x sensitive=sensitive /> })
.collect_view(); .collect_view();
let comments = object.replies().get() let comments = object.replies().get()

View file

@ -35,7 +35,17 @@ pub fn SearchPage() -> impl IntoView {
let search = format!("{URL_BASE}/search?q={q}"); let search = format!("{URL_BASE}/search?q={q}");
async move { async move {
let items = Http::fetch::<serde_json::Value>(&search, auth).await.ok()?; let items = Http::fetch::<serde_json::Value>(&search, auth).await.ok()?;
Some(crate::timeline::process_activities(items.ordered_items().collect(), auth).await) Some(
crate::timeline::process_activities(
items
.ordered_items()
.flat()
.into_iter()
.filter_map(|x| x.extract())
.collect(),
auth
).await
)
} }
} }
); );

View file

@ -87,6 +87,9 @@ impl Timeline {
let collection : serde_json::Value = Http::fetch(&feed_url, auth).await?; let collection : serde_json::Value = Http::fetch(&feed_url, auth).await?;
let activities : Vec<serde_json::Value> = collection let activities : Vec<serde_json::Value> = collection
.ordered_items() .ordered_items()
.flat()
.into_iter()
.filter_map(|x| x.extract())
.collect(); .collect();
let mut feed = self.feed.get_untracked(); let mut feed = self.feed.get_untracked();