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

@ -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(
@ -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[0].inner(), self.object.actor.inner())?;
}
Ok(())
}

View file

@ -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::{
@ -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,
@ -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[0].inner(), self.object.inner())?;
}
Ok(())
}

View file

@ -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(
@ -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[0].inner(), self.object.object.inner())?;
}
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 serde::{Deserialize, Serialize};
use url::Url;
@ -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>; 1]>,
pub(crate) object: Follow,
#[serde(rename = "type")]
pub(crate) kind: AcceptType,

View file

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

View file

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