Fix handling of follows addressed to single value (#2920)

* Fix handling of follows addressed to single value

* Switch to deserialize_skip_error for Follow to

* Also use deserialize_skip_error for AcceptFollow and UndoFollow

* actually import deserialize_skip_error
This commit is contained in:
vpzomtrrfrt 2023-06-06 16:33:38 -06:00 committed by GitHub
parent 3565ad984a
commit 09099e7b90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 3 deletions

View file

@ -0,0 +1,8 @@
{
"actor": "https://dev.narwhal.city/users/1",
"object": "https://beehaw.org/c/foss",
"to": "https://beehaw.org/c/foss",
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://dev.narwhal.city/communities/90/followers/1",
"type": "Follow"
}

View file

@ -2,7 +2,11 @@ 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,
protocol::helpers::deserialize_skip_error,
};
use serde::{Deserialize, Serialize};
use url::Url;
@ -11,6 +15,7 @@ use url::Url;
pub struct AcceptFollow {
pub(crate) actor: ObjectId<ApubCommunity>,
/// Optional, for compatibility with platforms that always expect recipient field
#[serde(deserialize_with = "deserialize_skip_error", default)]
pub(crate) to: Option<[ObjectId<ApubPerson>; 1]>,
pub(crate) object: Follow,
#[serde(rename = "type")]

View file

@ -1,5 +1,9 @@
use crate::{fetcher::user_or_community::UserOrCommunity, objects::person::ApubPerson};
use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::FollowType};
use activitypub_federation::{
fetch::object_id::ObjectId,
kinds::activity::FollowType,
protocol::helpers::deserialize_skip_error,
};
use serde::{Deserialize, Serialize};
use url::Url;
@ -8,6 +12,7 @@ use url::Url;
pub struct Follow {
pub(crate) actor: ObjectId<ApubPerson>,
/// Optional, for compatibility with platforms that always expect recipient field
#[serde(deserialize_with = "deserialize_skip_error", default)]
pub(crate) to: Option<[ObjectId<UserOrCommunity>; 1]>,
pub(crate) object: ObjectId<UserOrCommunity>,
#[serde(rename = "type")]

View file

@ -1,5 +1,9 @@
use crate::{objects::person::ApubPerson, protocol::activities::following::follow::Follow};
use activitypub_federation::{fetch::object_id::ObjectId, kinds::activity::UndoType};
use activitypub_federation::{
fetch::object_id::ObjectId,
kinds::activity::UndoType,
protocol::helpers::deserialize_skip_error,
};
use serde::{Deserialize, Serialize};
use url::Url;
@ -8,6 +12,7 @@ use url::Url;
pub struct UndoFollow {
pub(crate) actor: ObjectId<ApubPerson>,
/// Optional, for compatibility with platforms that always expect recipient field
#[serde(deserialize_with = "deserialize_skip_error", default)]
pub(crate) to: Option<[ObjectId<ApubPerson>; 1]>,
pub(crate) object: Follow,
#[serde(rename = "type")]

View file

@ -51,6 +51,7 @@ mod tests {
#[test]
fn test_parse_lotide_activities() {
test_json::<Follow>("assets/lotide/activities/follow.json").unwrap();
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page.json").unwrap();
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page_image.json").unwrap();
test_json::<CreateOrUpdateNote>("assets/lotide/activities/create_note_reply.json").unwrap();