chore: cleanup code

This commit is contained in:
Zomatree
2025-08-04 03:20:08 +01:00
parent 10c9682bba
commit a770d5822a
4 changed files with 32 additions and 22 deletions

View File

@@ -89,7 +89,7 @@ impl VoiceClient {
let room = self.get_node(node)?;
let voice = match channel {
Channel::DirectMessage { .. } => Some(Cow::Owned(v0::VoiceInformation::default())),
Channel::DirectMessage { .. } | Channel::Group { .. } => Some(Cow::Owned(v0::VoiceInformation::default())),
Channel::TextChannel { voice: Some(voice), .. } => Some(Cow::Borrowed(voice)),
_ => None
}
@@ -99,7 +99,7 @@ impl VoiceClient {
.create_room(
channel.id(),
CreateRoomOptions {
max_participants: voice.max_users.unwrap_or(u32::MAX),
max_participants: voice.max_users.unwrap_or(0),
empty_timeout: 5 * 60, // 5 minutes,
..Default::default()
},

View File

@@ -63,7 +63,8 @@ async fn ingress(db: &State<Database>, node: &str, voice_client: &State<VoiceCli
let config = revolt_config::config().await;
let node_info = config.api.livekit.nodes.get(node)
.ok_or_else(|| create_error!(NotAuthenticated))?;
.to_internal_error()
.inspect_err(|_| log::error!("Unknown node {node}, make sure livekit has the correct node name set."))?;
let webhook_receiver = WebhookReceiver::new(TokenVerifier::with_api_key(&node_info.key, &node_info.secret));
let event = webhook_receiver.receive(body, &auth_header).to_internal_error()?;

View File

@@ -1,5 +1,5 @@
use revolt_database::{
util::{permissions::DatabasePermissionQuery, reference::Reference}, voice::{delete_voice_state, get_channel_node, get_voice_channel_members, VoiceClient}, Channel, Database, PartialChannel, User, AMQP
util::{permissions::DatabasePermissionQuery, reference::Reference}, voice::{delete_voice_state, get_channel_node, get_voice_channel_members, is_in_voice_channel, VoiceClient}, Channel, Database, PartialChannel, User, AMQP
};
use revolt_models::v0;
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
@@ -39,27 +39,36 @@ pub async fn delete(
vec![],
)
.await?,
Channel::Group { .. } => channel
.remove_user_from_group(
db,
amqp,
&user,
None,
options.leave_silently.unwrap_or_default(),
)
.await?,
Channel::Group { .. } => {
channel
.remove_user_from_group(
db,
amqp,
&user,
None,
options.leave_silently.unwrap_or_default(),
)
.await?;
if is_in_voice_channel(&user.id, channel.id()).await? {
let node = get_channel_node(channel.id()).await?.unwrap();
voice_client.remove_user(&node, &user.id, channel.id()).await?;
delete_voice_state(channel.id(), None, &user.id).await?;
};
},
Channel::TextChannel { .. } | Channel::VoiceChannel { .. } => {
permissions.throw_if_lacking_channel_permission(ChannelPermission::ManageChannel)?;
channel.delete(db).await?
}
};
channel.delete(db).await?;
if let Some(users) = get_voice_channel_members(channel.id()).await? {
let node = get_channel_node(channel.id()).await?.unwrap();
if let Some(users) = get_voice_channel_members(channel.id()).await? {
let node = get_channel_node(channel.id()).await?.unwrap();
for user in users {
voice_client.remove_user(&node, &user, channel.id()).await?;
delete_voice_state(channel.id(), channel.server(), &user).await?;
for user in users {
voice_client.remove_user(&node, &user, channel.id()).await?;
delete_voice_state(channel.id(), channel.server(), &user).await?;
}
};
}
};

View File

@@ -36,7 +36,7 @@ pub async fn remove_member(
return Err(create_error!(CannotRemoveYourself));
}
if !recipients.iter().any(|x| *x == member.id) {
if !recipients.contains(&member.id) {
return Err(create_error!(NotInGroup));
}