Update actor JSON object in database when receiving Update(Person) activity
This commit is contained in:
parent
5b0a9ff931
commit
a9a99d7172
6 changed files with 28 additions and 6 deletions
|
@ -150,7 +150,7 @@ pub async fn fetch_profile_by_actor_id(
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
extra_fields,
|
extra_fields,
|
||||||
actor: Some(actor_value),
|
actor_json: Some(actor_value),
|
||||||
};
|
};
|
||||||
Ok(profile_data)
|
Ok(profile_data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -536,12 +536,29 @@ pub async fn receive_activity(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(UPDATE, PERSON) => {
|
(UPDATE, PERSON) => {
|
||||||
|
let actor_value = activity.object.clone();
|
||||||
let actor: Actor = serde_json::from_value(activity.object)
|
let actor: Actor = serde_json::from_value(activity.object)
|
||||||
.map_err(|_| ValidationError("invalid actor data"))?;
|
.map_err(|_| ValidationError("invalid actor data"))?;
|
||||||
let profile = get_profile_by_actor_id(db_client, &actor.id).await?;
|
let profile = get_profile_by_actor_id(db_client, &actor.id).await?;
|
||||||
let (avatar, banner) = fetch_avatar_and_banner(&actor, &config.media_dir()).await
|
let (avatar, banner) = fetch_avatar_and_banner(&actor, &config.media_dir()).await
|
||||||
.map_err(|_| ValidationError("failed to fetch image"))?;
|
.map_err(|_| ValidationError("failed to fetch image"))?;
|
||||||
let extra_fields = actor.extra_fields();
|
let extra_fields = actor.extra_fields();
|
||||||
|
let actor_old = profile.remote_actor()
|
||||||
|
.map_err(|_| HttpError::InternalError)?.unwrap();
|
||||||
|
if actor_old.id != actor.id {
|
||||||
|
log::warn!(
|
||||||
|
"actor ID changed from {} to {}",
|
||||||
|
actor_old.id,
|
||||||
|
actor.id,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
if actor_old.public_key.public_key_pem != actor.public_key.public_key_pem {
|
||||||
|
log::warn!(
|
||||||
|
"actor public key changed from {} to {}",
|
||||||
|
actor_old.public_key.public_key_pem,
|
||||||
|
actor.public_key.public_key_pem,
|
||||||
|
);
|
||||||
|
};
|
||||||
let mut profile_data = ProfileUpdateData {
|
let mut profile_data = ProfileUpdateData {
|
||||||
display_name: actor.name,
|
display_name: actor.name,
|
||||||
bio: actor.summary.clone(),
|
bio: actor.summary.clone(),
|
||||||
|
@ -549,6 +566,7 @@ pub async fn receive_activity(
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
extra_fields,
|
extra_fields,
|
||||||
|
actor_json: Some(actor_value),
|
||||||
};
|
};
|
||||||
profile_data.clean()?;
|
profile_data.clean()?;
|
||||||
update_profile(db_client, &profile.id, profile_data).await?;
|
update_profile(db_client, &profile.id, profile_data).await?;
|
||||||
|
|
|
@ -168,6 +168,7 @@ impl AccountUpdateData {
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
extra_fields,
|
extra_fields,
|
||||||
|
actor_json: None,
|
||||||
};
|
};
|
||||||
Ok(profile_data)
|
Ok(profile_data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub async fn create_profile(
|
||||||
&profile_data.avatar,
|
&profile_data.avatar,
|
||||||
&profile_data.banner,
|
&profile_data.banner,
|
||||||
&extra_fields,
|
&extra_fields,
|
||||||
&profile_data.actor,
|
&profile_data.actor_json,
|
||||||
],
|
],
|
||||||
).await.map_err(catch_unique_violation("profile"))?;
|
).await.map_err(catch_unique_violation("profile"))?;
|
||||||
let profile = row.try_get("actor_profile")?;
|
let profile = row.try_get("actor_profile")?;
|
||||||
|
@ -64,8 +64,9 @@ pub async fn update_profile(
|
||||||
bio_source = $3,
|
bio_source = $3,
|
||||||
avatar_file_name = $4,
|
avatar_file_name = $4,
|
||||||
banner_file_name = $5,
|
banner_file_name = $5,
|
||||||
extra_fields = $6
|
extra_fields = $6,
|
||||||
WHERE id = $7
|
actor_json = $7
|
||||||
|
WHERE id = $8
|
||||||
RETURNING actor_profile
|
RETURNING actor_profile
|
||||||
",
|
",
|
||||||
&[
|
&[
|
||||||
|
@ -75,6 +76,7 @@ pub async fn update_profile(
|
||||||
&data.avatar,
|
&data.avatar,
|
||||||
&data.banner,
|
&data.banner,
|
||||||
&ExtraFields(data.extra_fields),
|
&ExtraFields(data.extra_fields),
|
||||||
|
&data.actor_json,
|
||||||
&profile_id,
|
&profile_id,
|
||||||
],
|
],
|
||||||
).await?;
|
).await?;
|
||||||
|
|
|
@ -138,7 +138,7 @@ pub struct ProfileCreateData {
|
||||||
pub avatar: Option<String>,
|
pub avatar: Option<String>,
|
||||||
pub banner: Option<String>,
|
pub banner: Option<String>,
|
||||||
pub extra_fields: Vec<ExtraField>,
|
pub extra_fields: Vec<ExtraField>,
|
||||||
pub actor: Option<Value>,
|
pub actor_json: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProfileCreateData {
|
impl ProfileCreateData {
|
||||||
|
@ -156,6 +156,7 @@ pub struct ProfileUpdateData {
|
||||||
pub avatar: Option<String>,
|
pub avatar: Option<String>,
|
||||||
pub banner: Option<String>,
|
pub banner: Option<String>,
|
||||||
pub extra_fields: Vec<ExtraField>,
|
pub extra_fields: Vec<ExtraField>,
|
||||||
|
pub actor_json: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProfileUpdateData {
|
impl ProfileUpdateData {
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub async fn create_user(
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
extra_fields: vec![],
|
extra_fields: vec![],
|
||||||
actor: None,
|
actor_json: None,
|
||||||
};
|
};
|
||||||
let profile = create_profile(&transaction, &profile_data).await?;
|
let profile = create_profile(&transaction, &profile_data).await?;
|
||||||
// Create user
|
// Create user
|
||||||
|
|
Loading…
Reference in a new issue