2 objects::{community::ApubCommunity, person::ApubPerson},
3 protocol::objects::{group::Group, person::Person},
5 use chrono::NaiveDateTime;
6 use lemmy_apub_lib::traits::{ActorType, ApubObject};
7 use lemmy_utils::LemmyError;
8 use lemmy_websocket::LemmyContext;
9 use serde::Deserialize;
12 #[derive(Clone, Debug)]
13 pub enum UserOrCommunity {
15 Community(ApubCommunity),
18 #[derive(Deserialize)]
20 pub enum PersonOrGroup {
25 #[async_trait::async_trait(?Send)]
26 impl ApubObject for UserOrCommunity {
27 type DataType = LemmyContext;
28 type ApubType = PersonOrGroup;
29 type TombstoneType = ();
31 fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
33 UserOrCommunity::User(p) => p.last_refreshed_at,
34 UserOrCommunity::Community(p) => p.last_refreshed_at,
38 async fn read_from_apub_id(
40 data: &Self::DataType,
41 ) -> Result<Option<Self>, LemmyError> {
42 let person = ApubPerson::read_from_apub_id(object_id.clone(), data).await?;
44 Some(o) => Some(UserOrCommunity::User(o)),
45 None => ApubCommunity::read_from_apub_id(object_id, data)
47 .map(UserOrCommunity::Community),
51 async fn delete(self, data: &Self::DataType) -> Result<(), LemmyError> {
53 UserOrCommunity::User(p) => p.delete(data).await,
54 UserOrCommunity::Community(p) => p.delete(data).await,
58 async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
62 fn to_tombstone(&self) -> Result<Self::TombstoneType, LemmyError> {
67 apub: &Self::ApubType,
68 expected_domain: &Url,
69 data: &Self::DataType,
70 request_counter: &mut i32,
71 ) -> Result<(), LemmyError> {
73 PersonOrGroup::Person(a) => {
74 ApubPerson::verify(a, expected_domain, data, request_counter).await
76 PersonOrGroup::Group(a) => {
77 ApubCommunity::verify(a, expected_domain, data, request_counter).await
84 data: &Self::DataType,
85 request_counter: &mut i32,
86 ) -> Result<Self, LemmyError> {
88 PersonOrGroup::Person(p) => {
89 UserOrCommunity::User(ApubPerson::from_apub(p, data, request_counter).await?)
91 PersonOrGroup::Group(p) => {
92 UserOrCommunity::Community(ApubCommunity::from_apub(p, data, request_counter).await?)
98 impl ActorType for UserOrCommunity {
99 fn actor_id(&self) -> Url {
101 UserOrCommunity::User(p) => p.actor_id(),
102 UserOrCommunity::Community(p) => p.actor_id(),
106 fn public_key(&self) -> String {
108 UserOrCommunity::User(p) => p.public_key(),
109 UserOrCommunity::Community(p) => p.public_key(),
113 fn private_key(&self) -> Option<String> {
117 fn inbox_url(&self) -> Url {
121 fn shared_inbox_url(&self) -> Option<Url> {