Create type for deserializing Delete() activities
This commit is contained in:
parent
73e0b10a10
commit
bb033e11df
1 changed files with 13 additions and 7 deletions
|
@ -1,9 +1,9 @@
|
||||||
|
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,
|
receiver::deserialize_into_object_id,
|
||||||
receiver::find_object_id,
|
|
||||||
vocabulary::{NOTE, PERSON},
|
vocabulary::{NOTE, PERSON},
|
||||||
};
|
};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
@ -19,19 +19,25 @@ use crate::models::profiles::queries::{
|
||||||
};
|
};
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Delete {
|
||||||
|
actor: String,
|
||||||
|
#[serde(deserialize_with = "deserialize_into_object_id")]
|
||||||
|
object: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn handle_delete(
|
pub async fn handle_delete(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
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: Delete = serde_json::from_value(activity)
|
||||||
.map_err(|_| ValidationError("unexpected activity structure"))?;
|
.map_err(|_| ValidationError("unexpected activity structure"))?;
|
||||||
let object_id = find_object_id(&activity.object)?;
|
if activity.object == activity.actor {
|
||||||
if object_id == activity.actor {
|
|
||||||
// Self-delete
|
// Self-delete
|
||||||
let profile = match get_profile_by_remote_actor_id(
|
let profile = match get_profile_by_remote_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
&object_id,
|
&activity.object,
|
||||||
).await {
|
).await {
|
||||||
Ok(profile) => profile,
|
Ok(profile) => profile,
|
||||||
// Ignore Delete(Person) if profile is not found
|
// Ignore Delete(Person) if profile is not found
|
||||||
|
@ -48,7 +54,7 @@ pub async fn handle_delete(
|
||||||
};
|
};
|
||||||
let post = match get_post_by_remote_object_id(
|
let post = match get_post_by_remote_object_id(
|
||||||
db_client,
|
db_client,
|
||||||
&object_id,
|
&activity.object,
|
||||||
).await {
|
).await {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
// Ignore Delete(Note) if post is not found
|
// Ignore Delete(Note) if post is not found
|
||||||
|
|
Loading…
Reference in a new issue