|
|
@ -34,7 +34,7 @@ pub enum RoomVisibility { |
|
|
#[derive(
|
|
|
#[derive(
|
|
|
Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize,
|
|
|
Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize,
|
|
|
)]
|
|
|
)]
|
|
|
pub struct Message {
|
|
|
|
|
|
|
|
|
pub struct RoomMessage {
|
|
|
/// Time at which the message was received by this client.
|
|
|
/// Time at which the message was received by this client.
|
|
|
///
|
|
|
///
|
|
|
/// We use `SystemTime` instead of `Instant` because this is serialized and
|
|
|
/// We use `SystemTime` instead of `Instant` because this is serialized and
|
|
|
@ -53,24 +53,24 @@ pub struct Message { |
|
|
|
|
|
|
|
|
/// The history of messages sent for a single chat room.
|
|
|
/// The history of messages sent for a single chat room.
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
|
|
pub struct MessageHistory {
|
|
|
|
|
|
|
|
|
pub struct RoomMessageHistory {
|
|
|
/// Messages, sorted in increasing order.
|
|
|
/// Messages, sorted in increasing order.
|
|
|
messages: Vec<Message>,
|
|
|
|
|
|
|
|
|
messages: Vec<RoomMessage>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// MessageHistory should be transparent for serialization purposes.
|
|
|
// MessageHistory should be transparent for serialization purposes.
|
|
|
impl<'de> Deserialize<'de> for MessageHistory {
|
|
|
|
|
|
|
|
|
impl<'de> Deserialize<'de> for RoomMessageHistory {
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
|
where
|
|
|
where
|
|
|
D: Deserializer<'de>,
|
|
|
D: Deserializer<'de>,
|
|
|
{
|
|
|
{
|
|
|
let messages = Vec::<Message>::deserialize(deserializer)?;
|
|
|
|
|
|
|
|
|
let messages = Vec::<RoomMessage>::deserialize(deserializer)?;
|
|
|
Ok(Self::new(messages))
|
|
|
Ok(Self::new(messages))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// MessageHistory should be transparent for serialization purposes.
|
|
|
|
|
|
impl Serialize for MessageHistory {
|
|
|
|
|
|
|
|
|
// RoomMessageHistory should be transparent for serialization purposes.
|
|
|
|
|
|
impl Serialize for RoomMessageHistory {
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
where
|
|
|
where
|
|
|
S: Serializer,
|
|
|
S: Serializer,
|
|
|
@ -79,14 +79,14 @@ impl Serialize for MessageHistory { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl MessageHistory {
|
|
|
|
|
|
pub fn new(mut messages: Vec<Message>) -> Self {
|
|
|
|
|
|
|
|
|
impl RoomMessageHistory {
|
|
|
|
|
|
pub fn new(mut messages: Vec<RoomMessage>) -> Self {
|
|
|
messages.sort();
|
|
|
messages.sort();
|
|
|
Self { messages }
|
|
|
Self { messages }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// Inserts a `message` into this history.
|
|
|
/// Inserts a `message` into this history.
|
|
|
pub fn insert(&mut self, message: Message) {
|
|
|
|
|
|
|
|
|
pub fn insert(&mut self, message: RoomMessage) {
|
|
|
self.messages.push(message);
|
|
|
self.messages.push(message);
|
|
|
|
|
|
|
|
|
// This could be terrible for performance in the general case, but we know
|
|
|
// This could be terrible for performance in the general case, but we know
|
|
|
@ -97,7 +97,7 @@ impl MessageHistory { |
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
#[cfg(test)]
|
|
|
/// Returns the list of messages sorted in increasing chronological order.
|
|
|
/// Returns the list of messages sorted in increasing chronological order.
|
|
|
pub fn to_vec(&self) -> Vec<Message> {
|
|
|
|
|
|
|
|
|
pub fn to_vec(&self) -> Vec<RoomMessage> {
|
|
|
return self.messages.clone();
|
|
|
return self.messages.clone();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@ -123,7 +123,7 @@ pub struct RoomState { |
|
|
/// The names of the room's members.
|
|
|
/// The names of the room's members.
|
|
|
pub members: HashSet<String>,
|
|
|
pub members: HashSet<String>,
|
|
|
/// The messages sent to this chat room.
|
|
|
/// The messages sent to this chat room.
|
|
|
pub messages: MessageHistory,
|
|
|
|
|
|
|
|
|
pub messages: RoomMessageHistory,
|
|
|
/// The tickers displayed in this room.
|
|
|
/// The tickers displayed in this room.
|
|
|
pub tickers: Vec<(String, String)>,
|
|
|
pub tickers: Vec<(String, String)>,
|
|
|
}
|
|
|
}
|
|
|
@ -139,7 +139,7 @@ impl RoomState { |
|
|
owner: None,
|
|
|
owner: None,
|
|
|
operators: HashSet::new(),
|
|
|
operators: HashSet::new(),
|
|
|
members: HashSet::new(),
|
|
|
members: HashSet::new(),
|
|
|
messages: MessageHistory::default(),
|
|
|
|
|
|
|
|
|
messages: RoomMessageHistory::default(),
|
|
|
tickers: Vec::new(),
|
|
|
tickers: Vec::new(),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|