From f65b9c104177f6f8e787ebdfa536d497c84bb6c0 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Thu, 24 Oct 2024 21:44:39 +0200 Subject: [PATCH] add GatewayIdentifyPresenceUpdate --- src/types/events/identify.rs | 6 ++++-- src/types/events/presence.rs | 34 ++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/types/events/identify.rs b/src/types/events/identify.rs index bb2434b0..f6d0e071 100644 --- a/src/types/events/identify.rs +++ b/src/types/events/identify.rs @@ -2,10 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::types::events::{PresenceUpdate, WebSocketEvent}; +use crate::types::events::WebSocketEvent; use serde::{Deserialize, Serialize}; use serde_with::serde_as; +use super::GatewayIdentifyPresenceUpdate; + #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, WebSocketEvent)] pub struct GatewayIdentifyPayload { pub token: String, @@ -18,7 +20,7 @@ pub struct GatewayIdentifyPayload { #[serde(skip_serializing_if = "Option::is_none")] pub shard: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub presence: Option, + pub presence: Option, // What is the difference between these two? // Intents is documented, capabilities is used in users // I wonder if these are interchangeable... diff --git a/src/types/events/presence.rs b/src/types/events/presence.rs index 19df6f15..204b8b39 100644 --- a/src/types/events/presence.rs +++ b/src/types/events/presence.rs @@ -10,7 +10,8 @@ use serde::{Deserialize, Serialize}; /// Sent by the client to update its status and presence; /// See pub struct UpdatePresence { - /// Unix time of when the client went idle, or none if client is not idle. + /// Unix time of when the client went idle, or n + /// one if client is not idle. pub since: Option, /// the client's status (online, invisible, offline, dnd, idle..) pub status: UserStatus, @@ -19,20 +20,37 @@ pub struct UpdatePresence { } #[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, WebSocketEvent)] -/// Received to tell the client that a user updated their presence / status +/// Received to tell the client that a user updated their presence / status. If you are looking for +/// the PresenceUpdate used in the IDENTIFY gateway event, see /// /// See /// (Same structure as ) pub struct PresenceUpdate { - // BUG: `user` should always be present, but the spacebar client does not send it. Temporary fix: - // make `user` optional. - pub user: Option, + pub user: PublicUser, #[serde(default)] pub guild_id: Option, pub status: UserStatus, #[serde(default)] pub activities: Vec, - // BUG: `client_status` should always be present, but the spacebar client does not send it. Temporary fix: - // make `client_status` optional. - pub client_status: Option, + pub client_status: ClientStatusObject, +} + +#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, WebSocketEvent)] +/// Sent to the gateway as part of [GatewayIdentifyPayload](crate::types::GatewayIdentifyPayload) +pub struct GatewayIdentifyPresenceUpdate { + #[serde(default)] + pub guild_id: Option, + pub status: UserStatus, + #[serde(default)] + pub activities: Vec, +} + +impl From for GatewayIdentifyPresenceUpdate { + fn from(value: PresenceUpdate) -> Self { + Self { + guild_id: value.guild_id, + status: value.status, + activities: value.activities, + } + } }