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

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

* fix tests
This commit is contained in:
Nutomic 2023-04-24 23:19:08 +02:00 committed by Felix Ableitner
parent 6bdfd5948b
commit 416fc062cd
10 changed files with 29 additions and 5 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -40,6 +40,7 @@ impl AcceptFollow {
.await?;
let accept = AcceptFollow {
actor: ObjectId::new(user_or_community.actor_id()),
to: Some([ObjectId::new(person.actor_id())]),
object: follow,
kind: AcceptType::Accept,
id: generate_activity_id(
@ -74,6 +75,9 @@ impl ActivityHandler for AcceptFollow {
) -> Result<(), LemmyError> {
verify_urls_match(self.actor.inner(), self.object.object.inner())?;
self.object.verify(context, request_counter).await?;
if let Some(to) = &self.to {
verify_urls_match(to[0].inner(), self.object.actor.inner())?;
}
Ok(())
}

View File

@ -20,6 +20,7 @@ use activitypub_federation::{
core::object_id::ObjectId,
data::Data,
traits::{ActivityHandler, Actor},
utils::verify_urls_match,
};
use activitystreams_kinds::activity::FollowType;
use lemmy_api_common::{
@ -46,6 +47,7 @@ impl Follow {
Ok(Follow {
actor: ObjectId::new(actor.actor_id()),
object: ObjectId::new(community.actor_id()),
to: Some([ObjectId::new(community.actor_id())]),
kind: FollowType::Follow,
id: generate_activity_id(
FollowType::Follow,
@ -102,6 +104,9 @@ impl ActivityHandler for Follow {
if let UserOrCommunity::Community(c) = object {
verify_person_in_community(&self.actor, &c, context, request_counter).await?;
}
if let Some(to) = &self.to {
verify_urls_match(to[0].inner(), self.object.inner())?;
}
Ok(())
}

View File

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

View File

@ -7,10 +7,7 @@ use actix_web::web::Data;
use lemmy_api_common::{
context::LemmyContext,
post::{GetPosts, GetPostsResponse},
utils::{
check_private_instance,
get_local_user_view_from_jwt_opt,
},
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
};
use lemmy_db_schema::{
source::{community::Community, local_site::LocalSite},

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::core::object_id::ObjectId;
use activitystreams_kinds::activity::AcceptType;
use serde::{Deserialize, Serialize};
@ -8,6 +11,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>; 1]>,
pub(crate) object: Follow,
#[serde(rename = "type")]
pub(crate) kind: AcceptType,

View File

@ -8,6 +8,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>; 1]>,
pub(crate) object: ObjectId<UserOrCommunity>,
#[serde(rename = "type")]
pub(crate) kind: FollowType,

View File

@ -8,6 +8,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>; 1]>,
pub(crate) object: Follow,
#[serde(rename = "type")]
pub(crate) kind: UndoType,