mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 02:55:47 -04:00
message: only push message when timestamp is larger than last msg in queue
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user