mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-27 22:18:51 +00:00
Can update following status
This commit is contained in:
parent
f540716b86
commit
b15ffe0856
@ -120,11 +120,21 @@ pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
/// Remove a friend from the list
|
||||
pub fn remove_friend(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let friend_id = r.post_user_id("friendID")?;
|
||||
let friend_id = r.post_friend_id("friendID")?;
|
||||
|
||||
friends_helper::remove_friendship(r.user_id_ref()?, &friend_id)?;
|
||||
|
||||
// TODO : Delete any related notification
|
||||
|
||||
r.success("The friend was removed from the list!")
|
||||
}
|
||||
|
||||
/// Update following status
|
||||
pub fn set_following(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let friend_id = r.post_friend_id("friendID")?;
|
||||
let follow = r.post_bool("follow")?;
|
||||
|
||||
friends_helper::set_following(r.user_id_ref()?, &friend_id, follow)?;
|
||||
|
||||
r.success("Following status updated!")
|
||||
}
|
@ -105,6 +105,8 @@ pub fn get_routes() -> Vec<Route> {
|
||||
|
||||
Route::post("/friends/remove", Box::new(friends_controller::remove_friend)),
|
||||
|
||||
Route::post("/friends/setFollowing", Box::new(friends_controller::set_following)),
|
||||
|
||||
|
||||
// Conversations controller
|
||||
Route::post("/conversations/create", Box::new(conversations_controller::create)),
|
||||
|
@ -17,7 +17,7 @@ use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::data::group::GroupAccessLevel;
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::{account_helper, api_helper, conversations_helper, groups_helper, user_helper, virtual_directory_helper};
|
||||
use crate::helpers::{account_helper, api_helper, conversations_helper, friends_helper, groups_helper, user_helper, virtual_directory_helper};
|
||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||
use crate::utils::string_utils::{check_url, remove_html_nodes};
|
||||
use crate::utils::user_data_utils::{generate_new_user_data_file_name, prepare_file_creation, user_data_path};
|
||||
@ -438,6 +438,21 @@ impl HttpRequestHandler {
|
||||
Ok(user_id)
|
||||
}
|
||||
|
||||
/// Get the ID of a friend included in a POST request
|
||||
///
|
||||
/// *Note :* This function does not check whether the user exists or not before checking if the
|
||||
/// two users are friend because as it is not possible to be friend with a non existent person
|
||||
/// A single check is enough
|
||||
pub fn post_friend_id(&mut self, name: &str) -> ResultBoxError<UserID> {
|
||||
let friend_id = UserID::new(self.post_u64(name)?);
|
||||
|
||||
if !friends_helper::are_friend(&friend_id, self.user_id_ref()?)? {
|
||||
self.forbidden("You are not friend with this person!".to_string())?;
|
||||
}
|
||||
|
||||
Ok(friend_id)
|
||||
}
|
||||
|
||||
/// Get a virtual directory included in a POST request
|
||||
pub fn post_virtual_directory(&mut self, name: &str) -> ResultBoxError<String> {
|
||||
let dir = self.post_string(name)?;
|
||||
|
@ -163,6 +163,15 @@ pub fn is_following(user_id: &UserID, friend_id: &UserID) -> ResultBoxError<bool
|
||||
.map(|f| f > 0)
|
||||
}
|
||||
|
||||
/// Update following status of a friendship
|
||||
pub fn set_following(user_id: &UserID, friend_id: &UserID, follow: bool) -> ResultBoxError {
|
||||
database::UpdateInfo::new(FRIENDS_TABLE)
|
||||
.cond_user_id("ID_personne", user_id)
|
||||
.cond_user_id("ID_amis", friend_id)
|
||||
.set_legacy_bool("abonnement", follow)
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Get the status of a friendship
|
||||
pub fn get_status(user_id: &UserID, friend_id: &UserID) -> ResultBoxError<FriendshipStatus> {
|
||||
let mut status = FriendshipStatus {
|
||||
|
Loading…
Reference in New Issue
Block a user