Skip to content

Commit

Permalink
deserialize_one
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Apr 23, 2023
1 parent d989be1 commit ab6f766
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/apub/src/activities/community/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Report {
)?;
let report = Report {
actor: actor.id().into(),
to: [community.id().into()],
to: community.id().into(),
object: object_id,
summary: reason,
kind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl CreateOrUpdateChatMessage {
let create_or_update = CreateOrUpdateChatMessage {
id: id.clone(),
actor: sender.id().into(),
to: [recipient.id().into()],
to: recipient.id().into(),
object: ApubPrivateMessage(private_message.clone())
.into_json(context)
.await?,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl ActivityHandler for CreateOrUpdateChatMessage {
async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
verify_person(&self.actor, context).await?;
verify_domains_match(self.actor.inner(), self.object.id.inner())?;
verify_domains_match(self.to[0].inner(), self.object.to[0].inner())?;
verify_domains_match(self.to.inner(), self.object.to.inner())?;
ApubPrivateMessage::verify(&self.object, self.actor.inner(), context).await?;
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/private_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Object for ApubPrivateMessage {
r#type: ChatMessageType::ChatMessage,
id: self.ap_id.clone().into(),
attributed_to: creator.actor_id.into(),
to: [recipient.actor_id.into()],
to: recipient.actor_id.into(),
content: markdown_to_html(&self.content),
media_type: Some(MediaTypeHtml::Html),
source: Some(Source::new(self.content.clone())),
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Object for ApubPrivateMessage {
context: &Data<Self::DataType>,
) -> Result<ApubPrivateMessage, LemmyError> {
let creator = note.attributed_to.dereference(context).await?;
let recipient = note.to[0].dereference(context).await?;
let recipient = note.to.dereference(context).await?;
check_person_block(creator.id, recipient.id, context.pool()).await?;

let form = PrivateMessageInsertForm {
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/protocol/activities/community/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use url::Url;
pub struct Report {
pub(crate) actor: ObjectId<ApubPerson>,
#[serde(deserialize_with = "deserialize_one")]
pub(crate) to: [ObjectId<ApubCommunity>; 1],
pub(crate) to: ObjectId<ApubCommunity>,
pub(crate) object: ObjectId<PostOrComment>,
pub(crate) summary: String,
#[serde(rename = "type")]
Expand All @@ -32,7 +32,7 @@ pub struct Report {
#[async_trait::async_trait]
impl InCommunity for Report {
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
let community = self.to[0].dereference(context).await?;
let community = self.to.dereference(context).await?;
if let Some(audience) = &self.audience {
verify_community_matches(audience, community.actor_id.clone())?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct CreateOrUpdateChatMessage {
pub(crate) id: Url,
pub(crate) actor: ObjectId<ApubPerson>,
#[serde(deserialize_with = "deserialize_one")]
pub(crate) to: [ObjectId<ApubPerson>; 1],
pub(crate) to: ObjectId<ApubPerson>,
pub(crate) object: ChatMessage,
#[serde(rename = "type")]
pub(crate) kind: CreateOrUpdateType,
Expand Down
7 changes: 6 additions & 1 deletion crates/apub/src/protocol/activities/following/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use crate::{
objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::follow::Follow,
};
use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::AcceptType};
use activitypub_federation::{
fetch::object_id::ObjectId,
kinds::activity::AcceptType,
protocol::helpers::deserialize_one,
};
use serde::{Deserialize, Serialize};
use url::Url;

Expand All @@ -11,6 +15,7 @@ use url::Url;
pub struct AcceptFollow {
pub(crate) actor: ObjectId<ApubCommunity>,
/// Optional, for compatibility with platforms that always expect recipient field
#[serde(deserialize_with = "deserialize_one")]
pub(crate) to: Option<ObjectId<ApubPerson>>,
pub(crate) object: Follow,
#[serde(rename = "type")]
Expand Down
7 changes: 6 additions & 1 deletion crates/apub/src/protocol/activities/following/follow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::{fetcher::user_or_community::UserOrCommunity, objects::person::ApubPerson};
use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::FollowType};
use activitypub_federation::{
fetch::object_id::ObjectId,
kinds::activity::FollowType,
protocol::helpers::deserialize_one,
};
use serde::{Deserialize, Serialize};
use url::Url;

Expand All @@ -8,6 +12,7 @@ use url::Url;
pub struct Follow {
pub(crate) actor: ObjectId<ApubPerson>,
/// Optional, for compatibility with platforms that always expect recipient field
#[serde(deserialize_with = "deserialize_one")]
pub(crate) to: Option<ObjectId<UserOrCommunity>>,
pub(crate) object: ObjectId<UserOrCommunity>,
#[serde(rename = "type")]
Expand Down
7 changes: 6 additions & 1 deletion crates/apub/src/protocol/activities/following/undo_follow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::{objects::person::ApubPerson, protocol::activities::following::follow::Follow};
use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::UndoType};
use activitypub_federation::{
fetch::object_id::ObjectId,
kinds::activity::UndoType,
protocol::helpers::deserialize_one,
};
use serde::{Deserialize, Serialize};
use url::Url;

Expand All @@ -8,6 +12,7 @@ use url::Url;
pub struct UndoFollow {
pub(crate) actor: ObjectId<ApubPerson>,
/// Optional, for compatibility with platforms that always expect recipient field
#[serde(deserialize_with = "deserialize_one")]
pub(crate) to: Option<ObjectId<ApubPerson>>,
pub(crate) object: Follow,
#[serde(rename = "type")]
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/protocol/objects/chat_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct ChatMessage {
pub(crate) id: ObjectId<ApubPrivateMessage>,
pub(crate) attributed_to: ObjectId<ApubPerson>,
#[serde(deserialize_with = "deserialize_one")]
pub(crate) to: [ObjectId<ApubPerson>; 1],
pub(crate) to: ObjectId<ApubPerson>,
pub(crate) content: String,

pub(crate) media_type: Option<MediaTypeHtml>,
Expand Down

0 comments on commit ab6f766

Please sign in to comment.