Skip to content

Commit

Permalink
Add to field in follow activities for better compatibility (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Apr 24, 2023
1 parent a2fb4b8 commit 5a0621b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/apub/assets/lemmy/activities/following/accept.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"actor": "http://enterprise.lemmy.ml/c/main",
"to": "http://ds9.lemmy.ml/u/lemmy_alpha",
"object": {
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": "http://enterprise.lemmy.ml/c/main",
"object": "http://enterprise.lemmy.ml/c/main",
"type": "Follow",
"id": "http://ds9.lemmy.ml/activities/follow/6abcd50b-b8ca-4952-86b0-a6dd8cc12866"
Expand Down
1 change: 1 addition & 0 deletions crates/apub/assets/lemmy/activities/following/follow.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": "http://enterprise.lemmy.ml/c/main",
"object": "http://enterprise.lemmy.ml/c/main",
"type": "Follow",
"id": "http://ds9.lemmy.ml/activities/follow/6abcd50b-b8ca-4952-86b0-a6dd8cc12866"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": "http://enterprise.lemmy.ml/c/main",
"object": {
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": "http://enterprise.lemmy.ml/c/main",
"object": "http://enterprise.lemmy.ml/c/main",
"type": "Follow",
"id": "http://ds9.lemmy.ml/activities/follow/dc2f1bc5-f3a0-4daa-a46b-428cbfbd023c"
Expand Down
4 changes: 4 additions & 0 deletions crates/apub/src/activities/following/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl AcceptFollow {
let person = follow.actor.clone().dereference(context).await?;
let accept = AcceptFollow {
actor: user_or_community.id().into(),
to: Some(person.id().into()),
object: follow,
kind: AcceptType::Accept,
id: generate_activity_id(
Expand Down Expand Up @@ -64,6 +65,9 @@ impl ActivityHandler for AcceptFollow {
async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
verify_urls_match(self.actor.inner(), self.object.object.inner())?;
self.object.verify(context).await?;
if let Some(to) = &self.to {
verify_urls_match(to.inner(), self.object.actor.inner())?;
}
Ok(())
}

Expand Down
5 changes: 5 additions & 0 deletions crates/apub/src/activities/following/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
use activitypub_federation::{
config::Data,
kinds::activity::FollowType,
protocol::verification::verify_urls_match,
traits::{ActivityHandler, Actor},
};
use lemmy_api_common::{
Expand All @@ -44,6 +45,7 @@ impl Follow {
Ok(Follow {
actor: actor.id().into(),
object: community.id().into(),
to: Some(community.id().into()),
kind: FollowType::Follow,
id: generate_activity_id(
FollowType::Follow,
Expand Down Expand Up @@ -93,6 +95,9 @@ impl ActivityHandler for Follow {
if let UserOrCommunity::Community(c) = object {
verify_person_in_community(&self.actor, &c, context).await?;
}
if let Some(to) = &self.to {
verify_urls_match(to.inner(), self.object.inner())?;
}
Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions crates/apub/src/activities/following/undo_follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl UndoFollow {
let object = Follow::new(actor, community, context)?;
let undo = UndoFollow {
actor: actor.id().into(),
to: Some(community.id().into()),
object,
kind: UndoType::Undo,
id: generate_activity_id(
Expand Down Expand Up @@ -62,6 +63,9 @@ impl ActivityHandler for UndoFollow {
verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
verify_person(&self.actor, context).await?;
self.object.verify(context).await?;
if let Some(to) = &self.to {
verify_urls_match(to.inner(), self.object.object.inner())?;
}
Ok(())
}

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
@@ -1,4 +1,7 @@
use crate::{objects::community::ApubCommunity, protocol::activities::following::follow::Follow};
use crate::{
objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::follow::Follow,
};
use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::AcceptType};
use serde::{Deserialize, Serialize};
use url::Url;
Expand All @@ -7,6 +10,8 @@ use url::Url;
#[serde(rename_all = "camelCase")]
pub struct AcceptFollow {
pub(crate) actor: ObjectId<ApubCommunity>,
/// Optional, for compatibility with platforms that always expect recipient field
pub(crate) to: Option<ObjectId<ApubPerson>>,
pub(crate) object: Follow,
#[serde(rename = "type")]
pub(crate) kind: AcceptType,
Expand Down
2 changes: 2 additions & 0 deletions crates/apub/src/protocol/activities/following/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use url::Url;
#[serde(rename_all = "camelCase")]
pub struct Follow {
pub(crate) actor: ObjectId<ApubPerson>,
/// Optional, for compatibility with platforms that always expect recipient field
pub(crate) to: Option<ObjectId<UserOrCommunity>>,
pub(crate) object: ObjectId<UserOrCommunity>,
#[serde(rename = "type")]
pub(crate) kind: FollowType,
Expand Down
2 changes: 2 additions & 0 deletions crates/apub/src/protocol/activities/following/undo_follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use url::Url;
#[serde(rename_all = "camelCase")]
pub struct UndoFollow {
pub(crate) actor: ObjectId<ApubPerson>,
/// Optional, for compatibility with platforms that always expect recipient field
pub(crate) to: Option<ObjectId<ApubPerson>>,
pub(crate) object: Follow,
#[serde(rename = "type")]
pub(crate) kind: UndoType,
Expand Down

0 comments on commit 5a0621b

Please sign in to comment.