use ironforce::PublicKey; use serde::{Deserialize, Serialize}; /// A message in the messenger #[derive(Clone, Debug, Serialize, Deserialize)] pub struct DegMessage { pub sender: PublicKey, pub timestamp: i64, pub content: DegMessageContent, } impl DegMessage { /// Create a simple text message pub fn new_text(text: String, my_key: &PublicKey) -> DegMessage { Self { sender: my_key.clone(), timestamp: chrono::Utc::now().timestamp(), content: DegMessageContent::Text(text), } } } /// The content of the message #[derive(Clone, Debug, Serialize, Deserialize)] pub enum DegMessageContent { Text(String), File(Vec), Service, } /// User's profile #[derive(Clone, Debug, Serialize, Deserialize, Default)] pub struct Profile { pub name: String, } /// A protocol message (that's sent through IF) #[derive(Clone, Debug, Serialize, Deserialize)] pub enum ProtocolMsg { /// Requesting profile ProfileRequest, /// Responding to the profile request with a profile ProfileResponse(Profile), /// A peer discovery Ping, /// A message is sent NewMessage(DegMessage), }