Use Blog::outbox07() instead of outbox()

This commit is contained in:
Kitaiti Makoto 2022-05-02 22:53:35 +09:00
parent f608f7a4d6
commit cd6c57b9c5
2 changed files with 5 additions and 50 deletions

View file

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

View file

@ -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("/~/<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()?;
blog.outbox(&conn).ok()
blog.outbox07(&conn).ok()
}
#[allow(unused_variables)]
#[get("/~/<name>/outbox?<page>")]