message: only push message when timestamp is larger than last msg in queue
This commit is contained in:
parent
9788233771
commit
2c4b6919ef
1 changed files with 7 additions and 0 deletions
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue