From cd6c57b9c5041dae1b13eaf30efb86dbe5da1376 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 2 May 2022 22:53:35 +0900 Subject: [PATCH] Use Blog::outbox07() instead of outbox() --- plume-models/src/blogs.rs | 48 +-------------------------------------- src/routes/blogs.rs | 7 +++--- 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 091dd03a..ba8fef89 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -2,12 +2,7 @@ use crate::{ db_conn::DbConn, instance::*, medias::Media, posts::Post, safe_string::SafeString, schema::blogs, users::User, Connection, Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE, }; -use activitypub::{ - actor::Group, - collection::{OrderedCollection, OrderedCollectionPage}, - object::Image, - CustomObject, -}; +use activitypub::{actor::Group, collection::OrderedCollectionPage, object::Image, CustomObject}; use activitystreams::{ actor::{ApActor, ApActorExt, AsApActor, Group as Group07}, base::AnyBase, @@ -293,25 +288,6 @@ impl Blog { Ok(CustomGroup07::new(blog, ap_signature, source)) } - pub fn outbox(&self, conn: &Connection) -> Result> { - self.outbox_collection(conn).map(ActivityStream::new) - } - pub fn outbox_collection(&self, conn: &Connection) -> Result { - 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> { 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] fn outbox_collection07() { let conn = &db(); diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index c56b5a6e..25c09c91 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -1,4 +1,5 @@ -use activitypub::collection::{OrderedCollection, OrderedCollectionPage}; +use activitypub::collection::OrderedCollectionPage; +use activitystreams::collection::OrderedCollection as OrderedCollection07; use diesel::SaveChangesDsl; use rocket::{ http::ContentType, @@ -347,9 +348,9 @@ pub fn update( } #[get("/~//outbox")] -pub fn outbox(name: String, conn: DbConn) -> Option> { +pub fn outbox(name: String, conn: DbConn) -> Option> { let blog = Blog::find_by_fqn(&conn, &name).ok()?; - blog.outbox(&conn).ok() + blog.outbox07(&conn).ok() } #[allow(unused_variables)] #[get("/~//outbox?")]