feat: build out chat server websocket more, start identity websocket
This commit is contained in:
parent
18b644d24b
commit
f7494034d5
13 changed files with 300 additions and 24 deletions
25
foxchat/src/c2s/event.rs
Normal file
25
foxchat/src/c2s/event.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::s2s::Dispatch;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(tag = "t", content = "d", rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum Payload {
|
||||
#[serde(rename = "D")]
|
||||
Dispatch {
|
||||
#[serde(rename = "e")]
|
||||
event: Dispatch,
|
||||
#[serde(rename = "s")]
|
||||
server_id: String,
|
||||
},
|
||||
Error {
|
||||
message: String,
|
||||
},
|
||||
/// Hello message, sent after authentication succeeds
|
||||
Hello {
|
||||
guilds: Vec<String>,
|
||||
},
|
||||
Identify {
|
||||
token: String,
|
||||
},
|
||||
}
|
3
foxchat/src/c2s/mod.rs
Normal file
3
foxchat/src/c2s/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod event;
|
||||
|
||||
pub use event::Payload;
|
|
@ -3,6 +3,7 @@ pub mod fed;
|
|||
pub mod http;
|
||||
pub mod model;
|
||||
pub mod s2s;
|
||||
pub mod c2s;
|
||||
pub mod id;
|
||||
|
||||
pub use error::FoxError;
|
||||
|
|
|
@ -8,7 +8,7 @@ pub struct Channel {
|
|||
pub topic: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct PartialChannel {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::{user::PartialUser, channel::PartialChannel};
|
||||
use super::{channel::PartialChannel, user::PartialUser};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Guild {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub owner: PartialUser,
|
||||
pub default_channel: PartialChannel,
|
||||
pub channels: Option<Vec<PartialChannel>>,
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::{
|
||||
id::GuildType,
|
||||
model::{user::PartialUser, Message},
|
||||
model::{user::PartialUser, Guild, Message, User},
|
||||
Id,
|
||||
};
|
||||
|
||||
|
@ -18,6 +18,10 @@ pub enum Dispatch {
|
|||
content: Option<String>,
|
||||
created_at: DateTime<Utc>,
|
||||
},
|
||||
Ready {
|
||||
user: User,
|
||||
guilds: Vec<Guild>,
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch {
|
||||
|
|
|
@ -5,6 +5,7 @@ use super::Dispatch;
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(tag = "t", content = "d", rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum Payload {
|
||||
#[serde(rename = "D")]
|
||||
Dispatch {
|
||||
#[serde(rename = "e")]
|
||||
event: Dispatch,
|
||||
|
@ -15,7 +16,9 @@ pub enum Payload {
|
|||
message: String,
|
||||
},
|
||||
/// Hello message, sent after authentication succeeds
|
||||
Hello {},
|
||||
Hello {
|
||||
heartbeat_interval: u64,
|
||||
},
|
||||
/// S2S authentication. Fields correspond to headers (Host, Date, X-Foxchat-Server, X-Foxchat-Signature)
|
||||
Identify {
|
||||
host: String,
|
||||
|
@ -26,5 +29,15 @@ pub enum Payload {
|
|||
/// Sent when a user connects to the identity server's gateway, to signal the chat server to send READY for that user
|
||||
Connect {
|
||||
user_id: String,
|
||||
},
|
||||
/// Sent on a regular interval by the connecting server, to keep the connection alive.
|
||||
Heartbeat {
|
||||
#[serde(rename = "t")]
|
||||
timestamp: u64,
|
||||
},
|
||||
/// Sent in response to a Heartbeat.
|
||||
HeartbeatAck {
|
||||
#[serde(rename = "t")]
|
||||
timestamp: u64,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue