Cleaned up messages, spec changes

The protocol changed a bit, I forgot to add room ids for some of the
messages. Other big features are that there are now ways to process
messages built into the library itself. Signature verification is
stubbed out because its a low priority feature, but encoding it in the
lib gives a standardized way to do it
This commit is contained in:
2026-05-17 13:43:23 -07:00
parent 8712e4603d
commit a3f5470549
5 changed files with 142 additions and 20 deletions
+45 -6
View File
@@ -1,15 +1,54 @@
use crate::RoomId;
use crate::client::ClientMessage;
use crate::state::StatePath;
use crate::User;
use time::OffsetDateTime;
use serde::{Deserialize, Serialize};
pub enum VerificationError {
NoKey
}
//Monotonically increasing messageID
#[derive(Serialize,Deserialize,Debug,Clone)]
pub struct MessageId(u64);
#[derive(Serialize,Deserialize,Debug,Clone)]
pub struct Message {
body: String,
signature: Box<[u8]>,
sender: User,
timestamp: OffsetDateTime
#[derive(Serialize,Deserialize,Clone,Debug)]
pub struct TaggedMessage {
pub message: ClientMessage,
#[serde(with="time::serde::timestamp")]
pub client_timestamp: OffsetDateTime,
#[serde(with="time::serde::timestamp")]
pub server_timestamp: OffsetDateTime,
#[serde(with = "serde_bytes")]
pub signature: Box<[u8]>,
pub user: User
}
impl TaggedMessage {
pub fn verify(&self) -> Result<bool,VerificationError> {
unimplemented!()
}
// Returns room name or state path
pub fn get_relevance(&self) -> Option<Relevance> {
self.message.get_relevance()
}
}
#[derive(PartialEq,Eq,Hash,Clone,Debug)]
pub enum Relevance {
Message(RoomId),
State(RoomId,StatePath),
Post(User)
}
//#[derive(Serialize,Deserialize,Debug,Clone)]
//pub struct Message {
// body: String,
// signature: Box<[u8]>,
// sender: User,
// // Used for signature check
// client_timestamp: OffsetDateTime,
// // Used for ordering messages
// server_timestamp: OffsetDateTime,
//}