diff --git a/src/gateway.rs b/src/gateway.rs index 0ccf220..4105f92 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -442,6 +442,14 @@ impl Gateway { let new_data: types::PresenceUpdate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); self.events.lock().await.user.presence_update.update_data(new_data).await; } + "RELATIONSHIP_ADD" => { + let new_data: types::RelationshipAdd = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); + self.events.lock().await.relationship.add.update_data(new_data).await; + } + "RELATIONSHIP_REMOVE" => { + let new_data: types::RelationshipRemove = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); + self.events.lock().await.relationship.remove.update_data(new_data).await; + } "STAGE_INSTANCE_CREATE" => {} "STAGE_INSTANCE_UPDATE" => {} "STAGE_INSTANCE_DELETE" => {} @@ -687,6 +695,7 @@ mod events { pub session: Session, pub message: Message, pub user: User, + pub relationship: Relationship, pub channel: Channel, pub thread: Thread, pub guild: Guild, @@ -726,6 +735,12 @@ mod events { pub typing_start_event: GatewayEvent, } + #[derive(Default, Debug)] + pub struct Relationship { + pub add: GatewayEvent, + pub remove: GatewayEvent, + } + #[derive(Default, Debug)] pub struct Channel { pub create: GatewayEvent, diff --git a/src/types/entities/mod.rs b/src/types/entities/mod.rs index 28f11ad..a34246e 100644 --- a/src/types/entities/mod.rs +++ b/src/types/entities/mod.rs @@ -17,6 +17,7 @@ mod user_settings; mod voice_state; mod webhook; mod audit_log; +mod relationship; pub use application::*; pub use attachment::*; @@ -37,3 +38,4 @@ pub use user_settings::*; pub use voice_state::*; pub use webhook::*; pub use audit_log::*; +pub use relationship::*; \ No newline at end of file diff --git a/src/types/entities/relationship.rs b/src/types/entities/relationship.rs new file mode 100644 index 0000000..fc6d78d --- /dev/null +++ b/src/types/entities/relationship.rs @@ -0,0 +1,27 @@ +use serde::{Deserialize, Serialize}; +use serde_repr::{Serialize_repr, Deserialize_repr}; + +use crate::types::Snowflake; + +use super::PublicUser; + +#[derive(Debug, Deserialize, Serialize, Clone, Default)] +/// See https://docs.spacebar.chat/routes/#get-/users/@me/relationships/ +pub struct Relationship { + pub id: Snowflake, + #[serde(rename = "type")] + pub relationship_type: RelationshipType, + pub nickname: Option, + pub user: PublicUser +} + +#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)] +#[repr(u8)] +/// See https://github.com/spacebarchat/server/blob/60394d8c43904ff17935d6edbbfb09ecd479570a/src/util/entities/Relationship.ts#L30 +pub enum RelationshipType { + Outgoing = 4, + Incoming = 3, + Blocked = 2, + #[default] + Friends = 1, +} \ No newline at end of file diff --git a/src/types/events/mod.rs b/src/types/events/mod.rs index 6979e1d..514f387 100644 --- a/src/types/events/mod.rs +++ b/src/types/events/mod.rs @@ -20,6 +20,7 @@ mod integration; mod invite; mod call; mod lazy_request; +mod relationship; pub use channel::*; pub use guild::*; @@ -41,6 +42,7 @@ pub use integration::*; pub use invite::*; pub use call::*; pub use lazy_request::*; +pub use relationship::*; pub trait WebSocketEvent {} diff --git a/src/types/events/relationship.rs b/src/types/events/relationship.rs new file mode 100644 index 0000000..f8c0dff --- /dev/null +++ b/src/types/events/relationship.rs @@ -0,0 +1,22 @@ +use crate::types::{events::WebSocketEvent, Relationship, Snowflake, RelationshipType}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize, Default)] +/// See https://github.com/spacebarchat/server/issues/204 +pub struct RelationshipAdd { + #[serde(flatten)] + pub relationship: Relationship, + pub should_notify: bool, +} + +impl WebSocketEvent for RelationshipAdd {} + +#[derive(Debug, Deserialize, Serialize, Default)] +/// See https://github.com/spacebarchat/server/issues/203 +pub struct RelationshipRemove { + pub id: Snowflake, + #[serde(rename = "type")] + pub relationship_type: RelationshipType, +} + +impl WebSocketEvent for RelationshipRemove {} \ No newline at end of file