2 objects::{community::ApubCommunity, person::ApubPerson},
3 protocol::objects::{group::Group, person::Person},
5 use activitystreams::{chrono::NaiveDateTime, url::Url};
6 use lemmy_apub_lib::traits::{ActorType, ApubObject};
7 use lemmy_utils::LemmyError;
8 use lemmy_websocket::LemmyContext;
9 use serde::Deserialize;
11 #[derive(Clone, Debug)]
12 pub enum UserOrCommunity {
14 Community(ApubCommunity),
17 #[derive(Deserialize)]
19 pub enum PersonOrGroup {
24 #[async_trait::async_trait(?Send)]
25 impl ApubObject for UserOrCommunity {
26 type DataType = LemmyContext;
27 type ApubType = PersonOrGroup;
28 type TombstoneType = ();
30 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
32 UserOrCommunity::User(p) => p.last_refreshed_at,
33 UserOrCommunity::Community(p) => p.last_refreshed_at,
37 async fn read_from_apub_id(
39 data: &Self::DataType,
40 ) -> Result<Option<Self>, LemmyError> {
41 let person = ApubPerson::read_from_apub_id(object_id.clone(), data).await?;
43 Some(o) => Some(UserOrCommunity::User(o)),
44 None => ApubCommunity::read_from_apub_id(object_id, data)
46 .map(UserOrCommunity::Community),
50 async fn delete(self, data: &Self::DataType) -> Result<(), LemmyError> {
52 UserOrCommunity::User(p) => p.delete(data).await,
53 UserOrCommunity::Community(p) => p.delete(data).await,
57 async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
61 fn to_tombstone(&self) -> Result<Self::TombstoneType, LemmyError> {
67 data: &Self::DataType,
68 expected_domain: &Url,
69 request_counter: &mut i32,
70 ) -> Result<Self, LemmyError> {
72 PersonOrGroup::Person(p) => UserOrCommunity::User(
73 ApubPerson::from_apub(p, data, expected_domain, request_counter).await?,
75 PersonOrGroup::Group(p) => UserOrCommunity::Community(
76 ApubCommunity::from_apub(p, data, expected_domain, request_counter).await?,
82 impl ActorType for UserOrCommunity {
83 fn actor_id(&self) -> Url {
87 fn public_key(&self) -> Option<String> {
89 UserOrCommunity::User(p) => p.public_key(),
90 UserOrCommunity::Community(p) => p.public_key(),
94 fn private_key(&self) -> Option<String> {
98 fn inbox_url(&self) -> Url {
102 fn shared_inbox_url(&self) -> Option<Url> {