]> Untitled Git - lemmy.git/blob - crates/apub/src/fetcher/user_or_community.rs
Remove unused ActorType methods
[lemmy.git] / crates / apub / src / fetcher / user_or_community.rs
1 use crate::{
2   objects::{community::ApubCommunity, person::ApubPerson},
3   protocol::objects::{group::Group, person::Person},
4 };
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;
10
11 #[derive(Clone, Debug)]
12 pub enum UserOrCommunity {
13   User(ApubPerson),
14   Community(ApubCommunity),
15 }
16
17 #[derive(Deserialize)]
18 #[serde(untagged)]
19 pub enum PersonOrGroup {
20   Person(Person),
21   Group(Group),
22 }
23
24 #[async_trait::async_trait(?Send)]
25 impl ApubObject for UserOrCommunity {
26   type DataType = LemmyContext;
27   type ApubType = PersonOrGroup;
28   type TombstoneType = ();
29
30   fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
31     Some(match self {
32       UserOrCommunity::User(p) => p.last_refreshed_at,
33       UserOrCommunity::Community(p) => p.last_refreshed_at,
34     })
35   }
36
37   async fn read_from_apub_id(
38     object_id: Url,
39     data: &Self::DataType,
40   ) -> Result<Option<Self>, LemmyError> {
41     let person = ApubPerson::read_from_apub_id(object_id.clone(), data).await?;
42     Ok(match person {
43       Some(o) => Some(UserOrCommunity::User(o)),
44       None => ApubCommunity::read_from_apub_id(object_id, data)
45         .await?
46         .map(UserOrCommunity::Community),
47     })
48   }
49
50   async fn delete(self, data: &Self::DataType) -> Result<(), LemmyError> {
51     match self {
52       UserOrCommunity::User(p) => p.delete(data).await,
53       UserOrCommunity::Community(p) => p.delete(data).await,
54     }
55   }
56
57   async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
58     unimplemented!()
59   }
60
61   fn to_tombstone(&self) -> Result<Self::TombstoneType, LemmyError> {
62     unimplemented!()
63   }
64
65   async fn from_apub(
66     apub: Self::ApubType,
67     data: &Self::DataType,
68     expected_domain: &Url,
69     request_counter: &mut i32,
70   ) -> Result<Self, LemmyError> {
71     Ok(match apub {
72       PersonOrGroup::Person(p) => UserOrCommunity::User(
73         ApubPerson::from_apub(p, data, expected_domain, request_counter).await?,
74       ),
75       PersonOrGroup::Group(p) => UserOrCommunity::Community(
76         ApubCommunity::from_apub(p, data, expected_domain, request_counter).await?,
77       ),
78     })
79   }
80 }
81
82 impl ActorType for UserOrCommunity {
83   fn actor_id(&self) -> Url {
84     todo!()
85   }
86
87   fn public_key(&self) -> Option<String> {
88     match self {
89       UserOrCommunity::User(p) => p.public_key(),
90       UserOrCommunity::Community(p) => p.public_key(),
91     }
92   }
93
94   fn private_key(&self) -> Option<String> {
95     todo!()
96   }
97
98   fn inbox_url(&self) -> Url {
99     todo!()
100   }
101
102   fn shared_inbox_url(&self) -> Option<Url> {
103     todo!()
104   }
105 }