Create type for deserializing Undo() activities and remove Activity type

This commit is contained in:
silverpill 2022-12-10 01:00:31 +00:00
parent bb033e11df
commit 50b8ad9de4
2 changed files with 9 additions and 18 deletions

View file

@ -60,18 +60,3 @@ pub struct Object {
pub updated: Option<DateTime<Utc>>,
pub url: Option<Value>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Activity {
pub id: String,
#[serde(rename = "type")]
pub activity_type: String,
pub actor: String,
pub object: Value,
pub target: Option<Value>,
pub to: Option<Value>,
pub cc: Option<Value>,
}

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use serde_json::Value;
use tokio_postgres::GenericClient;
use crate::activitypub::{
activity::Activity,
identifiers::parse_local_actor_id,
receiver::find_object_id,
vocabulary::{ANNOUNCE, FOLLOW, LIKE},
@ -27,10 +27,16 @@ use crate::models::{
};
use super::HandlerResult;
#[derive(Deserialize)]
struct Undo {
actor: String,
object: Value,
}
async fn handle_undo_follow(
config: &Config,
db_client: &mut impl GenericClient,
activity: Activity,
activity: Undo,
) -> HandlerResult {
let source_profile = get_profile_by_remote_actor_id(
db_client,
@ -57,7 +63,7 @@ pub async fn handle_undo(
db_client: &mut impl GenericClient,
activity: Value,
) -> HandlerResult {
let activity: Activity = serde_json::from_value(activity)
let activity: Undo = serde_json::from_value(activity)
.map_err(|_| ValidationError("unexpected activity structure"))?;
if let Some(FOLLOW) = activity.object["type"].as_str() {
// Object type is currently required for processing Undo(Follow)