Refactor AccountUpdateData.into_profile_data() method

This commit is contained in:
silverpill 2023-01-06 22:44:46 +00:00
parent 1663d22b19
commit f35e8d806f
3 changed files with 15 additions and 13 deletions

View file

@ -11,7 +11,6 @@ use crate::mastodon_api::uploads::{save_b64_file, UploadError};
use crate::models::profiles::types::{
DbActorProfile,
ExtraField,
IdentityProof,
PaymentOption,
ProfileUpdateData,
};
@ -248,10 +247,7 @@ fn process_b64_image_field_value(
impl AccountUpdateData {
pub fn into_profile_data(
self,
current_avatar: &Option<String>,
current_banner: &Option<String>,
current_identity_proofs: &[IdentityProof],
current_payment_options: &[PaymentOption],
profile: &DbActorProfile,
media_dir: &Path,
) -> Result<ProfileUpdateData, HttpError> {
let maybe_bio = if let Some(ref bio_source) = self.note {
@ -262,13 +258,17 @@ impl AccountUpdateData {
None
};
let avatar = process_b64_image_field_value(
self.avatar, current_avatar.clone(), media_dir,
self.avatar,
profile.avatar_file_name.clone(),
media_dir,
)?;
let banner = process_b64_image_field_value(
self.header, current_banner.clone(), media_dir,
self.header,
profile.banner_file_name.clone(),
media_dir,
)?;
let identity_proofs = current_identity_proofs.to_vec();
let payment_options = current_payment_options.to_vec();
let identity_proofs = profile.identity_proofs.inner().to_vec();
let payment_options = profile.payment_options.inner().to_vec();
let mut extra_fields = vec![];
for field_source in self.fields_attributes.unwrap_or(vec![]) {
let value = markdown_basic_to_html(&field_source.value)

View file

@ -222,10 +222,7 @@ async fn update_credentials(
let mut current_user = get_current_user(db_client, auth.token()).await?;
let mut profile_data = account_data.into_inner()
.into_profile_data(
&current_user.profile.avatar_file_name,
&current_user.profile.banner_file_name,
&current_user.profile.identity_proofs.into_inner(),
&current_user.profile.payment_options.into_inner(),
&current_user.profile,
&config.media_dir(),
)?;
profile_data.clean()?;

View file

@ -236,6 +236,11 @@ impl Serialize for PaymentOption {
pub struct PaymentOptions(pub Vec<PaymentOption>);
impl PaymentOptions {
pub fn inner(&self) -> &[PaymentOption] {
let Self(payment_options) = self;
payment_options
}
pub fn into_inner(self) -> Vec<PaymentOption> {
let Self(payment_options) = self;
payment_options