feat: Chat request implementation #14
1 changed files with 19 additions and 2 deletions
|
@ -19,7 +19,10 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use oxidetalis_core::{cipher::K256Secret, types::Signature};
|
use oxidetalis_core::{
|
||||||
|
cipher::K256Secret,
|
||||||
|
types::{PublicKey, Signature},
|
||||||
|
};
|
||||||
use salvo::websocket::Message;
|
use salvo::websocket::Message;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
@ -42,12 +45,16 @@ pub struct ServerEvent<T> {
|
||||||
|
|
||||||
/// server websocket event type
|
/// server websocket event type
|
||||||
#[derive(Serialize, Clone, Eq, PartialEq, Debug)]
|
#[derive(Serialize, Clone, Eq, PartialEq, Debug)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase", tag = "event", content = "data")]
|
||||||
pub enum ServerEventType {
|
pub enum ServerEventType {
|
||||||
/// Ping event
|
/// Ping event
|
||||||
Ping { timestamp: u64 },
|
Ping { timestamp: u64 },
|
||||||
/// Pong event
|
/// Pong event
|
||||||
Pong { timestamp: u64 },
|
Pong { timestamp: u64 },
|
||||||
|
/// Message event, contain a message to the client
|
||||||
|
Message { msg: String },
|
||||||
|
/// New chat request from someone
|
||||||
|
ChatRequest { from: PublicKey },
|
||||||
/// Error event
|
/// Error event
|
||||||
Error {
|
Error {
|
||||||
awiteb marked this conversation as resolved
|
|||||||
name: &'static str,
|
name: &'static str,
|
||||||
|
@ -88,6 +95,16 @@ impl ServerEvent<Unsigned> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create message event
|
||||||
|
pub fn message(msg: impl Into<String>) -> Self {
|
||||||
|
Self::new(ServerEventType::Message { msg: msg.into() })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create chat request event
|
||||||
|
pub fn chat_request(from: &PublicKey) -> Self {
|
||||||
|
Self::new(ServerEventType::ChatRequest { from: *from })
|
||||||
|
}
|
||||||
|
|
||||||
/// Sign the event
|
/// Sign the event
|
||||||
pub fn sign(self, shared_secret: &[u8; 32]) -> ServerEvent<Signed> {
|
pub fn sign(self, shared_secret: &[u8; 32]) -> ServerEvent<Signed> {
|
||||||
ServerEvent::<Signed> {
|
ServerEvent::<Signed> {
|
||||||
|
|
Loading…
Reference in a new issue
in the client, you mentioned to make it alphabetical, should it be the same here?
Yes, I forgot it