--- /dev/null
+use crate::generate_followers_url;
+use activitystreams::collection::kind::CollectionType;
+use lemmy_api_common::blocking;
+use lemmy_db_schema::source::community::Community;
+use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct CommunityFollowers {
+ id: Url,
+ r#type: CollectionType,
+ total_items: i32,
+ items: Vec<()>,
+}
+
+impl CommunityFollowers {
+ pub(crate) async fn new(
+ community: Community,
+ context: &LemmyContext,
+ ) -> Result<CommunityFollowers, LemmyError> {
+ let community_id = community.id;
+ let community_followers = blocking(context.pool(), move |conn| {
+ CommunityFollowerView::for_community(conn, community_id)
+ })
+ .await??;
+
+ Ok(CommunityFollowers {
+ id: generate_followers_url(&community.actor_id)?.into_inner(),
+ r#type: CollectionType::Collection,
+ total_items: community_followers.len() as i32,
+ items: vec![],
+ })
+ }
+}
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize};
-use serde_with::skip_serializing_none;
use url::Url;
-#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupModerators {
};
use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize};
-use serde_with::skip_serializing_none;
use url::Url;
-#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupOutbox {
r#type: OrderedCollectionType,
id: Url,
+ total_items: i32,
ordered_items: Vec<CreateOrUpdatePost>,
}
Ok(GroupOutbox {
r#type: OrderedCollectionType::OrderedCollection,
id: generate_outbox_url(&data.0.actor_id)?.into(),
+ total_items: ordered_items.len() as i32,
ordered_items,
})
}
use crate::objects::community::ApubCommunity;
use lemmy_websocket::LemmyContext;
+pub(crate) mod community_followers;
pub(crate) mod community_moderators;
pub(crate) mod community_outbox;
+pub(crate) mod user_outbox;
/// Put community in the data, so we dont have to read it again from the database.
pub(crate) struct CommunityContext(pub ApubCommunity, pub LemmyContext);
--- /dev/null
+use crate::generate_outbox_url;
+use activitystreams::collection::kind::OrderedCollectionType;
+use lemmy_db_schema::source::person::Person;
+use lemmy_utils::LemmyError;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct UserOutbox {
+ r#type: OrderedCollectionType,
+ id: Url,
+ ordered_items: Vec<()>,
+ total_items: i32,
+}
+
+impl UserOutbox {
+ pub(crate) async fn new(user: Person) -> Result<UserOutbox, LemmyError> {
+ Ok(UserOutbox {
+ r#type: OrderedCollectionType::OrderedCollection,
+ id: generate_outbox_url(&user.actor_id)?.into_inner(),
+ ordered_items: vec![],
+ total_items: 0,
+ })
+ }
+}
verify_person_in_community,
},
collections::{
+ community_followers::CommunityFollowers,
community_moderators::ApubCommunityModerators,
community_outbox::ApubCommunityOutbox,
CommunityContext,
},
objects::community::ApubCommunity,
};
-use activitystreams::{
- base::BaseExt,
- collection::{CollectionExt, UnorderedCollection},
-};
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
verify::verify_domains_match,
};
use lemmy_db_schema::source::community::Community;
-use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use log::info;
Community::read_from_name(conn, &info.community_name)
})
.await??;
-
- let community_id = community.id;
- let community_followers = blocking(context.pool(), move |conn| {
- CommunityFollowerView::for_community(conn, community_id)
- })
- .await??;
-
- let mut collection = UnorderedCollection::new();
- collection
- .set_id(community.followers_url.into())
- .set_total_items(community_followers.len() as u64);
- let collection = WithContext::new(collection);
- Ok(create_apub_response(&collection))
+ let followers = CommunityFollowers::new(community, &context).await?;
+ Ok(create_apub_response(&followers))
}
/// Returns the community outbox, which is populated by a maximum of 20 posts (but no other
undo_delete::UndoDeletePrivateMessage,
},
},
+ collections::user_outbox::UserOutbox,
context::WithContext,
- generate_outbox_url,
http::{
create_apub_response,
create_apub_tombstone_response,
},
objects::person::ApubPerson,
};
-use activitystreams::{
- base::BaseExt,
- collection::{CollectionExt, OrderedCollection},
-};
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
use lemmy_api_common::blocking;
use lemmy_apub_lib::traits::{ActivityFields, ActivityHandler, ApubObject};
use lemmy_websocket::LemmyContext;
use log::info;
use serde::{Deserialize, Serialize};
-use url::Url;
#[derive(Deserialize)]
pub struct PersonQuery {
Person::find_by_name(conn, &info.user_name)
})
.await??;
- // TODO: populate the person outbox
- let mut collection = OrderedCollection::new();
- collection
- .set_many_items(Vec::<Url>::new())
- .set_id(generate_outbox_url(&person.actor_id)?.into())
- .set_total_items(0_u64);
- let collection = WithContext::new(collection);
- Ok(create_apub_response(&collection))
+ let outbox = UserOutbox::new(person).await?;
+ Ok(create_apub_response(&outbox))
}