Remove to field from follow activities

This commit is contained in:
Felix Ableitner 2021-11-16 17:27:43 +01:00
parent 20cddf5e81
commit 3249060f67
9 changed files with 21 additions and 38 deletions

View file

@ -1,13 +1,7 @@
{
"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,8 +1,5 @@
{
"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,13 +1,7 @@
{
"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

@ -28,7 +28,6 @@ impl AcceptFollowCommunity {
.await?;
let accept = AcceptFollowCommunity {
actor: ObjectId::new(community.actor_id()),
to: [ObjectId::new(person.actor_id())],
object: follow,
kind: AcceptType::Accept,
id: generate_activity_id(
@ -52,8 +51,7 @@ impl ActivityHandler for AcceptFollowCommunity {
request_counter: &mut i32,
) -> Result<(), LemmyError> {
verify_activity(&self.id, self.actor.inner(), &context.settings())?;
verify_urls_match(self.to[0].inner(), self.object.actor.inner())?;
verify_urls_match(self.actor.inner(), self.object.to[0].inner())?;
verify_urls_match(self.actor.inner(), self.object.object.inner())?;
self.object.verify(context, request_counter).await?;
Ok(())
}
@ -63,11 +61,15 @@ impl ActivityHandler for AcceptFollowCommunity {
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let actor = self.actor.dereference(context, request_counter).await?;
let to = self.to[0].dereference(context, request_counter).await?;
let person = self.actor.dereference(context, request_counter).await?;
let community = self
.object
.actor
.dereference(context, request_counter)
.await?;
// This will throw an error if no follow was requested
blocking(context.pool(), move |conn| {
CommunityFollower::follow_accepted(conn, actor.id, to.id)
CommunityFollower::follow_accepted(conn, person.id, community.id)
})
.await??;

View file

@ -15,7 +15,6 @@ use lemmy_apub_lib::{
data::Data,
object_id::ObjectId,
traits::{ActivityHandler, ActorType},
verify::verify_urls_match,
};
use lemmy_db_schema::{
source::community::{CommunityFollower, CommunityFollowerForm},
@ -32,7 +31,6 @@ impl FollowCommunity {
) -> Result<FollowCommunity, LemmyError> {
Ok(FollowCommunity {
actor: ObjectId::new(actor.actor_id()),
to: [ObjectId::new(community.actor_id())],
object: ObjectId::new(community.actor_id()),
kind: FollowType::Follow,
id: generate_activity_id(
@ -72,9 +70,8 @@ impl ActivityHandler for FollowCommunity {
request_counter: &mut i32,
) -> Result<(), LemmyError> {
verify_activity(&self.id, self.actor.inner(), &context.settings())?;
verify_urls_match(self.to[0].inner(), self.object.inner())?;
verify_person(&self.actor, context, request_counter).await?;
let community = self.to[0].dereference(context, request_counter).await?;
let community = self.object.dereference(context, request_counter).await?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
Ok(())
}
@ -84,11 +81,11 @@ impl ActivityHandler for FollowCommunity {
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let actor = self.actor.dereference(context, request_counter).await?;
let community = self.to[0].dereference(context, request_counter).await?;
let person = self.actor.dereference(context, request_counter).await?;
let community = self.object.dereference(context, request_counter).await?;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
person_id: actor.id,
person_id: person.id,
pending: false,
};

View file

@ -27,7 +27,6 @@ impl UndoFollowCommunity {
let object = FollowCommunity::new(actor, community, context)?;
let undo = UndoFollowCommunity {
actor: ObjectId::new(actor.actor_id()),
to: [ObjectId::new(community.actor_id())],
object,
kind: UndoType::Undo,
id: generate_activity_id(
@ -50,7 +49,6 @@ impl ActivityHandler for UndoFollowCommunity {
request_counter: &mut i32,
) -> Result<(), LemmyError> {
verify_activity(&self.id, self.actor.inner(), &context.settings())?;
verify_urls_match(self.to[0].inner(), self.object.object.inner())?;
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?;
@ -62,12 +60,16 @@ impl ActivityHandler for UndoFollowCommunity {
context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let actor = self.actor.dereference(context, request_counter).await?;
let community = self.to[0].dereference(context, request_counter).await?;
let person = self.actor.dereference(context, request_counter).await?;
let community = self
.object
.object
.dereference(context, request_counter)
.await?;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
person_id: actor.id,
person_id: person.id,
pending: false,
};

View file

@ -1,5 +1,5 @@
use crate::{
objects::{community::ApubCommunity, person::ApubPerson},
objects::community::ApubCommunity,
protocol::activities::following::follow::FollowCommunity,
};
use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed};
@ -11,7 +11,6 @@ use url::Url;
#[serde(rename_all = "camelCase")]
pub struct AcceptFollowCommunity {
pub(crate) actor: ObjectId<ApubCommunity>,
pub(crate) to: [ObjectId<ApubPerson>; 1],
pub(crate) object: FollowCommunity,
#[serde(rename = "type")]
pub(crate) kind: AcceptType,

View file

@ -8,7 +8,6 @@ use url::Url;
#[serde(rename_all = "camelCase")]
pub struct FollowCommunity {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubCommunity>; 1],
pub(crate) object: ObjectId<ApubCommunity>,
#[serde(rename = "type")]
pub(crate) kind: FollowType,

View file

@ -1,5 +1,5 @@
use crate::{
objects::{community::ApubCommunity, person::ApubPerson},
objects::person::ApubPerson,
protocol::activities::following::follow::FollowCommunity,
};
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
@ -11,7 +11,6 @@ use url::Url;
#[serde(rename_all = "camelCase")]
pub struct UndoFollowCommunity {
pub(crate) actor: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubCommunity>; 1],
pub(crate) object: FollowCommunity,
#[serde(rename = "type")]
pub(crate) kind: UndoType,