Add `to` field in follow activities for better compatibility (#2829)

* Add `to` field in follow activities for better compatibility (fixes #2744)

* fix tests
revert_multiarch_dockerfile
Nutomic 2023-04-24 23:19:08 +02:00 committed by GitHub
parent a2fb4b8cd0
commit a25faf3e97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 1 deletions

View File

@ -1,7 +1,9 @@
{ {
"actor": "http://enterprise.lemmy.ml/c/main", "actor": "http://enterprise.lemmy.ml/c/main",
"to": ["http://ds9.lemmy.ml/u/lemmy_alpha"],
"object": { "object": {
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha", "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": ["http://enterprise.lemmy.ml/c/main"],
"object": "http://enterprise.lemmy.ml/c/main", "object": "http://enterprise.lemmy.ml/c/main",
"type": "Follow", "type": "Follow",
"id": "http://ds9.lemmy.ml/activities/follow/6abcd50b-b8ca-4952-86b0-a6dd8cc12866" "id": "http://ds9.lemmy.ml/activities/follow/6abcd50b-b8ca-4952-86b0-a6dd8cc12866"

View File

@ -1,5 +1,6 @@
{ {
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha", "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": ["http://enterprise.lemmy.ml/c/main"],
"object": "http://enterprise.lemmy.ml/c/main", "object": "http://enterprise.lemmy.ml/c/main",
"type": "Follow", "type": "Follow",
"id": "http://ds9.lemmy.ml/activities/follow/6abcd50b-b8ca-4952-86b0-a6dd8cc12866" "id": "http://ds9.lemmy.ml/activities/follow/6abcd50b-b8ca-4952-86b0-a6dd8cc12866"

View File

@ -1,7 +1,9 @@
{ {
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha", "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": ["http://enterprise.lemmy.ml/c/main"],
"object": { "object": {
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha", "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": ["http://enterprise.lemmy.ml/c/main"],
"object": "http://enterprise.lemmy.ml/c/main", "object": "http://enterprise.lemmy.ml/c/main",
"type": "Follow", "type": "Follow",
"id": "http://ds9.lemmy.ml/activities/follow/dc2f1bc5-f3a0-4daa-a46b-428cbfbd023c" "id": "http://ds9.lemmy.ml/activities/follow/dc2f1bc5-f3a0-4daa-a46b-428cbfbd023c"

View File

@ -34,6 +34,7 @@ impl AcceptFollow {
let person = follow.actor.clone().dereference(context).await?; let person = follow.actor.clone().dereference(context).await?;
let accept = AcceptFollow { let accept = AcceptFollow {
actor: user_or_community.id().into(), actor: user_or_community.id().into(),
to: Some([person.id().into()]),
object: follow, object: follow,
kind: AcceptType::Accept, kind: AcceptType::Accept,
id: generate_activity_id( id: generate_activity_id(
@ -64,6 +65,9 @@ impl ActivityHandler for AcceptFollow {
async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> { async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
verify_urls_match(self.actor.inner(), self.object.object.inner())?; verify_urls_match(self.actor.inner(), self.object.object.inner())?;
self.object.verify(context).await?; self.object.verify(context).await?;
if let Some(to) = &self.to {
verify_urls_match(to[0].inner(), self.object.actor.inner())?;
}
Ok(()) Ok(())
} }

View File

@ -18,6 +18,7 @@ use crate::{
use activitypub_federation::{ use activitypub_federation::{
config::Data, config::Data,
kinds::activity::FollowType, kinds::activity::FollowType,
protocol::verification::verify_urls_match,
traits::{ActivityHandler, Actor}, traits::{ActivityHandler, Actor},
}; };
use lemmy_api_common::{ use lemmy_api_common::{
@ -44,6 +45,7 @@ impl Follow {
Ok(Follow { Ok(Follow {
actor: actor.id().into(), actor: actor.id().into(),
object: community.id().into(), object: community.id().into(),
to: Some([community.id().into()]),
kind: FollowType::Follow, kind: FollowType::Follow,
id: generate_activity_id( id: generate_activity_id(
FollowType::Follow, FollowType::Follow,
@ -93,6 +95,9 @@ impl ActivityHandler for Follow {
if let UserOrCommunity::Community(c) = object { if let UserOrCommunity::Community(c) = object {
verify_person_in_community(&self.actor, &c, context).await?; verify_person_in_community(&self.actor, &c, context).await?;
} }
if let Some(to) = &self.to {
verify_urls_match(to[0].inner(), self.object.inner())?;
}
Ok(()) Ok(())
} }

View File

@ -32,6 +32,7 @@ impl UndoFollow {
let object = Follow::new(actor, community, context)?; let object = Follow::new(actor, community, context)?;
let undo = UndoFollow { let undo = UndoFollow {
actor: actor.id().into(), actor: actor.id().into(),
to: Some([community.id().into()]),
object, object,
kind: UndoType::Undo, kind: UndoType::Undo,
id: generate_activity_id( id: generate_activity_id(
@ -62,6 +63,9 @@ impl ActivityHandler for UndoFollow {
verify_urls_match(self.actor.inner(), self.object.actor.inner())?; verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
verify_person(&self.actor, context).await?; verify_person(&self.actor, context).await?;
self.object.verify(context).await?; self.object.verify(context).await?;
if let Some(to) = &self.to {
verify_urls_match(to[0].inner(), self.object.object.inner())?;
}
Ok(()) Ok(())
} }

View File

@ -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 activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::AcceptType};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;
@ -7,6 +10,8 @@ use url::Url;
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct AcceptFollow { pub struct AcceptFollow {
pub(crate) actor: ObjectId<ApubCommunity>, pub(crate) actor: ObjectId<ApubCommunity>,
/// Optional, for compatibility with platforms that always expect recipient field
pub(crate) to: Option<[ObjectId<ApubPerson>; 1]>,
pub(crate) object: Follow, pub(crate) object: Follow,
#[serde(rename = "type")] #[serde(rename = "type")]
pub(crate) kind: AcceptType, pub(crate) kind: AcceptType,

View File

@ -7,6 +7,8 @@ use url::Url;
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Follow { pub struct Follow {
pub(crate) actor: ObjectId<ApubPerson>, pub(crate) actor: ObjectId<ApubPerson>,
/// Optional, for compatibility with platforms that always expect recipient field
pub(crate) to: Option<[ObjectId<UserOrCommunity>; 1]>,
pub(crate) object: ObjectId<UserOrCommunity>, pub(crate) object: ObjectId<UserOrCommunity>,
#[serde(rename = "type")] #[serde(rename = "type")]
pub(crate) kind: FollowType, pub(crate) kind: FollowType,

View File

@ -7,6 +7,8 @@ use url::Url;
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct UndoFollow { pub struct UndoFollow {
pub(crate) actor: ObjectId<ApubPerson>, pub(crate) actor: ObjectId<ApubPerson>,
/// Optional, for compatibility with platforms that always expect recipient field
pub(crate) to: Option<[ObjectId<ApubPerson>; 1]>,
pub(crate) object: Follow, pub(crate) object: Follow,
#[serde(rename = "type")] #[serde(rename = "type")]
pub(crate) kind: UndoType, pub(crate) kind: UndoType,