Add Relationship & related events

This commit is contained in:
kozabrada123 2023-05-27 16:03:23 +02:00
parent e2d07ec7a6
commit 51c786661e
5 changed files with 68 additions and 0 deletions

View File

@ -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<types::TypingStartEvent>,
}
#[derive(Default, Debug)]
pub struct Relationship {
pub add: GatewayEvent<types::RelationshipAdd>,
pub remove: GatewayEvent<types::RelationshipRemove>,
}
#[derive(Default, Debug)]
pub struct Channel {
pub create: GatewayEvent<types::ChannelCreate>,

View File

@ -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::*;

View File

@ -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<String>,
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,
}

View File

@ -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 {}

View File

@ -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 {}