Use Blog::outbox07() instead of outbox()
This commit is contained in:
parent
f608f7a4d6
commit
cd6c57b9c5
@ -2,12 +2,7 @@ use crate::{
|
|||||||
db_conn::DbConn, instance::*, medias::Media, posts::Post, safe_string::SafeString,
|
db_conn::DbConn, instance::*, medias::Media, posts::Post, safe_string::SafeString,
|
||||||
schema::blogs, users::User, Connection, Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
|
schema::blogs, users::User, Connection, Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
|
||||||
};
|
};
|
||||||
use activitypub::{
|
use activitypub::{actor::Group, collection::OrderedCollectionPage, object::Image, CustomObject};
|
||||||
actor::Group,
|
|
||||||
collection::{OrderedCollection, OrderedCollectionPage},
|
|
||||||
object::Image,
|
|
||||||
CustomObject,
|
|
||||||
};
|
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
actor::{ApActor, ApActorExt, AsApActor, Group as Group07},
|
actor::{ApActor, ApActorExt, AsApActor, Group as Group07},
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
@ -293,25 +288,6 @@ impl Blog {
|
|||||||
Ok(CustomGroup07::new(blog, ap_signature, source))
|
Ok(CustomGroup07::new(blog, ap_signature, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn outbox(&self, conn: &Connection) -> Result<ActivityStream<OrderedCollection>> {
|
|
||||||
self.outbox_collection(conn).map(ActivityStream::new)
|
|
||||||
}
|
|
||||||
pub fn outbox_collection(&self, conn: &Connection) -> Result<OrderedCollection> {
|
|
||||||
let mut coll = OrderedCollection::default();
|
|
||||||
coll.collection_props.items = serde_json::to_value(self.get_activities(conn))?;
|
|
||||||
coll.collection_props
|
|
||||||
.set_total_items_u64(self.get_activities(conn).len() as u64)?;
|
|
||||||
coll.collection_props
|
|
||||||
.set_first_link(Id::new(&format!("{}?page=1", &self.outbox_url)))?;
|
|
||||||
coll.collection_props.set_last_link(Id::new(&format!(
|
|
||||||
"{}?page={}",
|
|
||||||
&self.outbox_url,
|
|
||||||
(self.get_activities(conn).len() as u64 + ITEMS_PER_PAGE as u64 - 1) as u64
|
|
||||||
/ ITEMS_PER_PAGE as u64
|
|
||||||
)))?;
|
|
||||||
Ok(coll)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn outbox07(&self, conn: &Connection) -> Result<ActivityStream<OrderedCollection07>> {
|
pub fn outbox07(&self, conn: &Connection) -> Result<ActivityStream<OrderedCollection07>> {
|
||||||
self.outbox_collection07(conn).map(ActivityStream::new)
|
self.outbox_collection07(conn).map(ActivityStream::new)
|
||||||
}
|
}
|
||||||
@ -1177,28 +1153,6 @@ pub(crate) mod tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn outbox_collection() {
|
|
||||||
let conn = &db();
|
|
||||||
conn.test_transaction::<_, Error, _>(|| {
|
|
||||||
let (_users, blogs) = fill_database(conn);
|
|
||||||
let blog = &blogs[0];
|
|
||||||
let act = blog.outbox_collection(conn)?;
|
|
||||||
|
|
||||||
let expected = json!({
|
|
||||||
"items": [],
|
|
||||||
"totalItems": 0,
|
|
||||||
"first": "https://plu.me/~/BlogName/outbox?page=1",
|
|
||||||
"last": "https://plu.me/~/BlogName/outbox?page=0",
|
|
||||||
"type": "OrderedCollection"
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_json_eq!(to_value(act)?, expected);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn outbox_collection07() {
|
fn outbox_collection07() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use activitypub::collection::{OrderedCollection, OrderedCollectionPage};
|
use activitypub::collection::OrderedCollectionPage;
|
||||||
|
use activitystreams::collection::OrderedCollection as OrderedCollection07;
|
||||||
use diesel::SaveChangesDsl;
|
use diesel::SaveChangesDsl;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
http::ContentType,
|
http::ContentType,
|
||||||
@ -347,9 +348,9 @@ pub fn update(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/~/<name>/outbox")]
|
#[get("/~/<name>/outbox")]
|
||||||
pub fn outbox(name: String, conn: DbConn) -> Option<ActivityStream<OrderedCollection>> {
|
pub fn outbox(name: String, conn: DbConn) -> Option<ActivityStream<OrderedCollection07>> {
|
||||||
let blog = Blog::find_by_fqn(&conn, &name).ok()?;
|
let blog = Blog::find_by_fqn(&conn, &name).ok()?;
|
||||||
blog.outbox(&conn).ok()
|
blog.outbox07(&conn).ok()
|
||||||
}
|
}
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[get("/~/<name>/outbox?<page>")]
|
#[get("/~/<name>/outbox?<page>")]
|
||||||
|
Loading…
Reference in New Issue
Block a user