Update to rAuth v1, closes #63.

Add Pong packet for normal frames.
This commit is contained in:
Paul
2021-09-11 11:23:15 +01:00
parent 5328c66cbb
commit 06f968022d
24 changed files with 888 additions and 795 deletions

View File

@@ -1,6 +1,5 @@
use hive_pubsub::PubSub;
use mongodb::bson::doc;
use rauth::auth::Session;
use rocket::serde::json::Value;
use serde::{Deserialize, Serialize};
@@ -19,24 +18,17 @@ pub enum WebSocketError {
}
#[derive(Deserialize, Debug)]
pub struct BotAuth {
pub token: String
}
#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum AuthType {
User(Session),
Bot(BotAuth)
pub struct Auth {
pub token: String,
}
#[derive(Deserialize, Debug)]
#[serde(tag = "type")]
pub enum ServerboundNotification {
Authenticate(AuthType),
Authenticate(Auth),
BeginTyping { channel: String },
EndTyping { channel: String },
Ping { data: Vec<u8> }
Ping { data: Vec<u8>, responded: Option<()> },
}
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -50,7 +42,7 @@ pub enum RemoveUserField {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum RemoveChannelField {
Icon,
Description
Description,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -85,8 +77,9 @@ pub enum ClientboundNotification {
users: Vec<User>,
servers: Vec<Server>,
channels: Vec<Channel>,
members: Vec<Member>
members: Vec<Member>,
},
Pong { data: Vec<u8> },
Message(Message),
MessageUpdate {
@@ -159,11 +152,11 @@ pub enum ClientboundNotification {
role_id: String,
data: Value,
#[serde(skip_serializing_if = "Option::is_none")]
clear: Option<RemoveRoleField>
clear: Option<RemoveRoleField>,
},
ServerRoleDelete {
id: String,
role_id: String
role_id: String,
},
UserUpdate {
@@ -222,8 +215,7 @@ pub async fn prehandle_hook(notification: &ClientboundNotification) -> Result<()
subscribe_if_exists(recipient.clone(), channel_id.to_string()).ok();
}
}
Channel::TextChannel { server, .. }
| Channel::VoiceChannel { server, .. } => {
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
// ! FIXME: write a better algorithm?
let members = Server::fetch_member_ids(server).await?;
for member in members {