mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-01-30 14:03:00 +00:00
Return the number of friends of a user
This commit is contained in:
parent
9d4b60f0ff
commit
a5dab7e312
@ -36,6 +36,7 @@ struct APIAdvancedInfo {
|
||||
allowPostFromFriendOnHisPage: bool,
|
||||
account_creation_time: u64,
|
||||
backgroundImage: String,
|
||||
number_friends: usize,
|
||||
}
|
||||
|
||||
impl APIUserInfo {
|
||||
@ -62,6 +63,13 @@ impl APIUserInfo {
|
||||
pub fn new_advanced_info(user_id: Option<UserID>, info: &User) -> ResultBoxError<APIUserInfo> {
|
||||
let mut user = APIUserInfo::new(user_id, info)?;
|
||||
|
||||
// Check if we can return the number of friends of the user
|
||||
let number_friends = if info.public_friends_list || user_id.unwrap_or(0) == info.id {
|
||||
friends_helper::count_friends(info.id)?
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
// Set advanced user information
|
||||
user.advanced_info = Some(APIAdvancedInfo {
|
||||
friend_list_public: info.public_friends_list,
|
||||
@ -71,6 +79,7 @@ impl APIUserInfo {
|
||||
allowPostFromFriendOnHisPage: info.allow_posts_from_friends,
|
||||
account_creation_time: info.account_creation_time,
|
||||
backgroundImage: background_image_helper::get_url(info.id),
|
||||
number_friends,
|
||||
});
|
||||
|
||||
Ok(user)
|
||||
|
@ -15,4 +15,12 @@ pub fn are_friend(user_one: UserID, user_two: UserID) -> ResultBoxError<bool> {
|
||||
.cond_i64("ID_personne", user_one)
|
||||
.cond_i64("ID_amis", user_two)
|
||||
.cond_i64("actif", 1))? > 0)
|
||||
}
|
||||
|
||||
/// Count the number of friends of a user
|
||||
pub fn count_friends(user_id: UserID) -> ResultBoxError<usize> {
|
||||
QueryInfo::new(FRIENDS_TABLE)
|
||||
.cond_i64("ID_amis", user_id)
|
||||
.cond_u32("actif", 1)
|
||||
.exec_count()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user