2 objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
3 protocol::{ImageObject, Source},
5 use chrono::{DateTime, FixedOffset};
9 traits::{ActivityHandler, ApubObject},
10 values::MediaTypeHtml,
12 use lemmy_utils::LemmyError;
13 use lemmy_websocket::LemmyContext;
14 use serde::{Deserialize, Serialize};
15 use serde_with::skip_serializing_none;
18 #[derive(Clone, Debug, Deserialize, Serialize)]
24 #[skip_serializing_none]
25 #[derive(Clone, Debug, Deserialize, Serialize)]
26 #[serde(rename_all = "camelCase")]
28 pub(crate) r#type: PageType,
29 pub(crate) id: ObjectId<ApubPost>,
30 pub(crate) attributed_to: ObjectId<ApubPerson>,
31 #[serde(deserialize_with = "crate::deserialize_one_or_many")]
32 pub(crate) to: Vec<Url>,
33 pub(crate) name: String,
36 #[serde(deserialize_with = "crate::deserialize_one_or_many")]
37 pub(crate) cc: Vec<Url>,
38 pub(crate) content: Option<String>,
39 pub(crate) media_type: Option<MediaTypeHtml>,
40 pub(crate) source: Option<Source>,
41 pub(crate) url: Option<Url>,
42 pub(crate) image: Option<ImageObject>,
43 pub(crate) comments_enabled: Option<bool>,
44 pub(crate) sensitive: Option<bool>,
45 pub(crate) stickied: Option<bool>,
46 pub(crate) published: Option<DateTime<FixedOffset>>,
47 pub(crate) updated: Option<DateTime<FixedOffset>>,
51 /// Only mods can change the post's stickied/locked status. So if either of these is changed from
52 /// the current value, it is a mod action and needs to be verified as such.
54 /// Both stickied and locked need to be false on a newly created post (verified in [[CreatePost]].
55 pub(crate) async fn is_mod_action(&self, context: &LemmyContext) -> Result<bool, LemmyError> {
56 let old_post = ObjectId::<ApubPost>::new(self.id.clone())
57 .dereference_local(context)
60 let is_mod_action = if let Ok(old_post) = old_post {
61 self.stickied != Some(old_post.stickied) || self.comments_enabled != Some(!old_post.locked)
68 pub(crate) async fn extract_community(
70 context: &LemmyContext,
71 request_counter: &mut i32,
72 ) -> Result<ApubCommunity, LemmyError> {
73 let mut to_iter = self.to.iter();
75 if let Some(cid) = to_iter.next() {
76 let cid = ObjectId::new(cid.clone());
78 .dereference(context, context.client(), request_counter)
84 return Err(LemmyError::from_message("No community found in cc"));
90 // Used for community outbox, so that it can be compatible with Pleroma/Mastodon.
91 #[async_trait::async_trait(?Send)]
92 impl ActivityHandler for Page {
93 type DataType = LemmyContext;
96 data: &Data<Self::DataType>,
97 request_counter: &mut i32,
98 ) -> Result<(), LemmyError> {
99 ApubPost::verify(self, self.id.inner(), data, request_counter).await
103 data: &Data<Self::DataType>,
104 request_counter: &mut i32,
105 ) -> Result<(), LemmyError> {
106 ApubPost::from_apub(self, data, request_counter).await?;