Servers: Core objects required. Includes creation. Bump version to 0.5.0.

This commit is contained in:
Paul
2021-06-01 17:09:31 +01:00
parent a4c1fee4cc
commit bff72fa6c3
23 changed files with 415 additions and 59 deletions

View File

@@ -39,6 +39,12 @@ pub enum RemoveChannelField {
Icon,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum RemoveServerField {
Icon,
Banner,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum ClientboundNotification {
@@ -46,6 +52,7 @@ pub enum ClientboundNotification {
Authenticated,
Ready {
users: Vec<User>,
servers: Vec<Server>,
channels: Vec<Channel>,
},
@@ -67,6 +74,9 @@ pub enum ClientboundNotification {
#[serde(skip_serializing_if = "Option::is_none")]
clear: Option<RemoveChannelField>,
},
ChannelDelete {
id: String,
},
ChannelGroupJoin {
id: String,
user: String,
@@ -75,9 +85,6 @@ pub enum ClientboundNotification {
id: String,
user: String,
},
ChannelDelete {
id: String,
},
ChannelStartTyping {
id: String,
user: String,
@@ -87,6 +94,25 @@ pub enum ClientboundNotification {
user: String,
},
ServerCreate(Server),
ServerUpdate {
id: String,
data: JsonValue,
#[serde(skip_serializing_if = "Option::is_none")]
clear: Option<RemoveServerField>,
},
ServerDelete {
id: String,
},
ServerMemberJoin {
id: String,
user: String,
},
ServerMemberLeave {
id: String,
user: String,
},
UserUpdate {
id: String,
data: JsonValue,
@@ -104,8 +130,8 @@ pub enum ClientboundNotification {
},
UserSettingsUpdate {
id: String,
update: JsonValue
}
update: JsonValue,
},
}
impl ClientboundNotification {
@@ -137,6 +163,12 @@ pub fn prehandle_hook(notification: &ClientboundNotification) {
}
}
}
ClientboundNotification::ServerMemberJoin { id, user } => {
subscribe_if_exists(user.clone(), id.clone()).ok();
}
ClientboundNotification::ServerCreate(server) => {
subscribe_if_exists(server.owner.clone(), server.id.clone()).ok();
}
ClientboundNotification::UserRelationship { id, user, status } => {
if status != &RelationshipStatus::None {
subscribe_if_exists(id.clone(), user.id.clone()).ok();
@@ -151,6 +183,21 @@ pub fn posthandle_hook(notification: &ClientboundNotification) {
ClientboundNotification::ChannelDelete { id } => {
get_hive().hive.drop_topic(&id).ok();
}
ClientboundNotification::ChannelGroupLeave { id, user } => {
get_hive()
.hive
.unsubscribe(&user.to_string(), &id.to_string())
.ok();
}
ClientboundNotification::ServerDelete { id } => {
get_hive().hive.drop_topic(&id).ok();
}
ClientboundNotification::ServerMemberLeave { id, user } => {
get_hive()
.hive
.unsubscribe(&user.to_string(), &id.to_string())
.ok();
}
ClientboundNotification::UserRelationship { id, user, status } => {
if status == &RelationshipStatus::None {
get_hive()
@@ -159,12 +206,6 @@ pub fn posthandle_hook(notification: &ClientboundNotification) {
.ok();
}
}
ClientboundNotification::ChannelGroupLeave { id, user } => {
get_hive()
.hive
.unsubscribe(&user.to_string(), &id.to_string())
.ok();
}
_ => {}
}
}