mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Start to return advanced user info
This commit is contained in:
parent
9915e9af23
commit
a0f105090d
@ -21,6 +21,20 @@ pub struct APIUserInfo {
|
||||
virtualDirectory: String,
|
||||
accountImage: String,
|
||||
customEmojis: Vec<CustomEmojiAPI>,
|
||||
|
||||
#[serde(flatten)]
|
||||
advanced_info: Option<APIAdvancedInfo>,
|
||||
}
|
||||
|
||||
#[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<UserID>, info: &User) -> ResultBoxError<APIUserInfo> {
|
||||
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<UserID>, user: &User) -> ResultBoxError<String> {
|
||||
if !user.has_account_image() {
|
||||
|
@ -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)?)
|
||||
}
|
@ -32,6 +32,12 @@ pub struct User {
|
||||
pub virtual_directory: Option<String>,
|
||||
pub account_image_path: Option<String>,
|
||||
pub account_image_visibility: AccountImageVisibility,
|
||||
pub public_friends_list: bool,
|
||||
pub personal_website: Option<String>,
|
||||
pub public_note: Option<String>,
|
||||
pub block_comments_on_his_page: bool,
|
||||
pub allow_posts_from_friends: bool,
|
||||
pub account_creation_time: u64,
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
@ -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<bool> {
|
||||
Ok(self.get_int64(name)? == 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,6 +52,12 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
|
||||
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
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user