maybe (barely) working websocket now?

This commit is contained in:
sam 2024-01-22 02:18:34 +01:00
parent f07333e358
commit 0858d4893a
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
5 changed files with 253 additions and 41 deletions

View file

@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize};
use super::user::PartialUser;
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Message {
pub id: String,
pub channel_id: String,

View file

@ -1,6 +1,6 @@
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct User {
pub id: String,
pub username: String,
@ -8,7 +8,7 @@ pub struct User {
pub avatar_url: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PartialUser {
pub id: String,
pub username: String,

View file

@ -1,7 +1,34 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::{
id::GuildType,
model::{user::PartialUser, Message},
Id,
};
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "t", content = "d", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Dispatch {
MessageCreate
MessageCreate {
id: String,
channel_id: String,
guild_id: String,
author: PartialUser,
content: Option<String>,
created_at: DateTime<Utc>,
},
}
impl Dispatch {
pub fn message_create(m: Message, guild_id: Id<GuildType>) -> Self {
Self::MessageCreate {
id: m.id,
channel_id: m.channel_id,
guild_id: guild_id.0,
author: m.author,
content: m.content,
created_at: m.created_at,
}
}
}

View file

@ -11,14 +11,20 @@ pub enum Payload {
#[serde(rename = "r")]
recipients: Vec<String>,
},
Hello,
Error {
message: String,
},
/// Hello message, sent after authentication succeeds
Hello {},
/// S2S authentication. Fields correspond to headers (Host, Date, X-Foxchat-Server, X-Foxchat-Signature)
Identify {
host: String,
date: String,
server: String,
signature: String,
},
Error {
message: String,
/// 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,
}
}