mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Upgrade UserID to a structure
This commit is contained in:
@ -40,12 +40,12 @@ impl ConversationAPI {
|
||||
pub fn new(conv: &Conversation) -> ConversationAPI {
|
||||
ConversationAPI {
|
||||
ID: conv.id,
|
||||
ID_owner: conv.owner_id as u64,
|
||||
ID_owner: conv.owner_id.id(),
|
||||
last_active: conv.last_active,
|
||||
name: ConvName(conv.name.clone()),
|
||||
following: LegacyBool(conv.following),
|
||||
saw_last_message: LegacyBool(conv.saw_last_message),
|
||||
members: conv.members.iter().map(|x| x.clone() as u64).collect(),
|
||||
members: conv.members.iter().map(|x| x.id()).collect(),
|
||||
canEveryoneAddMembers: conv.can_everyone_add_members,
|
||||
|
||||
// TODO : update when call system is implemented
|
||||
|
@ -26,7 +26,7 @@ impl ConversationMessageAPI {
|
||||
ConversationMessageAPI {
|
||||
ID: msg.id,
|
||||
convID: msg.conv_id,
|
||||
ID_user: msg.user_id as u64,
|
||||
ID_user: msg.user_id.id(),
|
||||
time_insert: msg.time_sent,
|
||||
message: msg.message.clone().unwrap_or(String::new()),
|
||||
image_path: msg.image_path.as_ref().map(|f| user_data_url(f)),
|
||||
|
@ -6,13 +6,13 @@ use crate::data::user::UserID;
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct CurrentUserID {
|
||||
userID: i64
|
||||
userID: u64
|
||||
}
|
||||
|
||||
impl CurrentUserID {
|
||||
pub fn new(id: UserID) -> CurrentUserID {
|
||||
pub fn new(id: &UserID) -> CurrentUserID {
|
||||
CurrentUserID {
|
||||
userID: id
|
||||
userID: id.id()
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::custom_emoji::CustomEmoji;
|
||||
use crate::utils::user_data_utils::user_data_url;
|
||||
|
||||
@ -9,21 +10,19 @@ use crate::utils::user_data_utils::user_data_url;
|
||||
#[allow(non_snake_case)]
|
||||
pub struct CustomEmojiAPI {
|
||||
id: u64,
|
||||
userID: i64,
|
||||
userID: u64,
|
||||
shortcut: String,
|
||||
url: String
|
||||
url: String,
|
||||
}
|
||||
|
||||
impl CustomEmojiAPI {
|
||||
|
||||
/// Create a new Custom Emoji API entry
|
||||
pub fn new(custom_emoji: &CustomEmoji) -> CustomEmojiAPI {
|
||||
CustomEmojiAPI {
|
||||
id: custom_emoji.id,
|
||||
userID: custom_emoji.user_id,
|
||||
userID: custom_emoji.user_id.id(),
|
||||
shortcut: custom_emoji.shortcut.to_string(),
|
||||
url: user_data_url(&custom_emoji.path),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,7 @@ impl GlobalSearchResultAPI {
|
||||
match res {
|
||||
GlobalSearchResult::User(user_id) => GlobalSearchResultAPI {
|
||||
kind: "user".to_string(),
|
||||
id: user_id.clone() as u64,
|
||||
id: user_id.id(),
|
||||
},
|
||||
GlobalSearchResult::Group(group_id) => GlobalSearchResultAPI {
|
||||
kind: "group".to_string(),
|
||||
|
@ -19,7 +19,7 @@ impl UnreadConversationAPI {
|
||||
id: conv.id,
|
||||
conv_name: conv.name.clone().unwrap_or(String::new()),
|
||||
last_active: conv.last_active,
|
||||
userID: conv.user_id as u64,
|
||||
userID: conv.user_id.id(),
|
||||
message: conv.message.clone()
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ impl FindUserByVirtualDirectoryAPIResult {
|
||||
/// Construct a new `FindUserByVirtualDirectoryAPIResult` instance
|
||||
pub fn new(user_id: UserID) -> FindUserByVirtualDirectoryAPIResult {
|
||||
FindUserByVirtualDirectoryAPIResult {
|
||||
userID: user_id as u64
|
||||
userID: user_id.id()
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ impl ResultFindVirtualDirectory {
|
||||
match (user, group) {
|
||||
|
||||
// User
|
||||
(Ok(u), _) => ResultFindVirtualDirectory { kind: "user".to_string(), id: u.id as u64 },
|
||||
(Ok(u), _) => ResultFindVirtualDirectory { kind: "user".to_string(), id: u.id.id() },
|
||||
|
||||
// Group
|
||||
(_, Ok(g)) => ResultFindVirtualDirectory { kind: "group".to_string(), id: g.id() },
|
||||
|
@ -3,18 +3,18 @@
|
||||
//! @author Pierre Hubert
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::user::{User, UserPageStatus, UserID};
|
||||
use crate::helpers::{friends_helper, custom_emojies_helper, background_image_helper, likes_helper, user_helper};
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::utils::user_data_utils::user_data_url;
|
||||
use crate::data::user::AccountImageVisibility::{EVERYONE, COMUNIC_USERS};
|
||||
use crate::api_data::custom_emoji::CustomEmojiAPI;
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::user::{User, UserID, UserPageStatus};
|
||||
use crate::data::user::AccountImageVisibility::{COMUNIC_USERS, EVERYONE};
|
||||
use crate::helpers::{background_image_helper, custom_emojies_helper, friends_helper, likes_helper, user_helper};
|
||||
use crate::helpers::likes_helper::LikeType;
|
||||
use crate::utils::user_data_utils::user_data_url;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct APIUserInfo {
|
||||
userID: i64,
|
||||
userID: u64,
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
publicPage: bool,
|
||||
@ -46,16 +46,16 @@ struct APIAdvancedInfo {
|
||||
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) -> ResultBoxError<APIUserInfo> {
|
||||
pub fn new(user_id: &Option<UserID>, info: &User) -> ResultBoxError<APIUserInfo> {
|
||||
Ok(APIUserInfo {
|
||||
userID: info.id,
|
||||
userID: info.id.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)?,
|
||||
customEmojis: custom_emojies_helper::get_list_user(info.id)?
|
||||
customEmojis: custom_emojies_helper::get_list_user(&info.id)?
|
||||
.iter()
|
||||
.map(|f| CustomEmojiAPI::new(f))
|
||||
.collect(),
|
||||
@ -64,18 +64,18 @@ impl APIUserInfo {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
let curr_user_id = user_id.unwrap_or(0);
|
||||
pub fn new_advanced_info(user_id: &Option<UserID>, info: &User) -> ResultBoxError<APIUserInfo> {
|
||||
let mut 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();
|
||||
|
||||
// Check if we can return the number of friends of the user
|
||||
let number_friends = if info.public_friends_list || curr_user_id == info.id {
|
||||
friends_helper::count_friends(info.id)?
|
||||
friends_helper::count_friends(&info.id)?
|
||||
} else { 0 };
|
||||
|
||||
let likes_page = if signed_in {
|
||||
likes_helper::is_liking(curr_user_id, info.id as u64, LikeType::USER)?
|
||||
likes_helper::is_liking(&curr_user_id, info.id.id(), LikeType::USER)?
|
||||
} else { false };
|
||||
|
||||
// Set advanced user information
|
||||
@ -86,25 +86,25 @@ impl APIUserInfo {
|
||||
noCommentOnHisPage: info.block_comments_on_his_page,
|
||||
allowPostFromFriendOnHisPage: info.allow_posts_from_friends,
|
||||
account_creation_time: info.account_creation_time,
|
||||
backgroundImage: background_image_helper::get_url(info.id),
|
||||
backgroundImage: background_image_helper::get_url(&info.id),
|
||||
number_friends,
|
||||
pageLikes: likes_helper::count(info.id as u64, LikeType::USER)?,
|
||||
pageLikes: likes_helper::count(info.id.id(), LikeType::USER)?,
|
||||
user_page_like: likes_page,
|
||||
can_post_texts: user_helper::can_create_posts(curr_user_id, info.id)?
|
||||
can_post_texts: user_helper::can_create_posts(&curr_user_id, &info.id)?,
|
||||
});
|
||||
|
||||
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> {
|
||||
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) {
|
||||
if user.account_image_visibility == EVERYONE || user_id == &Some(user.id.clone()) {
|
||||
return user_account_image;
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ impl APIUserInfo {
|
||||
}
|
||||
|
||||
if user.account_image_visibility == COMUNIC_USERS ||
|
||||
friends_helper::are_friend(user_id.unwrap(), user.id)? {
|
||||
friends_helper::are_friend(&user_id.clone().unwrap(), &user.id)? {
|
||||
return user_account_image;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user