mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 21:47:02 +00:00
Fix various issues relating to voice channels.
This commit is contained in:
@@ -232,59 +232,63 @@ impl Channel {
|
||||
}
|
||||
|
||||
// Remove from server object.
|
||||
if let Channel::TextChannel { server, .. } = &self {
|
||||
let server = Ref::from_unchecked(server.clone()).fetch_server().await?;
|
||||
let mut update = doc! {
|
||||
"$pull": {
|
||||
"channels": id
|
||||
}
|
||||
};
|
||||
match &self {
|
||||
Channel::TextChannel { server, .. }
|
||||
| Channel::VoiceChannel { server, .. } => {
|
||||
let server = Ref::from_unchecked(server.clone()).fetch_server().await?;
|
||||
let mut update = doc! {
|
||||
"$pull": {
|
||||
"channels": id
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(sys) = &server.system_messages {
|
||||
let mut unset = doc! {};
|
||||
if let Some(sys) = &server.system_messages {
|
||||
let mut unset = doc! {};
|
||||
|
||||
if let Some(cid) = &sys.user_joined {
|
||||
if id == cid {
|
||||
unset.insert("system_messages.user_joined", 1);
|
||||
if let Some(cid) = &sys.user_joined {
|
||||
if id == cid {
|
||||
unset.insert("system_messages.user_joined", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cid) = &sys.user_left {
|
||||
if id == cid {
|
||||
unset.insert("system_messages.user_left", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cid) = &sys.user_kicked {
|
||||
if id == cid {
|
||||
unset.insert("system_messages.user_kicked", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cid) = &sys.user_banned {
|
||||
if id == cid {
|
||||
unset.insert("system_messages.user_banned", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if unset.len() > 0 {
|
||||
update.insert("$unset", unset);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cid) = &sys.user_left {
|
||||
if id == cid {
|
||||
unset.insert("system_messages.user_left", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cid) = &sys.user_kicked {
|
||||
if id == cid {
|
||||
unset.insert("system_messages.user_kicked", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cid) = &sys.user_banned {
|
||||
if id == cid {
|
||||
unset.insert("system_messages.user_banned", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if unset.len() > 0 {
|
||||
update.insert("$unset", unset);
|
||||
}
|
||||
}
|
||||
|
||||
get_collection("servers")
|
||||
.update_one(
|
||||
doc! {
|
||||
"_id": server.id
|
||||
},
|
||||
update,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "servers",
|
||||
})?;
|
||||
get_collection("servers")
|
||||
.update_one(
|
||||
doc! {
|
||||
"_id": server.id
|
||||
},
|
||||
update,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "servers",
|
||||
})?;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Finally, delete the channel object.
|
||||
|
||||
@@ -45,7 +45,9 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
}
|
||||
|
||||
match &target {
|
||||
Channel::Group { id, icon, .. } | Channel::TextChannel { id, icon, .. } => {
|
||||
Channel::Group { id, icon, .. }
|
||||
| Channel::TextChannel { id, icon, .. }
|
||||
| Channel::VoiceChannel { id, icon, .. } => {
|
||||
let mut set = doc! {};
|
||||
let mut unset = doc! {};
|
||||
|
||||
|
||||
@@ -35,29 +35,24 @@ pub async fn req(target: Ref) -> Result<JsonValue> {
|
||||
let channel = Ref::from_unchecked(channel).fetch_channel().await?;
|
||||
let creator = Ref::from_unchecked(creator).fetch_user().await?;
|
||||
|
||||
if let Channel::TextChannel {
|
||||
id,
|
||||
server,
|
||||
name,
|
||||
description,
|
||||
..
|
||||
} = channel
|
||||
{
|
||||
let server = Ref::from_unchecked(server).fetch_server().await?;
|
||||
|
||||
Ok(json!(InviteResponse::Server {
|
||||
server_id: server.id,
|
||||
server_name: server.name,
|
||||
server_icon: server.icon,
|
||||
server_banner: server.banner,
|
||||
channel_id: id,
|
||||
channel_name: name,
|
||||
channel_description: description,
|
||||
user_name: creator.username,
|
||||
user_avatar: creator.avatar
|
||||
}))
|
||||
} else {
|
||||
unreachable!()
|
||||
match channel {
|
||||
Channel::TextChannel { id, server, name, description, .. }
|
||||
| Channel::VoiceChannel { id, server, name, description, .. } => {
|
||||
let server = Ref::from_unchecked(server).fetch_server().await?;
|
||||
|
||||
Ok(json!(InviteResponse::Server {
|
||||
server_id: server.id,
|
||||
server_name: server.name,
|
||||
server_icon: server.icon,
|
||||
server_banner: server.banner,
|
||||
channel_id: id,
|
||||
channel_name: name,
|
||||
channel_description: description,
|
||||
user_name: creator.username,
|
||||
user_avatar: creator.avatar
|
||||
}))
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
||||
@@ -10,10 +10,12 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
match target {
|
||||
Invite::Server { channel, .. } => {
|
||||
let channel = Ref::from_unchecked(channel).fetch_channel().await?;
|
||||
let server = if let Channel::TextChannel { server, .. } = &channel {
|
||||
Ref::from_unchecked(server.clone()).fetch_server().await?
|
||||
} else {
|
||||
unreachable!()
|
||||
let server = match &channel {
|
||||
Channel::TextChannel { server, .. }
|
||||
| Channel::VoiceChannel { server, .. } => {
|
||||
Ref::from_unchecked(server.clone()).fetch_server().await?
|
||||
}
|
||||
_ => unreachable!()
|
||||
};
|
||||
|
||||
server.join_member(&user.id).await?;
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub const VERSION: &str = "0.5.1-alpha.0";
|
||||
pub const VERSION: &str = "0.5.1-alpha.0-patch.0";
|
||||
|
||||
Reference in New Issue
Block a user