diff --git a/src/controllers/account_controller.rs b/src/controllers/account_controller.rs index dd9889f..59a27dd 100644 --- a/src/controllers/account_controller.rs +++ b/src/controllers/account_controller.rs @@ -1,8 +1,8 @@ +use crate::api_data::current_user_id::CurrentUserID; use crate::api_data::login_success::LoginSuccess; use crate::controllers::routes::RequestResult; use crate::data::http_request_handler::HttpRequestHandler; use crate::helpers::account_helper; -use crate::api_data::current_user_id::CurrentUserID; /// Account controller /// @@ -35,7 +35,7 @@ pub fn login_user(request: &mut HttpRequestHandler) -> RequestResult { pub fn logout_user(request: &mut HttpRequestHandler) -> RequestResult { account_helper::destroy_login_tokens( &request.user_id()?, - request.api_client() + request.api_client(), )?; request.success("User disconnected.") diff --git a/src/controllers/friends_controller.rs b/src/controllers/friends_controller.rs index 829f07d..759a915 100644 --- a/src/controllers/friends_controller.rs +++ b/src/controllers/friends_controller.rs @@ -5,13 +5,16 @@ use crate::api_data::friend_api::FriendAPI; use crate::controllers::routes::RequestResult; use crate::data::http_request_handler::HttpRequestHandler; -use crate::helpers::friends_helper; +use crate::helpers::{account_helper, friends_helper}; /// 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()?)?; - // TODO : update last activity (if allowed) + // Update last activity (if allowed) + if !r.post_bool_opt("incognito", false) { + account_helper::update_last_activity(&r.user_id()?)?; + } r.set_response(FriendAPI::from_list(&list)) } \ No newline at end of file diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 5b322fb..5482919 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -1,4 +1,4 @@ -use crate::constants::database_tables_names::USER_ACCESS_TOKENS_TABLE; +use crate::constants::database_tables_names::{USER_ACCESS_TOKENS_TABLE, USERS_TABLE}; use crate::data::api_client::APIClient; use crate::data::error::{ExecError, ResultBoxError}; use crate::data::user::UserID; @@ -6,6 +6,7 @@ use crate::data::user_token::UserAccessToken; use crate::helpers::{database, user_helper}; use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo}; use crate::utils::crypt_utils::{crypt_pass, rand_str}; +use crate::utils::date_utils::time; /// Account helper /// @@ -101,4 +102,12 @@ pub fn check_user_directory_availability(dir: &str, user_id: Option) -> // No user was found, virtual directory is considered as available (Err(_), _) => Ok(true) } +} + +/// Update the last activity of a user +pub fn update_last_activity(user_id: &UserID) -> ResultBoxError { + database::UpdateInfo::new(USERS_TABLE) + .cond_user_id("ID", user_id) + .set_u64("last_activity", time()) + .exec() } \ No newline at end of file