Commit 5e11e32b authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

Message: Implement PartialOrd trait

This gives a manual implementation of the PartialOrd trait for Message
which is a chronological order. We first check that the messages are
not the same in order to be sure that no time offset could make the
comparison erroneous, then we simply compare the dates and times of
the messages.
parent f92387cd
Pipeline #10995 passed with stage
in 15 minutes and 47 seconds
extern crate md5;
extern crate chrono;
use self::chrono::prelude::*;
use std::cmp::Ordering;
#[derive(Debug)]
#[derive(PartialOrd)]
#[derive(Serialize, Deserialize)]
pub struct Message {
pub sender: String,
......@@ -61,6 +61,16 @@ impl PartialEq for Message {
}
}
impl PartialOrd for Message {
fn partial_cmp(&self, other: &Message) -> Option<Ordering> {
if self == other {
Some(Ordering::Equal)
} else {
self.date.partial_cmp(&other.date)
}
}
}
impl Message {
/// Generates an unique transaction id for this message
/// The txn_id is generated using the md5sum of a concatenation of the message room id, the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment