mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-03 17:14:03 +00:00 
			
		
		
		
	Return user account image
This commit is contained in:
		@@ -4,6 +4,10 @@
 | 
			
		||||
use serde::Serialize;
 | 
			
		||||
 | 
			
		||||
use crate::data::user::{User, UserPageStatus, UserID};
 | 
			
		||||
use crate::helpers::friends_helper;
 | 
			
		||||
use crate::data::error::ResultBoxError;
 | 
			
		||||
use crate::utils::user_data_utils::user_data_url;
 | 
			
		||||
use crate::data::user::AccountImageVisibility::{EVERYONE, COMUNIC_USERS};
 | 
			
		||||
 | 
			
		||||
#[derive(Serialize)]
 | 
			
		||||
#[allow(non_snake_case)]
 | 
			
		||||
@@ -20,20 +24,40 @@ pub struct APIUserInfo {
 | 
			
		||||
impl APIUserInfo {
 | 
			
		||||
    /// Construct a new API user instance. Note: `user_id` is the ID of the user who makes the
 | 
			
		||||
    /// requests, not the user whose we return information about!
 | 
			
		||||
    pub fn new(user_id: Option<UserID>, info: &User) -> APIUserInfo {
 | 
			
		||||
        APIUserInfo {
 | 
			
		||||
    pub fn new(user_id: Option<UserID>, info: &User) -> ResultBoxError<APIUserInfo> {
 | 
			
		||||
        Ok(APIUserInfo {
 | 
			
		||||
            userID: info.id,
 | 
			
		||||
            firstName: info.first_name.to_string(),
 | 
			
		||||
            lastName: info.last_name.to_string(),
 | 
			
		||||
            publicPage: info.status != UserPageStatus::PRIVATE,
 | 
			
		||||
            openPage: info.status == UserPageStatus::OPEN,
 | 
			
		||||
            virtualDirectory: info.virtual_directory.clone().unwrap_or(String::new()),
 | 
			
		||||
            accountImage: APIUserInfo::get_account_image_url(user_id, info),
 | 
			
		||||
        }
 | 
			
		||||
            accountImage: APIUserInfo::get_account_image_url(user_id, info)?,
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Get the URL of a specific user account image
 | 
			
		||||
    pub fn get_account_image_url(user_id: Option<UserID>, user: &User) -> String {
 | 
			
		||||
        "do it".to_string()
 | 
			
		||||
    pub fn get_account_image_url(user_id: Option<UserID>, user: &User) -> ResultBoxError<String> {
 | 
			
		||||
        if !user.has_account_image() {
 | 
			
		||||
            return Ok(User::default_account_image_url());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let user_account_image = Ok(user_data_url(user.account_image_path.as_ref().unwrap()));
 | 
			
		||||
 | 
			
		||||
        if user.account_image_visibility == EVERYONE || user_id == Some(user.id) {
 | 
			
		||||
            return user_account_image;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if user_id.is_none() { // User is not signed in
 | 
			
		||||
            return Ok(User::error_account_image_url());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if user.account_image_visibility == COMUNIC_USERS ||
 | 
			
		||||
            friends_helper::are_friend(user_id.unwrap(), user.id)? {
 | 
			
		||||
            return user_account_image;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        Ok(User::error_account_image_url())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user