2020-05-14 03:54:50 +00:00
|
|
|
use activitystreams_new::{
|
|
|
|
collection::OrderedCollection,
|
|
|
|
object::{ApObject, Page},
|
2020-05-15 03:18:34 +00:00
|
|
|
prelude::*,
|
2020-05-14 03:54:50 +00:00
|
|
|
traits::Extends,
|
|
|
|
};
|
|
|
|
use anyhow::Error;
|
|
|
|
|
|
|
|
fn main() -> Result<(), Error> {
|
|
|
|
let collection_json = r#"{
|
|
|
|
"type": "OrderedCollection",
|
|
|
|
"id": "http://lemmy_alpha:8540/federation/c/main",
|
|
|
|
"context": "https://www.w3.org/ns/activitystreams",
|
|
|
|
"items": [
|
|
|
|
{
|
|
|
|
"type": "Page",
|
|
|
|
"id": "http://lemmy_alpha:8540/federation/post/2",
|
|
|
|
"attributedTo": "http://lemmy_alpha:8540/federation/u/2",
|
|
|
|
"content": "test",
|
|
|
|
"context": "https://www.w3.org/ns/activitystreams",
|
|
|
|
"name": "test",
|
|
|
|
"published": "2020-03-13T00:14:41.188634+00:00"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "Page",
|
|
|
|
"id": "http://lemmy_alpha:8540/federation/post/1",
|
|
|
|
"attributedTo": "http://lemmy_alpha:8540/federation/u/2",
|
|
|
|
"context": "https://www.w3.org/ns/activitystreams",
|
|
|
|
"name": "test",
|
|
|
|
"published": "2020-03-13T00:13:56.311479+00:00"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"totalItems": 2
|
|
|
|
}"#;
|
|
|
|
|
|
|
|
let page_json = r#"{
|
|
|
|
"type": "Page",
|
|
|
|
"id": "http://lemmy_alpha:8540/federation/post/2",
|
|
|
|
"attributedTo": "http://lemmy_alpha:8540/federation/u/2",
|
|
|
|
"content": "test",
|
|
|
|
"name": "test",
|
|
|
|
"published": "2020-03-13T00:14:41.188634+00:00"
|
|
|
|
}"#;
|
|
|
|
|
|
|
|
let page: ApObject<Page> = serde_json::from_str(page_json)?;
|
|
|
|
println!("{:#?}", page);
|
2020-05-15 03:18:34 +00:00
|
|
|
let mut collection: ApObject<OrderedCollection> = serde_json::from_str(collection_json)?;
|
2020-05-14 03:54:50 +00:00
|
|
|
println!("{:#?}", collection);
|
|
|
|
|
|
|
|
let v: Vec<ApObject<Page>> = collection
|
2020-05-15 03:18:34 +00:00
|
|
|
.items()
|
2020-05-14 03:54:50 +00:00
|
|
|
.clone()
|
|
|
|
.many()
|
|
|
|
.into_iter()
|
|
|
|
.flatten()
|
|
|
|
.filter_map(|any_object| any_object.object())
|
|
|
|
.map(|object| object.solidify().and_then(|o| o.extend()))
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
|
|
|
|
println!("{:#?}", v);
|
|
|
|
let v = v
|
|
|
|
.into_iter()
|
|
|
|
.map(|o| o.retracts().and_then(|o| o.into_generic()))
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
collection.set_many_items(v);
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|