Use User::outbox_page07() instead of outbox_page()
This commit is contained in:
parent
7b3b00be23
commit
68c794c54b
@ -7,7 +7,7 @@ use crate::{
|
||||
use activitypub::{
|
||||
activity::Delete,
|
||||
actor::Person,
|
||||
collection::{OrderedCollection, OrderedCollectionPage},
|
||||
collection::OrderedCollection,
|
||||
object::{Image, Tombstone},
|
||||
Activity, CustomObject, Endpoint,
|
||||
};
|
||||
@ -16,9 +16,7 @@ use activitystreams::{
|
||||
actor::{ApActor, AsApActor},
|
||||
actor::{ApActor as ApActor07, Endpoints as Endpoints07, Person as Person07},
|
||||
base::{AnyBase, Base},
|
||||
collection::{
|
||||
OrderedCollection as OrderedCollection07, OrderedCollectionPage as OrderedCollectionPage07,
|
||||
},
|
||||
collection::{OrderedCollection as OrderedCollection07, OrderedCollectionPage},
|
||||
iri_string::types::IriString,
|
||||
markers::Activity as Activity07,
|
||||
object::{kind::ImageType, AsObject as _, Image as Image07, Tombstone as Tombstone07},
|
||||
@ -505,59 +503,23 @@ impl User {
|
||||
coll.set_total_items(self.get_activities_count(conn) as u64);
|
||||
Ok(coll)
|
||||
}
|
||||
pub fn outbox_page(
|
||||
pub fn outbox_page07(
|
||||
&self,
|
||||
conn: &Connection,
|
||||
(min, max): (i32, i32),
|
||||
) -> Result<ActivityStream<OrderedCollectionPage>> {
|
||||
Ok(ActivityStream::new(
|
||||
self.outbox_collection_page(conn, (min, max))?,
|
||||
))
|
||||
}
|
||||
pub fn outbox_page07(
|
||||
&self,
|
||||
conn: &Connection,
|
||||
(min, max): (i32, i32),
|
||||
) -> Result<ActivityStream<OrderedCollectionPage07>> {
|
||||
Ok(ActivityStream::new(
|
||||
self.outbox_collection_page07(conn, (min, max))?,
|
||||
))
|
||||
}
|
||||
pub fn outbox_collection_page(
|
||||
pub fn outbox_collection_page07(
|
||||
&self,
|
||||
conn: &Connection,
|
||||
(min, max): (i32, i32),
|
||||
) -> Result<OrderedCollectionPage> {
|
||||
let acts = self.get_activities_page(conn, (min, max))?;
|
||||
let n_acts = self.get_activities_count(conn);
|
||||
let mut coll = OrderedCollectionPage::default();
|
||||
if n_acts - i64::from(min) >= i64::from(ITEMS_PER_PAGE) {
|
||||
coll.collection_page_props.set_next_link(Id::new(&format!(
|
||||
"{}?page={}",
|
||||
&self.outbox_url,
|
||||
min / ITEMS_PER_PAGE + 2
|
||||
)))?;
|
||||
}
|
||||
if min > 0 {
|
||||
coll.collection_page_props.set_prev_link(Id::new(&format!(
|
||||
"{}?page={}",
|
||||
&self.outbox_url,
|
||||
min / ITEMS_PER_PAGE
|
||||
)))?;
|
||||
}
|
||||
coll.collection_props.items = serde_json::to_value(acts)?;
|
||||
coll.collection_page_props
|
||||
.set_part_of_link(Id::new(&self.outbox_url))?;
|
||||
Ok(coll)
|
||||
}
|
||||
pub fn outbox_collection_page07(
|
||||
&self,
|
||||
conn: &Connection,
|
||||
(min, max): (i32, i32),
|
||||
) -> Result<OrderedCollectionPage07> {
|
||||
let acts = self.get_activities_page(conn, (min, max))?;
|
||||
let n_acts = self.get_activities_count(conn);
|
||||
let mut coll = OrderedCollectionPage07::new();
|
||||
let mut coll = OrderedCollectionPage::new();
|
||||
if n_acts - i64::from(min) >= i64::from(ITEMS_PER_PAGE) {
|
||||
coll.set_next(
|
||||
format!("{}?page={}", &self.outbox_url, min / ITEMS_PER_PAGE + 2)
|
||||
@ -1851,27 +1813,6 @@ pub(crate) mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outbox_collection_page() {
|
||||
let conn = db();
|
||||
conn.test_transaction::<_, Error, _>(|| {
|
||||
let users = fill_database(&conn);
|
||||
let user = &users[0];
|
||||
let act = user.outbox_collection_page(&conn, (33, 36))?;
|
||||
|
||||
let expected = json!({
|
||||
"items": [],
|
||||
"partOf": "https://plu.me/@/admin/outbox",
|
||||
"prev": "https://plu.me/@/admin/outbox?page=2",
|
||||
"type": "OrderedCollectionPage",
|
||||
});
|
||||
|
||||
assert_json_eq!(to_value(act)?, expected);
|
||||
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outbox_collection_page07() {
|
||||
let conn = db();
|
||||
|
@ -1,4 +1,5 @@
|
||||
use activitypub::collection::{OrderedCollection, OrderedCollectionPage};
|
||||
use activitypub::collection::OrderedCollection;
|
||||
use activitystreams::collection::OrderedCollectionPage;
|
||||
use diesel::SaveChangesDsl;
|
||||
use rocket::{
|
||||
http::{uri::Uri, ContentType, Cookies},
|
||||
@ -537,7 +538,7 @@ pub fn outbox_page(
|
||||
conn: DbConn,
|
||||
) -> Option<ActivityStream<OrderedCollectionPage>> {
|
||||
let user = User::find_by_fqn(&conn, &name).ok()?;
|
||||
user.outbox_page(&conn, page.limits()).ok()
|
||||
user.outbox_page07(&conn, page.limits()).ok()
|
||||
}
|
||||
#[post("/@/<name>/inbox", data = "<data>")]
|
||||
pub fn inbox(
|
||||
|
Loading…
Reference in New Issue
Block a user