From b17884681d56e149799d39451ffa97dd29fc67f3 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Tue, 3 May 2022 02:50:14 +0900 Subject: [PATCH] Implement ap_followers using activitystreams --- src/routes/user.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/routes/user.rs b/src/routes/user.rs index 443cb151..e1b1cfdd 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -1,6 +1,7 @@ -use activitypub::collection::OrderedCollection; -use activitystreams::collection::{ - OrderedCollection as OrderedCollection07, OrderedCollectionPage, +use activitystreams::{ + collection::{OrderedCollection, OrderedCollectionPage}, + iri_string::types::IriString, + prelude::*, }; use diesel::SaveChangesDsl; use rocket::{ @@ -18,7 +19,7 @@ use crate::routes::{ }; use crate::template_utils::{IntoContext, Ructe}; use crate::utils::requires_login; -use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest, CustomPerson, Id}; +use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest, CustomPerson}; use plume_common::utils::md_to_html; use plume_models::{ blogs::Blog, @@ -529,7 +530,7 @@ pub fn create( } #[get("/@//outbox")] -pub fn outbox(name: String, conn: DbConn) -> Option> { +pub fn outbox(name: String, conn: DbConn) -> Option> { let user = User::find_by_fqn(&conn, &name).ok()?; user.outbox(&conn).ok() } @@ -564,17 +565,13 @@ pub fn ap_followers( .get_followers(&conn) .ok()? .into_iter() - .map(|f| Id::new(f.ap_url)) - .collect::>(); + .filter_map(|f| f.ap_url.parse::().ok()) + .collect::>(); - let mut coll = OrderedCollection::default(); - coll.object_props - .set_id_string(user.followers_endpoint) - .ok()?; - coll.collection_props - .set_total_items_u64(followers.len() as u64) - .ok()?; - coll.collection_props.set_items_link_vec(followers).ok()?; + let mut coll = OrderedCollection::new(); + coll.set_id(user.followers_endpoint.parse::().ok()?); + coll.set_total_items(followers.len() as u64); + coll.set_many_items(followers); Some(ActivityStream::new(coll)) }