Refactor send_signed_update view

This commit is contained in:
silverpill 2022-11-26 01:00:42 +00:00
parent dd268634ef
commit fbcba1b99d
2 changed files with 17 additions and 16 deletions

View file

@ -89,13 +89,20 @@ pub async fn prepare_signed_update_person(
db_client: &impl GenericClient, db_client: &impl GenericClient,
instance: &Instance, instance: &Instance,
user: &User, user: &User,
activity: Value, internal_activity_id: Uuid,
) -> Result<OutgoingActivity<Value>, DatabaseError> { ) -> Result<OutgoingActivity<Value>, DatabaseError> {
let activity = build_update_person(
&instance.url(),
user,
Some(internal_activity_id),
).map_err(|_| ConversionError)?;
let activity_value = serde_json::to_value(activity)
.map_err(|_| ConversionError)?;
let recipients = get_update_person_recipients(db_client, &user.id).await?; let recipients = get_update_person_recipients(db_client, &user.id).await?;
Ok(OutgoingActivity { Ok(OutgoingActivity {
instance: instance.clone(), instance: instance.clone(),
sender: user.clone(), sender: user.clone(),
activity, activity: activity_value,
recipients, recipients,
}) })
} }

View file

@ -267,12 +267,13 @@ async fn send_signed_update(
if !current_user.profile.identity_proofs.any(&signer) { if !current_user.profile.identity_proofs.any(&signer) {
return Err(ValidationError("unknown signer").into()); return Err(ValidationError("unknown signer").into());
}; };
let activity = build_update_person( let mut outgoing_activity = prepare_signed_update_person(
&config.instance_url(), db_client,
&config.instance(),
&current_user, &current_user,
Some(data.internal_activity_id), data.internal_activity_id,
).map_err(|_| HttpError::InternalError)?; ).await.map_err(|_| HttpError::InternalError)?;
let canonical_json = canonicalize_object(&activity) let canonical_json = canonicalize_object(&outgoing_activity.activity)
.map_err(|_| HttpError::InternalError)?; .map_err(|_| HttpError::InternalError)?;
let proof = match signer { let proof = match signer {
Did::Key(signer) => { Did::Key(signer) => {
@ -290,17 +291,10 @@ async fn send_signed_update(
IntegrityProof::jcs_eip191(&signer, &signature_bin) IntegrityProof::jcs_eip191(&signer, &signature_bin)
}, },
}; };
let mut activity_value = serde_json::to_value(activity) add_integrity_proof(&mut outgoing_activity.activity, proof)
.map_err(|_| HttpError::InternalError)?;
add_integrity_proof(&mut activity_value, proof)
.map_err(|_| HttpError::InternalError)?; .map_err(|_| HttpError::InternalError)?;
prepare_signed_update_person( outgoing_activity.spawn_deliver();
db_client,
&config.instance(),
&current_user,
activity_value,
).await?.spawn_deliver();
let account = Account::from_user(current_user, &config.instance_url()); let account = Account::from_user(current_user, &config.instance_url());
Ok(HttpResponse::Ok().json(account)) Ok(HttpResponse::Ok().json(account))