fetcher::user_or_community::{PersonOrGroupType, UserOrCommunity},
local_instance,
objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
- protocol::{ImageObject, Source},
+ protocol::{objects::LanguageTag, ImageObject, Source},
};
use activitypub_federation::{
core::object_id::ObjectId,
},
traits::{ActivityHandler, ApubObject},
};
-use activitystreams_kinds::link::LinkType;
+use activitystreams_kinds::{link::LinkType, object::ImageType};
use chrono::{DateTime, FixedOffset};
use itertools::Itertools;
use lemmy_db_schema::newtypes::DbUrl;
use serde_with::skip_serializing_none;
use url::Url;
-#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
+#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum PageType {
Page,
Article,
pub(crate) stickied: Option<bool>,
pub(crate) published: Option<DateTime<FixedOffset>>,
pub(crate) updated: Option<DateTime<FixedOffset>>,
+ pub(crate) language: Option<LanguageTag>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
-pub(crate) struct Attachment {
+pub(crate) struct Link {
pub(crate) href: Url,
pub(crate) r#type: LinkType,
}
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct Image {
+ #[serde(rename = "type")]
+ pub(crate) kind: ImageType,
+ pub(crate) url: Url,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(untagged)]
+pub(crate) enum Attachment {
+ Link(Link),
+ Image(Image),
+}
+
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub(crate) enum AttributedTo {
/// Both stickied and locked need to be false on a newly created post (verified in [[CreatePost]].
pub(crate) async fn is_mod_action(&self, context: &LemmyContext) -> Result<bool, LemmyError> {
let old_post = ObjectId::<ApubPost>::new(self.id.clone())
- .dereference_local::<LemmyError>(context)
+ .dereference_local(context)
.await;
let stickied_changed = Page::is_stickied_changed(&old_post, &self.stickied);
if let Some(cid) = iter.next() {
let cid = ObjectId::new(cid.clone());
if let Ok(c) = cid
- .dereference::<LemmyError>(context, local_instance(context), request_counter)
+ .dereference(context, local_instance(context), request_counter)
.await
{
break Ok(c);
.find(|a| a.kind == PersonOrGroupType::Group)
.map(|a| ObjectId::<ApubCommunity>::new(a.id.clone().into_inner()))
.ok_or_else(|| LemmyError::from_message("page does not specify group"))?
- .dereference::<LemmyError>(context, local_instance(context), request_counter)
+ .dereference(context, local_instance(context), request_counter)
.await
}
}
impl Attachment {
pub(crate) fn new(url: DbUrl) -> Attachment {
- Attachment {
+ Attachment::Link(Link {
href: url.into(),
r#type: Default::default(),
- }
+ })
}
}