feat(client): protocol v2 wire layer, screen sharing, channel webhooks and secure voice

Verified against the real gateway via tests/gateway_interop.rs.
This commit is contained in:
Loki 2026-10-24 16:51:15 +02:00
parent 8460fb28fd
commit 3d7dd5413b
Signed by: boba
GPG key ID: 253067914055423B
65 changed files with 6048 additions and 1156 deletions

View file

@ -1,5 +1,5 @@
use crate::net::wire;
use anyhow::Result;
use serde_json;
use tokio::sync::mpsc;
use tracing::debug;
@ -9,7 +9,7 @@ use super::super::super::types::*;
pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Result<()> {
match pid {
PID_DM_START => {
let p: DmStartResponsePayload = serde_json::from_slice(payload)?;
let p: DmStartResponsePayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::DmStart {
dm_id: p.dm_id,
@ -31,7 +31,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_DM_MESSAGE => {
let p: DmMessagePayload = serde_json::from_slice(payload)?;
let p: DmMessagePayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::DmMessage {
dm_id: p.dm_id,
@ -42,7 +42,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_DM_HISTORY => {
let p: DmHistoryPayload = serde_json::from_slice(payload)?;
let p: DmHistoryPayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::DmHistory {
dm_id: p.dm_id,
@ -61,7 +61,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_FRIEND_LIST => {
let p: FriendListPayload = serde_json::from_slice(payload)?;
let p: FriendListPayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::FriendList {
friends: p
@ -78,7 +78,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_MESSAGE_REACTION_ADD => {
let p: ReactionPayload = serde_json::from_slice(payload)?;
let p: ReactionPayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::ReactionAdded {
channel_id: p.channel_id,
@ -89,7 +89,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_MESSAGE_REACTION_REMOVE => {
let p: ReactionPayload = serde_json::from_slice(payload)?;
let p: ReactionPayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::ReactionRemoved {
channel_id: p.channel_id,
@ -100,7 +100,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_MESSAGE_EDIT => {
let p: ChatMessagePayload = serde_json::from_slice(payload)?;
let p: ChatMessagePayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::MessageEdited {
channel_id: p.channel_id,
@ -111,7 +111,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_MESSAGE_DELETE => {
let p: MessageDeletePayload = serde_json::from_slice(payload)?;
let p: MessageDeletePayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::MessageDeleted {
channel_id: p.channel_id,
@ -120,9 +120,9 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_FRIEND_EVENT => {
let p: FriendEventPayload = serde_json::from_slice(payload)?;
match p.event_type.as_str() {
"request" => {
let p: FriendEventPayload = wire::decode(payload)?;
match p.event.as_str() {
"request" | "REQUEST_RECEIVED" => {
let _ = tx
.send(NetEvent::FriendRequested {
user_id: p.user_id,
@ -130,7 +130,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
})
.await;
}
"accepted" => {
"accepted" | "REQUEST_ACCEPTED" => {
let _ = tx
.send(NetEvent::FriendAccepted {
user_id: p.user_id,
@ -138,16 +138,16 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
})
.await;
}
"removed" => {
"removed" | "FRIEND_REMOVED" => {
let _ = tx
.send(NetEvent::FriendRemoved { user_id: p.user_id })
.await;
}
_ => debug!("unhandled friend event: {}", p.event_type),
_ => debug!("unhandled friend event: {}", p.event),
}
}
PID_E2EE_DM_KEY_EXCHANGE => {
let p: E2eeDmKeyExchangePayload = serde_json::from_slice(payload)?;
let p: E2eeDmKeyExchangePayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::E2eeDmKeyExchange {
dm_id: p.dm_id,
@ -156,13 +156,13 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_E2EE_DM_KEY_EXCHANGE_ACK => {
let p: E2eeDmKeyExchangeAckPayload = serde_json::from_slice(payload)?;
let p: E2eeDmKeyExchangeAckPayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::E2eeDmKeyExchangeAck { dm_id: p.dm_id })
.await;
}
PID_E2EE_DM_MESSAGE => {
let p: E2eeDmMessagePayload = serde_json::from_slice(payload)?;
let p: E2eeDmMessagePayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::E2eeDmMessage {
dm_id: p.dm_id,
@ -173,7 +173,7 @@ pub async fn handle(pid: u16, payload: &[u8], tx: &mpsc::Sender<NetEvent>) -> Re
.await;
}
PID_E2EE_DM_HISTORY => {
let p: E2eeDmHistoryPayload = serde_json::from_slice(payload)?;
let p: E2eeDmHistoryPayload = wire::decode(payload)?;
let _ = tx
.send(NetEvent::E2eeDmHistory {
dm_id: p.dm_id,