IronForce is a decentralized network, Degeon is a messenger built on it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
1.2 KiB

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<u8>),
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),
}