2020-07-13 09:17:35 +00:00
|
|
|
//! # User membership
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
|
2020-07-13 09:44:37 +00:00
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
2020-07-13 09:17:35 +00:00
|
|
|
use crate::data::conversation::Conversation;
|
2020-07-13 09:44:37 +00:00
|
|
|
use crate::data::friend::Friend;
|
2020-07-13 09:17:35 +00:00
|
|
|
use crate::data::group_id::GroupID;
|
|
|
|
|
2020-07-13 09:44:37 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
2020-07-13 09:17:35 +00:00
|
|
|
pub enum UserMembership {
|
|
|
|
Group(GroupID, u64),
|
|
|
|
Friend(Friend),
|
2020-07-13 09:44:37 +00:00
|
|
|
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<Ordering> {
|
|
|
|
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())
|
|
|
|
}
|
2020-07-13 09:17:35 +00:00
|
|
|
}
|