From a0f105090dc6771c6bf17cb2883507bce9f083c0 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 1 Jun 2020 09:19:29 +0200 Subject: [PATCH] Start to return advanced user info --- src/api_data/user_info.rs | 32 ++++++++++++++++++++++++++++++ src/controllers/user_controller.rs | 3 ++- src/data/user.rs | 6 ++++++ src/helpers/database.rs | 5 +++++ src/helpers/user_helper.rs | 6 ++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/api_data/user_info.rs b/src/api_data/user_info.rs index 45a4584..d35dd52 100644 --- a/src/api_data/user_info.rs +++ b/src/api_data/user_info.rs @@ -21,6 +21,20 @@ pub struct APIUserInfo { virtualDirectory: String, accountImage: String, customEmojis: Vec, + + #[serde(flatten)] + advanced_info: Option, +} + +#[derive(Serialize)] +#[allow(non_snake_case)] +struct APIAdvancedInfo { + friend_list_public: bool, + personnalWebsite: String, + publicNote: String, + noCommentOnHisPage: bool, + allowPostFromFriendOnHisPage: bool, + account_creation_time: u64 } impl APIUserInfo { @@ -39,9 +53,27 @@ impl APIUserInfo { .iter() .map(|f| CustomEmojiAPI::new(f)) .collect(), + advanced_info: None, }) } + /// Get advanced user information + pub fn new_advanced_info(user_id: Option, info: &User) -> ResultBoxError { + let mut user = APIUserInfo::new(user_id, info)?; + + // Set advanced user information + user.advanced_info = Some(APIAdvancedInfo { + 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()), + noCommentOnHisPage: info.block_comments_on_his_page, + allowPostFromFriendOnHisPage: info.allow_posts_from_friends, + account_creation_time: info.account_creation_time + }); + + Ok(user) + } + /// Get the URL of a specific user account image pub fn get_account_image_url(user_id: Option, user: &User) -> ResultBoxError { if !user.has_account_image() { diff --git a/src/controllers/user_controller.rs b/src/controllers/user_controller.rs index 2caa533..25bce28 100644 --- a/src/controllers/user_controller.rs +++ b/src/controllers/user_controller.rs @@ -54,5 +54,6 @@ pub fn get_advanced_info(request: &mut HttpRequestHandler) -> RequestResult { request.forbidden("You are not allowed to see this user page!".to_string())?; } - request.success("get user info") + let user = user_helper::find_user_by_id(user_id)?; + request.set_response(APIUserInfo::new_advanced_info(request.user_id_opt(), &user)?) } \ No newline at end of file diff --git a/src/data/user.rs b/src/data/user.rs index 411bb34..9eba984 100644 --- a/src/data/user.rs +++ b/src/data/user.rs @@ -32,6 +32,12 @@ pub struct User { pub virtual_directory: Option, pub account_image_path: Option, pub account_image_visibility: AccountImageVisibility, + pub public_friends_list: bool, + pub personal_website: Option, + pub public_note: Option, + pub block_comments_on_his_page: bool, + pub allow_posts_from_friends: bool, + pub account_creation_time: u64, } impl User { diff --git a/src/helpers/database.rs b/src/helpers/database.rs index 99dba3a..dcb296c 100644 --- a/src/helpers/database.rs +++ b/src/helpers/database.rs @@ -208,6 +208,11 @@ impl<'a> RowResult<'a> { })) } } + + /// Get legacy boolean value : 1 = true / 0 = false + pub fn get_legacy_bool(&self, name: &str) -> ResultBoxError { + Ok(self.get_int64(name)? == 1) + } } diff --git a/src/helpers/user_helper.rs b/src/helpers/user_helper.rs index c156dd2..7c793df 100644 --- a/src/helpers/user_helper.rs +++ b/src/helpers/user_helper.rs @@ -52,6 +52,12 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError { virtual_directory: res.get_optional_str("sous_repertoire")?, account_image_path: res.get_optional_str("account_image_path")?, account_image_visibility, + public_friends_list: res.get_legacy_bool("liste_amis_publique")?, + personal_website: res.get_optional_str("site_web")?, + public_note: res.get_optional_str("public_note")?, + block_comments_on_his_page: res.get_legacy_bool("bloquecommentaire")?, + allow_posts_from_friends: res.get_legacy_bool("autoriser_post_amis")?, + account_creation_time: 10,//TODO : parse date }) }) }