mirror of https://github.com/LemmyNet/lemmy
Rewrite community followers and user outbox to use our own structs
parent
d89156810d
commit
358ef99ea2
@ -0,0 +1,38 @@
|
||||
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![],
|
||||
})
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
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);
|
||||
|
@ -0,0 +1,26 @@
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue