mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-29 16:56:28 +00:00
Get more accurate info
This commit is contained in:
parent
5c3bbfcfaa
commit
4a968b3d6f
@ -22,7 +22,7 @@ impl FriendAPI {
|
|||||||
FriendAPI {
|
FriendAPI {
|
||||||
ID_friend: f.friend_id.id(),
|
ID_friend: f.friend_id.id(),
|
||||||
accepted: LegacyBool(f.accepted),
|
accepted: LegacyBool(f.accepted),
|
||||||
time_last_activity: f.last_activity_time,
|
time_last_activity: f.computed_last_activity_time(),
|
||||||
following: LegacyBool(f.following),
|
following: LegacyBool(f.following),
|
||||||
canPostTexts: f.can_post_texts,
|
canPostTexts: f.can_post_texts,
|
||||||
}
|
}
|
||||||
|
@ -482,6 +482,12 @@ pub fn is_user_connected(user_id: &UserID) -> bool {
|
|||||||
get_ws_connections_list().lock().unwrap().iter().any(|c| &c.user_id == user_id)
|
get_ws_connections_list().lock().unwrap().iter().any(|c| &c.user_id == user_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check out whether user is connected or not and has at list one not incognito connection
|
||||||
|
pub fn is_user_connected_not_incognito(user_id: &UserID) -> bool {
|
||||||
|
get_ws_connections_list().lock().unwrap().iter().any(|c| &c.user_id == user_id && !c.incognito)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Disconnect a user from all the WebSockets of a given client
|
/// Disconnect a user from all the WebSockets of a given client
|
||||||
pub fn disconnect_user_from_client(user_id: &UserID, client: &APIClient) -> Res {
|
pub fn disconnect_user_from_client(user_id: &UserID, client: &APIClient) -> Res {
|
||||||
let connections = get_ws_connections_list()
|
let connections = get_ws_connections_list()
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
//!
|
//!
|
||||||
//! @author Pierre Hubert
|
//! @author Pierre Hubert
|
||||||
|
|
||||||
|
use crate::controllers::user_ws_controller;
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
|
use crate::utils::date_utils::time;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub struct Friend {
|
pub struct Friend {
|
||||||
@ -12,3 +14,15 @@ pub struct Friend {
|
|||||||
pub last_activity_time: u64,
|
pub last_activity_time: u64,
|
||||||
pub can_post_texts: bool,
|
pub can_post_texts: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Friend {
|
||||||
|
/// Get the last activity of this friend. If this friend is both connected and not incognito,
|
||||||
|
/// current time will be returned instead of time stored in database
|
||||||
|
pub fn computed_last_activity_time(&self) -> u64 {
|
||||||
|
if user_ws_controller::is_user_connected_not_incognito(&self.friend_id) {
|
||||||
|
time()
|
||||||
|
} else {
|
||||||
|
self.last_activity_time
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user