Remove confusing type alias for AnyPossiblyRedactedSyncMessageEvent.
There's already a SyncMessageEvent in Ruma which is something else. Let's prefer the full, unambiguous type.master
parent
6a96368048
commit
2ce0765206
|
@ -46,24 +46,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
|
||||||
|
@ -118,7 +116,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 {
|
||||||
|
@ -181,7 +179,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