use std::collections::BTreeMap;
use opentalk_types_common::{time::Timestamp, users::GroupName};
use opentalk_types_signaling::ParticipantId;
use serde::{Deserialize, Serialize};
use crate::state::{ChatChunk, PrivateHistory};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ChatState {
pub enabled: bool,
pub global_history: ChatChunk,
#[serde(skip_serializing_if = "Option::is_none")]
pub breakout_room_history: Option<ChatChunk>,
pub private_history: Vec<PrivateHistory>,
pub last_seen_timestamp_global: Option<Timestamp>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_seen_timestamp_breakout: Option<Timestamp>,
pub last_seen_timestamps_private: BTreeMap<ParticipantId, Timestamp>,
pub last_seen_timestamps_group: BTreeMap<GroupName, Timestamp>,
}
impl opentalk_types_signaling::SignalingModuleFrontendData for ChatState {
const NAMESPACE: Option<opentalk_types_common::modules::ModuleId> = Some(crate::CHAT_MODULE_ID);
}
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use serde_json::json;
use super::*;
use crate::{MessageId, Scope, state::StoredMessage};
#[test]
fn server_message() {
let expected = json!({
"id":"00000000-0000-0000-0000-000000000000",
"source":"00000000-0000-0000-0000-000000000000",
"timestamp":"1970-01-01T00:00:00Z",
"content":"Hello All!",
"scope":"global",
});
let produced = serde_json::to_value(StoredMessage {
id: MessageId::nil(),
source: ParticipantId::nil(),
timestamp: Timestamp::unix_epoch(),
content: "Hello All!".to_string(),
scope: Scope::Global,
})
.unwrap();
assert_eq!(expected, produced);
}
}