message: only push message when timestamp is larger than last msg in queue

master
Devin R 2020-04-30 06:57:25 -04:00
parent 9788233771
commit 2c4b6919ef
1 changed files with 7 additions and 0 deletions

View File

@ -71,6 +71,13 @@ impl MessageQueue {
///
/// Removes the oldest element in the queue if there are more than 10 elements.
pub fn push(&mut self, msg: MessageEvent) -> bool {
// only push new messages into the queue
if let Some(latest) = self.msgs.last() {
if msg.origin_server_ts < latest.origin_server_ts {
return false;
}
}
let message = MessageWrapper(msg);
match self.msgs.binary_search_by(|m| m.cmp(&message)) {
Ok(pos) => self.msgs.insert(pos, message),