room/message: make docs more clear, deserialize to MessageEvent over RoomEvent
parent
d4b2fd0e1a
commit
9788233771
|
@ -2,13 +2,12 @@ use std::cmp::Ordering;
|
|||
use std::ops::Deref;
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use crate::events::collections::all::RoomEvent;
|
||||
use crate::events::room::message::MessageEvent;
|
||||
use crate::events::EventJson;
|
||||
|
||||
use serde::{de, ser, Serialize};
|
||||
|
||||
/// A queue that holds at most 10 messages received from the server.
|
||||
/// A queue that holds the 10 most recent messages received from the server.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct MessageQueue {
|
||||
msgs: Vec<MessageWrapper>,
|
||||
|
@ -104,19 +103,12 @@ pub(crate) mod ser_deser {
|
|||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
let messages: Vec<EventJson<RoomEvent>> = de::Deserialize::deserialize(deserializer)?;
|
||||
let messages: Vec<EventJson<MessageEvent>> = de::Deserialize::deserialize(deserializer)?;
|
||||
|
||||
// TODO this should probably bail out if deserialization fails not skip
|
||||
// TODO this should probably bail out if deserialization fails not skip the message
|
||||
let msgs: Vec<MessageWrapper> = messages
|
||||
.into_iter()
|
||||
.flat_map(|json| json.deserialize())
|
||||
.flat_map(|ev| {
|
||||
if let RoomEvent::RoomMessage(msg) = ev {
|
||||
Some(msg)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(MessageWrapper)
|
||||
.collect();
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ pub struct Room {
|
|||
pub creator: Option<UserId>,
|
||||
/// The map of room members.
|
||||
pub members: HashMap<UserId, RoomMember>,
|
||||
/// A queue of messages no longer than MAX_MSGS
|
||||
/// A queue of messages, holds no more than 10 of the most recent messages.
|
||||
///
|
||||
/// This is helpful when using a `StateStore` to avoid multiple requests
|
||||
/// to the server for messages.
|
||||
|
|
Loading…
Reference in New Issue