fix(apb): remove ambiguous Iterator impl for node

This commit is contained in:
əlemi 2024-11-11 01:19:33 +01:00
parent ae85351b11
commit 4b632faf2a
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 20 additions and 27 deletions

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> {

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();