diff --git a/src/data/conversation.rs b/src/data/conversation.rs index 48772c2..9396b47 100644 --- a/src/data/conversation.rs +++ b/src/data/conversation.rs @@ -4,7 +4,7 @@ use crate::data::user::UserID; -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub struct Conversation { pub id: u64, pub owner_id: UserID, diff --git a/src/data/friend.rs b/src/data/friend.rs index 85db299..590e31e 100644 --- a/src/data/friend.rs +++ b/src/data/friend.rs @@ -4,6 +4,7 @@ use crate::data::user::UserID; +#[derive(PartialEq, Eq)] pub struct Friend { pub friend_id: UserID, pub accepted: bool, diff --git a/src/data/user_membership.rs b/src/data/user_membership.rs index 2a11f69..4be6ac3 100644 --- a/src/data/user_membership.rs +++ b/src/data/user_membership.rs @@ -2,12 +2,37 @@ //! //! @author Pierre Hubert -use crate::data::friend::Friend; +use std::cmp::Ordering; + use crate::data::conversation::Conversation; +use crate::data::friend::Friend; use crate::data::group_id::GroupID; +#[derive(PartialEq, Eq)] pub enum UserMembership { Group(GroupID, u64), Friend(Friend), - Conversation(Conversation) + Conversation(Conversation), +} + +impl UserMembership { + pub fn last_active(&self) -> u64 { + match self { + UserMembership::Group(_, last_active) => *last_active, + UserMembership::Friend(f) => f.last_activity_time, + UserMembership::Conversation(c) => c.last_active, + } + } +} + +impl PartialOrd for UserMembership { + fn partial_cmp(&self, other: &Self) -> Option { + self.last_active().partial_cmp(&other.last_active()) + } +} + +impl Ord for UserMembership { + fn cmp(&self, other: &Self) -> Ordering { + self.last_active().cmp(&other.last_active()) + } } \ No newline at end of file diff --git a/src/helpers/webapp_helper.rs b/src/helpers/webapp_helper.rs index fecd458..cf98fe4 100644 --- a/src/helpers/webapp_helper.rs +++ b/src/helpers/webapp_helper.rs @@ -30,5 +30,7 @@ pub fn get_user_memberships(user_id: &UserID) -> ResultBoxError