mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-26 05:28:50 +00:00
Add new user information
This commit is contained in:
parent
a4bdc89be2
commit
b5d2410413
@ -250,7 +250,7 @@ CREATE TABLE `utilisateurs` (
|
||||
`delete_likes_after` int DEFAULT '0',
|
||||
`allow_notif_conv` int DEFAULT '1',
|
||||
`allow_notif_sound` int DEFAULT '1',
|
||||
`is_email_visible` int DEFAULT '0',
|
||||
`is_email_public` int DEFAULT '0',
|
||||
`location` varchar(45) DEFAULT NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
|
||||
|
@ -1,4 +1,4 @@
|
||||
-- Nothing yet
|
||||
ALTER TABLE `utilisateurs`
|
||||
ADD COLUMN `is_email_visible` INT NULL DEFAULT 0 AFTER `allow_notif_sound`,
|
||||
ADD COLUMN `is_email_public` INT NULL DEFAULT 0 AFTER `allow_notif_sound`,
|
||||
ADD COLUMN `location` VARCHAR(45) NULL AFTER `is_email_visible`;
|
||||
|
@ -13,7 +13,7 @@ use crate::api_data::friend_api::FriendAPI;
|
||||
use crate::api_data::group_api::GroupApi;
|
||||
use crate::api_data::post_api::PostAPI;
|
||||
use crate::api_data::survey_response_api::SurveyResponseAPI;
|
||||
use crate::api_data::user_info::APIUserInfo;
|
||||
use crate::api_data::user_info::{APIUserInfo, APIAdvancedInfo};
|
||||
use crate::api_data::user_like_api::UserLikeAPI;
|
||||
use crate::data::account_export::AccountExport;
|
||||
use crate::data::error::ResultBoxError;
|
||||
@ -26,7 +26,7 @@ use crate::helpers::user_helper;
|
||||
#[allow(non_snake_case)]
|
||||
pub struct AccountExportAPI {
|
||||
userID: u64,
|
||||
advanced_info: APIUserInfo,
|
||||
advanced_info: APIAdvancedInfo,
|
||||
posts: Vec<PostAPI>,
|
||||
comments: Vec<CommentAPI>,
|
||||
likes: Vec<UserLikeAPI>,
|
||||
|
@ -22,17 +22,17 @@ pub struct APIUserInfo {
|
||||
virtualDirectory: String,
|
||||
accountImage: String,
|
||||
customEmojis: Vec<CustomEmojiAPI>,
|
||||
|
||||
#[serde(flatten)]
|
||||
advanced_info: Option<APIAdvancedInfo>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
struct APIAdvancedInfo {
|
||||
pub struct APIAdvancedInfo {
|
||||
friend_list_public: bool,
|
||||
personnalWebsite: String,
|
||||
publicNote: String,
|
||||
location: Option<String>,
|
||||
is_email_public: bool,
|
||||
email_address: Option<String>,
|
||||
noCommentOnHisPage: bool,
|
||||
allowPostFromFriendOnHisPage: bool,
|
||||
account_creation_time: u64,
|
||||
@ -41,6 +41,9 @@ struct APIAdvancedInfo {
|
||||
pageLikes: usize,
|
||||
user_like_page: bool,
|
||||
can_post_texts: bool,
|
||||
|
||||
#[serde(flatten)]
|
||||
base_info: APIUserInfo,
|
||||
}
|
||||
|
||||
impl APIUserInfo {
|
||||
@ -59,13 +62,12 @@ impl APIUserInfo {
|
||||
.iter()
|
||||
.map(|f| CustomEmojiAPI::new(f))
|
||||
.collect(),
|
||||
advanced_info: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get advanced user information
|
||||
pub fn new_advanced_info(user_id: &Option<UserID>, info: &User) -> ResultBoxError<APIUserInfo> {
|
||||
let mut user = APIUserInfo::new(&user_id, info)?;
|
||||
pub fn new_advanced_info(user_id: &Option<UserID>, info: &User) -> ResultBoxError<APIAdvancedInfo> {
|
||||
let user = APIUserInfo::new(&user_id, info)?;
|
||||
let curr_user_id = user_id.clone().unwrap_or(UserID::new(0));
|
||||
let signed_in = user_id.is_some();
|
||||
|
||||
@ -79,10 +81,17 @@ impl APIUserInfo {
|
||||
} else { false };
|
||||
|
||||
// Set advanced user information
|
||||
user.advanced_info = Some(APIAdvancedInfo {
|
||||
Ok(APIAdvancedInfo {
|
||||
base_info: user,
|
||||
friend_list_public: info.public_friends_list,
|
||||
personnalWebsite: info.personal_website.clone().unwrap_or(String::new()),
|
||||
publicNote: info.public_note.clone().unwrap_or(String::new()),
|
||||
location: info.location.clone(),
|
||||
is_email_public: info.is_email_public,
|
||||
email_address: match info.is_email_public {
|
||||
true => Some(info.email.clone()),
|
||||
false => None,
|
||||
},
|
||||
noCommentOnHisPage: info.block_comments_on_his_page,
|
||||
allowPostFromFriendOnHisPage: info.allow_posts_from_friends,
|
||||
account_creation_time: info.account_creation_time,
|
||||
@ -91,9 +100,7 @@ impl APIUserInfo {
|
||||
pageLikes: likes_helper::count(info.id.id(), LikeType::USER)?,
|
||||
user_like_page: likes_page,
|
||||
can_post_texts: user_helper::can_create_posts(&curr_user_id, &info.id)?,
|
||||
});
|
||||
|
||||
Ok(user)
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the URL of a specific user account image
|
||||
|
@ -115,13 +115,17 @@ pub struct User {
|
||||
pub account_image_path: Option<String>,
|
||||
pub account_image_visibility: AccountImageVisibility,
|
||||
pub public_friends_list: bool,
|
||||
pub is_email_public: bool,
|
||||
pub personal_website: Option<String>,
|
||||
pub public_note: Option<String>,
|
||||
pub location: Option<String>,
|
||||
pub block_comments_on_his_page: bool,
|
||||
pub allow_posts_from_friends: bool,
|
||||
pub account_creation_time: u64,
|
||||
pub allow_mails: bool,
|
||||
pub lang: String,
|
||||
|
||||
/// Security questions
|
||||
pub security_question_1: Option<String>,
|
||||
pub security_answer_1: Option<String>,
|
||||
pub security_question_2: Option<String>,
|
||||
|
@ -68,13 +68,17 @@ fn db_to_user(res: &database::RowResult) -> ResultBoxError<User> {
|
||||
account_image_path: res.get_optional_str("account_image_path")?,
|
||||
account_image_visibility,
|
||||
public_friends_list: res.get_legacy_bool("liste_amis_publique")?,
|
||||
is_email_public: res.get_legacy_bool("is_email_public")?,
|
||||
personal_website: res.get_optional_str("site_web")?,
|
||||
public_note: res.get_optional_str("public_note")?,
|
||||
location: res.get_optional_str("location")?,
|
||||
block_comments_on_his_page: res.get_legacy_bool("bloquecommentaire")?,
|
||||
allow_posts_from_friends: res.get_legacy_bool("autoriser_post_amis")?,
|
||||
account_creation_time: res.get_date_as_time("date_creation")?,
|
||||
allow_mails: res.get_legacy_bool("autorise_mail")?,
|
||||
lang: res.get_str("lang")?,
|
||||
|
||||
// Security questions
|
||||
security_question_1: res.get_optional_str("question1")?,
|
||||
security_answer_1: res.get_optional_str("reponse1")?,
|
||||
security_question_2: res.get_optional_str("question2")?,
|
||||
|
Loading…
Reference in New Issue
Block a user