Create unified handler for Update() activities
This commit is contained in:
parent
a3c3f97759
commit
648a217971
3 changed files with 39 additions and 11 deletions
|
@ -15,5 +15,6 @@ pub mod reject_follow;
|
||||||
pub mod remove;
|
pub mod remove;
|
||||||
pub mod undo;
|
pub mod undo;
|
||||||
pub mod undo_follow;
|
pub mod undo_follow;
|
||||||
pub mod update_note;
|
pub mod update;
|
||||||
|
mod update_note;
|
||||||
pub mod update_person;
|
pub mod update_person;
|
||||||
|
|
34
src/activitypub/handlers/update.rs
Normal file
34
src/activitypub/handlers/update.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use tokio_postgres::GenericClient;
|
||||||
|
|
||||||
|
use crate::activitypub::{
|
||||||
|
activity::{Activity, Object},
|
||||||
|
vocabulary::{NOTE, PERSON},
|
||||||
|
};
|
||||||
|
use crate::config::Config;
|
||||||
|
use crate::errors::ValidationError;
|
||||||
|
use super::HandlerResult;
|
||||||
|
use super::update_note::handle_update_note;
|
||||||
|
use super::update_person::handle_update_person;
|
||||||
|
|
||||||
|
pub async fn handle_update(
|
||||||
|
config: &Config,
|
||||||
|
db_client: &mut impl GenericClient,
|
||||||
|
activity: Activity,
|
||||||
|
) -> HandlerResult {
|
||||||
|
let object_type = activity.object["type"].as_str()
|
||||||
|
.ok_or(ValidationError("unknown object type"))?;
|
||||||
|
match object_type {
|
||||||
|
NOTE => {
|
||||||
|
let object: Object = serde_json::from_value(activity.object)
|
||||||
|
.map_err(|_| ValidationError("invalid object"))?;
|
||||||
|
handle_update_note(db_client, object).await
|
||||||
|
},
|
||||||
|
PERSON => {
|
||||||
|
handle_update_person(config, db_client, activity).await
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
log::warn!("unexpected object type {}", object_type);
|
||||||
|
Ok(None)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,8 +32,7 @@ use super::handlers::{
|
||||||
remove::handle_remove,
|
remove::handle_remove,
|
||||||
undo::handle_undo,
|
undo::handle_undo,
|
||||||
undo_follow::handle_undo_follow,
|
undo_follow::handle_undo_follow,
|
||||||
update_note::handle_update_note,
|
update::handle_update,
|
||||||
update_person::handle_update_person,
|
|
||||||
};
|
};
|
||||||
use super::vocabulary::*;
|
use super::vocabulary::*;
|
||||||
|
|
||||||
|
@ -264,15 +263,9 @@ pub async fn receive_activity(
|
||||||
require_actor_signature(&activity.actor, &signer_id)?;
|
require_actor_signature(&activity.actor, &signer_id)?;
|
||||||
handle_undo(db_client, activity).await?
|
handle_undo(db_client, activity).await?
|
||||||
},
|
},
|
||||||
(UPDATE, NOTE) => {
|
(UPDATE, _) => {
|
||||||
require_actor_signature(&activity.actor, &signer_id)?;
|
require_actor_signature(&activity.actor, &signer_id)?;
|
||||||
let object: Object = serde_json::from_value(activity.object)
|
handle_update(config, db_client, activity).await?
|
||||||
.map_err(|_| ValidationError("invalid object"))?;
|
|
||||||
handle_update_note(db_client, object).await?
|
|
||||||
},
|
|
||||||
(UPDATE, PERSON) => {
|
|
||||||
require_actor_signature(&activity.actor, &signer_id)?;
|
|
||||||
handle_update_person(config, db_client, activity).await?
|
|
||||||
},
|
},
|
||||||
(MOVE, _) => {
|
(MOVE, _) => {
|
||||||
require_actor_signature(&activity.actor, &signer_id)?;
|
require_actor_signature(&activity.actor, &signer_id)?;
|
||||||
|
|
Loading…
Reference in a new issue