Merge branch 'remove-possibly-redacted-type-alias' into master
commit
3472614649
|
@ -56,24 +56,22 @@ impl PossiblyRedactedExt for AnyPossiblyRedactedSyncMessageEvent {
|
||||||
|
|
||||||
const MESSAGE_QUEUE_CAP: usize = 35;
|
const MESSAGE_QUEUE_CAP: usize = 35;
|
||||||
|
|
||||||
pub type SyncMessageEvent = AnyPossiblyRedactedSyncMessageEvent;
|
|
||||||
|
|
||||||
/// A queue that holds the 35 most recent messages received from the server.
|
/// A queue that holds the 35 most recent messages received from the server.
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct MessageQueue {
|
pub struct MessageQueue {
|
||||||
pub(crate) msgs: Vec<MessageWrapper>,
|
pub(crate) msgs: Vec<MessageWrapper>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A wrapper for `ruma_events::SyncMessageEvent` that allows implementation of
|
/// A wrapper for `ruma_events::AnyPossiblyRedactedSyncMessageEvent` that allows
|
||||||
/// Eq, Ord and the Partial versions of the traits.
|
/// implementation of Eq, Ord and the Partial versions of the traits.
|
||||||
///
|
///
|
||||||
/// `MessageWrapper` also implements Deref and DerefMut so accessing the events contents
|
/// `MessageWrapper` also implements Deref and DerefMut so accessing the events
|
||||||
/// are simplified.
|
/// contents are simplified.
|
||||||
#[derive(Clone, Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub struct MessageWrapper(pub SyncMessageEvent);
|
pub struct MessageWrapper(pub AnyPossiblyRedactedSyncMessageEvent);
|
||||||
|
|
||||||
impl Deref for MessageWrapper {
|
impl Deref for MessageWrapper {
|
||||||
type Target = SyncMessageEvent;
|
type Target = AnyPossiblyRedactedSyncMessageEvent;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -128,7 +126,7 @@ impl MessageQueue {
|
||||||
/// Inserts a `MessageEvent` into `MessageQueue`, sorted by by `origin_server_ts`.
|
/// Inserts a `MessageEvent` into `MessageQueue`, sorted by by `origin_server_ts`.
|
||||||
///
|
///
|
||||||
/// Removes the oldest element in the queue if there are more than 10 elements.
|
/// Removes the oldest element in the queue if there are more than 10 elements.
|
||||||
pub fn push(&mut self, msg: SyncMessageEvent) -> bool {
|
pub fn push(&mut self, msg: AnyPossiblyRedactedSyncMessageEvent) -> bool {
|
||||||
// only push new messages into the queue
|
// only push new messages into the queue
|
||||||
if let Some(latest) = self.msgs.last() {
|
if let Some(latest) = self.msgs.last() {
|
||||||
if msg.origin_server_ts() < latest.origin_server_ts() && self.msgs.len() >= 10 {
|
if msg.origin_server_ts() < latest.origin_server_ts() && self.msgs.len() >= 10 {
|
||||||
|
@ -191,7 +189,7 @@ pub(crate) mod ser_deser {
|
||||||
{
|
{
|
||||||
let mut msgs = Vec::with_capacity(access.size_hint().unwrap_or(0));
|
let mut msgs = Vec::with_capacity(access.size_hint().unwrap_or(0));
|
||||||
|
|
||||||
while let Some(msg) = access.next_element::<SyncMessageEvent>()? {
|
while let Some(msg) = access.next_element::<AnyPossiblyRedactedSyncMessageEvent>()? {
|
||||||
msgs.push(MessageWrapper(msg));
|
msgs.push(MessageWrapper(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue