2020-06-29 13:45:26 +00:00
|
|
|
//! # Friends controller
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
|
|
|
|
use crate::api_data::friend_api::FriendAPI;
|
|
|
|
use crate::controllers::routes::RequestResult;
|
|
|
|
use crate::data::http_request_handler::HttpRequestHandler;
|
2020-06-30 05:49:23 +00:00
|
|
|
use crate::helpers::{account_helper, friends_helper, user_helper};
|
2020-06-29 13:45:26 +00:00
|
|
|
|
|
|
|
/// Get the list of friends of the current user
|
|
|
|
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
|
|
|
|
let list = friends_helper::get_list(&r.user_id()?)?;
|
|
|
|
|
2020-06-29 13:53:39 +00:00
|
|
|
// Update last activity (if allowed)
|
|
|
|
if !r.post_bool_opt("incognito", false) {
|
|
|
|
account_helper::update_last_activity(&r.user_id()?)?;
|
|
|
|
}
|
2020-06-29 13:45:26 +00:00
|
|
|
|
|
|
|
r.set_response(FriendAPI::from_list(&list))
|
2020-06-30 05:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the list of friends of another user
|
|
|
|
pub fn get_other_user_list(r: &mut HttpRequestHandler) -> RequestResult {
|
|
|
|
let user_id = r.post_user_id("userID")?;
|
|
|
|
|
|
|
|
if !user_helper::can_see_user_page(&r.user_id_or_invalid(), &user_id)? {
|
|
|
|
r.forbidden("You can not access this user information!".to_string())?;
|
|
|
|
}
|
|
|
|
|
|
|
|
if !user_helper::is_user_friends_list_public(&user_id)? {
|
|
|
|
r.forbidden("The friend list of this user is not public!".to_string())?;
|
|
|
|
}
|
|
|
|
|
|
|
|
let friends = friends_helper::get_list(&user_id)?;
|
|
|
|
|
|
|
|
r.set_response(friends.iter().map(|f| f.friend_id.id()).collect::<Vec<u64>>())
|
2020-06-29 13:45:26 +00:00
|
|
|
}
|