Compare commits

..

No commits in common. "cfff8fb0530f33ff995ee4ed582d652dd3210c4e" and "ae85351b115a14108702e1aac379714cc011e6ae" have entirely different histories.

6 changed files with 35 additions and 22 deletions

View file

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

View file

@ -41,6 +41,32 @@ 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> {
/// return reference to embedded object (or first if many are present)
pub fn get(&self) -> Option<&T> {
@ -61,7 +87,7 @@ impl<T : super::Base> Node<T> {
}
/// true only if Node is empty
pub fn is_empty(&self) -> bool {
pub fn is_nothing(&self) -> bool {
matches!(self, Node::Empty)
}
@ -80,6 +106,12 @@ impl<T : super::Base> Node<T> {
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)
pub fn len(&self) -> usize {
match self {

View file

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

View file

@ -15,9 +15,6 @@ pub fn Object(object: crate::Object) -> impl IntoView {
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 attachments = object.attachment()
.flat()
.into_iter()
.filter_map(|x| x.extract()) // TODO maybe show links?
.map(|x| view! { <Attachment object=x sensitive=sensitive /> })
.collect_view();
let comments = object.replies().get()

View file

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

View file

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