use crate::Identity;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct MessageId(pub String);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Message {
pub id: MessageId,
pub sender: Identity,
pub content: MessageContent,
pub timestamp: DateTime<Utc>,
pub signatures: Vec<Vec<u8>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MessageContent {
Text(String),
File(FileMetadata),
VoiceCall(CallInfo),
VideoCall(CallInfo),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileMetadata {
pub name: String,
pub size: u64,
pub hash: String,
pub mime_type: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CallInfo {
pub call_id: String,
pub sdp: String,
}
impl Message {
pub fn new(sender: Identity, content: MessageContent) -> Self {
Self {
id: MessageId(format!("msg-{}", chrono::Utc::now().timestamp())),
sender,
content,
timestamp: Utc::now(),
signatures: Vec::new(),
}
}
}