Create type for deserializing Undo() activities and remove Activity type
This commit is contained in:
parent
bb033e11df
commit
50b8ad9de4
2 changed files with 9 additions and 18 deletions
|
@ -60,18 +60,3 @@ pub struct Object {
|
||||||
pub updated: Option<DateTime<Utc>>,
|
pub updated: Option<DateTime<Utc>>,
|
||||||
pub url: Option<Value>,
|
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>,
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
use serde::Deserialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tokio_postgres::GenericClient;
|
use tokio_postgres::GenericClient;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
activity::Activity,
|
|
||||||
identifiers::parse_local_actor_id,
|
identifiers::parse_local_actor_id,
|
||||||
receiver::find_object_id,
|
receiver::find_object_id,
|
||||||
vocabulary::{ANNOUNCE, FOLLOW, LIKE},
|
vocabulary::{ANNOUNCE, FOLLOW, LIKE},
|
||||||
|
@ -27,10 +27,16 @@ use crate::models::{
|
||||||
};
|
};
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Undo {
|
||||||
|
actor: String,
|
||||||
|
object: Value,
|
||||||
|
}
|
||||||
|
|
||||||
async fn handle_undo_follow(
|
async fn handle_undo_follow(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
activity: Activity,
|
activity: Undo,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let source_profile = get_profile_by_remote_actor_id(
|
let source_profile = get_profile_by_remote_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
|
@ -57,7 +63,7 @@ pub async fn handle_undo(
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
activity: Value,
|
activity: Value,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let activity: Activity = serde_json::from_value(activity)
|
let activity: Undo = serde_json::from_value(activity)
|
||||||
.map_err(|_| ValidationError("unexpected activity structure"))?;
|
.map_err(|_| ValidationError("unexpected activity structure"))?;
|
||||||
if let Some(FOLLOW) = activity.object["type"].as_str() {
|
if let Some(FOLLOW) = activity.object["type"].as_str() {
|
||||||
// Object type is currently required for processing Undo(Follow)
|
// Object type is currently required for processing Undo(Follow)
|
||||||
|
|
Loading…
Reference in a new issue