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> {
66 apub: &Self::ApubType,
67 expected_domain: &Url,
68 data: &Self::DataType,
69 request_counter: &mut i32,
70 ) -> Result<(), LemmyError> {
72 PersonOrGroup::Person(a) => {
73 ApubPerson::verify(a, expected_domain, data, request_counter).await
75 PersonOrGroup::Group(a) => {
76 ApubCommunity::verify(a, expected_domain, data, request_counter).await
83 data: &Self::DataType,
84 request_counter: &mut i32,
85 ) -> Result<Self, LemmyError> {
87 PersonOrGroup::Person(p) => {
88 UserOrCommunity::User(ApubPerson::from_apub(p, data, request_counter).await?)
90 PersonOrGroup::Group(p) => {
91 UserOrCommunity::Community(ApubCommunity::from_apub(p, data, request_counter).await?)
97 impl ActorType for UserOrCommunity {
98 fn actor_id(&self) -> Url {
102 fn public_key(&self) -> Option<String> {
104 UserOrCommunity::User(p) => p.public_key(),
105 UserOrCommunity::Community(p) => p.public_key(),
109 fn private_key(&self) -> Option<String> {
113 fn inbox_url(&self) -> Url {
117 fn shared_inbox_url(&self) -> Option<Url> {