Add Relationship & related events
This commit is contained in:
parent
7367475d99
commit
ab902c5ef2
|
@ -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>,
|
||||
|
|
|
@ -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::*;
|
|
@ -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,
|
||||
}
|
|
@ -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 {}
|
||||
|
||||
|
|
|
@ -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 {}
|
Loading…
Reference in New Issue