forked from jmug/stoatchat
fix: store server id in redis and in room metadata to be able to delete voice state in all scenarios (#656)
* fix: store server id in redis values and in room metadata to be able to fully delete voice state in all scenarios * fix: undo logging change
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
use revolt_database::{Database, User, util::reference::Reference, voice::{VoiceClient, remove_user_from_voice_channels}};
|
||||
use revolt_database::{
|
||||
util::reference::Reference,
|
||||
voice::{remove_user_from_voice_channels, VoiceClient},
|
||||
Database, User,
|
||||
};
|
||||
use revolt_result::{create_error, Result};
|
||||
use rocket::State;
|
||||
use rocket_empty::EmptyResponse;
|
||||
@@ -21,7 +25,7 @@ pub async fn delete_bot(
|
||||
|
||||
bot.delete(db).await?;
|
||||
|
||||
remove_user_from_voice_channels(db, voice_client, &bot.id).await?;
|
||||
remove_user_from_voice_channels(voice_client, &bot.id).await?;
|
||||
|
||||
Ok(EmptyResponse)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use revolt_database::{
|
||||
AMQP, Channel, Database, PartialChannel, User, util::{permissions::DatabasePermissionQuery, reference::Reference}, voice::{
|
||||
VoiceClient, delete_voice_channel, is_in_voice_channel, remove_user_from_voice_channel
|
||||
}
|
||||
util::{permissions::DatabasePermissionQuery, reference::Reference},
|
||||
voice::{
|
||||
delete_voice_channel, is_in_voice_channel, remove_user_from_voice_channel,
|
||||
UserVoiceChannel, VoiceClient,
|
||||
},
|
||||
Channel, Database, PartialChannel, User, AMQP,
|
||||
};
|
||||
use revolt_models::v0;
|
||||
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
|
||||
@@ -54,15 +57,17 @@ pub async fn delete(
|
||||
)
|
||||
.await?;
|
||||
|
||||
if is_in_voice_channel(&user.id, channel.id()).await? {
|
||||
remove_user_from_voice_channel(db, voice_client, channel.id(), &user.id).await?;
|
||||
let user_voice_channel = UserVoiceChannel::from_channel(&channel);
|
||||
|
||||
if is_in_voice_channel(&user.id, &user_voice_channel).await? {
|
||||
remove_user_from_voice_channel(voice_client, &user_voice_channel, &user.id).await?;
|
||||
};
|
||||
}
|
||||
Channel::TextChannel { .. } => {
|
||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::ManageChannel)?;
|
||||
channel.delete(db).await?;
|
||||
|
||||
delete_voice_channel(voice_client, channel.id(), channel.server()).await?;
|
||||
delete_voice_channel(voice_client, &UserVoiceChannel::from_channel(&channel)).await?;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use revolt_database::{
|
||||
util::{permissions::DatabasePermissionQuery, reference::Reference},
|
||||
voice::{delete_voice_channel, VoiceClient},
|
||||
voice::{delete_voice_channel, UserVoiceChannel, VoiceClient},
|
||||
Channel, Database, File, PartialChannel, SystemMessage, User, AMQP,
|
||||
};
|
||||
use revolt_models::v0;
|
||||
@@ -260,7 +260,7 @@ pub async fn edit(
|
||||
.await?;
|
||||
|
||||
if channel.voice().is_none() {
|
||||
delete_voice_channel(voice_client, channel.id(), channel.server()).await?;
|
||||
delete_voice_channel(voice_client, &UserVoiceChannel::from_channel(&channel)).await?;
|
||||
}
|
||||
|
||||
Ok(Json(channel.into()))
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use revolt_database::{
|
||||
util::reference::Reference,
|
||||
voice::{is_in_voice_channel, remove_user_from_voice_channel, VoiceClient},
|
||||
Channel, Database, User, AMQP,
|
||||
AMQP, Channel, Database, User, util::reference::Reference, voice::{UserVoiceChannel, VoiceClient, is_in_voice_channel, remove_user_from_voice_channel}
|
||||
};
|
||||
use revolt_permissions::ChannelPermission;
|
||||
use revolt_result::{create_error, Result};
|
||||
@@ -54,8 +52,10 @@ pub async fn remove_member(
|
||||
return Err(create_error!(InvalidOperation));
|
||||
};
|
||||
|
||||
if is_in_voice_channel(&member.id, channel.id()).await? {
|
||||
remove_user_from_voice_channel(db, voice_client, channel.id(), &member.id).await?;
|
||||
let user_voice_channel = UserVoiceChannel::from_channel(&channel);
|
||||
|
||||
if is_in_voice_channel(member.id, &user_voice_channel).await? {
|
||||
remove_user_from_voice_channel(voice_client, &user_voice_channel, member.id).await?;
|
||||
};
|
||||
|
||||
Ok(EmptyResponse)
|
||||
|
||||
@@ -3,7 +3,8 @@ use revolt_database::{
|
||||
util::{permissions::perms, reference::Reference},
|
||||
voice::{
|
||||
delete_voice_state, get_channel_node, get_user_voice_channels, get_voice_channel_members,
|
||||
raise_if_in_voice, set_call_notification_recipients, set_channel_node, VoiceClient,
|
||||
raise_if_in_voice, set_call_notification_recipients, set_channel_node, UserVoiceChannel,
|
||||
VoiceClient,
|
||||
},
|
||||
Database, User,
|
||||
};
|
||||
@@ -50,7 +51,9 @@ pub async fn call(
|
||||
let current_permissions = calculate_channel_permissions(&mut permissions).await;
|
||||
current_permissions.throw_if_lacking_channel_permission(ChannelPermission::Connect)?;
|
||||
|
||||
if get_voice_channel_members(channel.id())
|
||||
let user_voice_channel = UserVoiceChannel::from_channel(&channel);
|
||||
|
||||
if get_voice_channel_members(&user_voice_channel)
|
||||
.await?
|
||||
.zip(voice_info.max_users)
|
||||
.is_some_and(|(ms, max_users)| ms.len() >= max_users)
|
||||
@@ -79,22 +82,18 @@ pub async fn call(
|
||||
// Finds and disconnects any existing voice connections by the user,
|
||||
// should only ever loop once but just to cover our backs.
|
||||
|
||||
for channel_id in get_user_voice_channels(&user.id).await? {
|
||||
if let Some(node) = get_channel_node(&channel_id).await? {
|
||||
for previous_channel in get_user_voice_channels(&user.id).await? {
|
||||
if let Some(node) = get_channel_node(&previous_channel.id).await? {
|
||||
// if this errors its just a mismatching state - ignore and proceed to still delete our state
|
||||
let _ = voice_client.remove_user(&node, &user.id, &channel_id).await;
|
||||
let _ = voice_client
|
||||
.remove_user(&node, &user.id, &previous_channel.id)
|
||||
.await;
|
||||
};
|
||||
|
||||
let channel = Reference::from_unchecked(&channel_id)
|
||||
.as_channel(db)
|
||||
.await;
|
||||
|
||||
if channel.is_ok() {
|
||||
delete_voice_state(&channel_id, channel.unwrap().server(), &user.id).await?;
|
||||
}
|
||||
delete_voice_state(&previous_channel, &user.id).await?;
|
||||
}
|
||||
} else {
|
||||
raise_if_in_voice(&user, channel.id()).await?;
|
||||
raise_if_in_voice(&user, &user_voice_channel).await?;
|
||||
}
|
||||
|
||||
let token = voice_client
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use revolt_database::{
|
||||
util::reference::Reference,
|
||||
voice::{get_voice_state, VoiceClient},
|
||||
voice::{get_voice_state, UserVoiceChannel, VoiceClient},
|
||||
Channel, Database, User, AMQP,
|
||||
};
|
||||
use revolt_result::{create_error, Result, ToRevoltError};
|
||||
@@ -32,9 +32,15 @@ pub async fn stop_ring(
|
||||
return Err(create_error!(NoEffect));
|
||||
}
|
||||
|
||||
if get_voice_state(channel.id(), None, &user.id)
|
||||
.await?
|
||||
.is_none()
|
||||
if get_voice_state(
|
||||
&UserVoiceChannel {
|
||||
id: channel.id().to_string(),
|
||||
server_id: None,
|
||||
},
|
||||
&user.id,
|
||||
)
|
||||
.await?
|
||||
.is_none()
|
||||
{
|
||||
return Err(create_error!(NotConnected));
|
||||
}
|
||||
@@ -46,7 +52,7 @@ pub async fn stop_ring(
|
||||
_ => return Err(create_error!(NoEffect)),
|
||||
};
|
||||
|
||||
if members.iter().any(|m| &target_user.id == m) {
|
||||
if members.iter().any(|m| target_user.id == m) {
|
||||
if let Err(e) = amqp
|
||||
.dm_call_updated(
|
||||
&user.id,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use revolt_database::{
|
||||
util::{permissions::DatabasePermissionQuery, reference::Reference},
|
||||
voice::{get_user_voice_channel_in_server, remove_user_from_voice_channel, VoiceClient},
|
||||
voice::{
|
||||
get_user_voice_channel_in_server, remove_user_from_voice_channel, UserVoiceChannel,
|
||||
VoiceClient,
|
||||
},
|
||||
Database, RemovalIntention, ServerBan, User,
|
||||
};
|
||||
use revolt_models::v0;
|
||||
@@ -58,8 +61,16 @@ pub async fn ban(
|
||||
.await?;
|
||||
|
||||
// If the member is in a voice channel while banned kick them from the voice channel
|
||||
if let Some(channel_id) = get_user_voice_channel_in_server(&target.id, &server.id).await? {
|
||||
remove_user_from_voice_channel(db, voice_client, &channel_id, &target.id).await?;
|
||||
if let Some(channel_id) = get_user_voice_channel_in_server(target.id, &server.id).await? {
|
||||
remove_user_from_voice_channel(
|
||||
voice_client,
|
||||
&UserVoiceChannel {
|
||||
id: channel_id,
|
||||
server_id: Some(server.id.clone()),
|
||||
},
|
||||
target.id,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use revolt_database::{
|
||||
voice::{
|
||||
get_channel_node, get_user_voice_channel_in_server, set_channel_node,
|
||||
set_user_moved_from_voice, set_user_moved_to_voice, sync_user_voice_permissions,
|
||||
VoiceClient,
|
||||
UserVoiceChannel, VoiceClient,
|
||||
},
|
||||
Database, File, PartialMember, User,
|
||||
};
|
||||
@@ -52,7 +52,9 @@ pub async fn edit(
|
||||
let permissions = calculate_server_permissions(&mut query).await;
|
||||
|
||||
// Fetch target permissions
|
||||
let mut target_query = DatabasePermissionQuery::new(db, &target_user).server(&server).member(&member);
|
||||
let mut target_query = DatabasePermissionQuery::new(db, &target_user)
|
||||
.server(&server)
|
||||
.member(&member);
|
||||
let target_permissions = calculate_server_permissions(&mut target_query).await;
|
||||
|
||||
// Check permissions in server
|
||||
@@ -83,7 +85,7 @@ pub async fn edit(
|
||||
}
|
||||
|
||||
if target_permissions.has_channel_permission(ChannelPermission::TimeoutMembers) {
|
||||
return Err(create_error!(IsElevated))
|
||||
return Err(create_error!(IsElevated));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +101,7 @@ pub async fn edit(
|
||||
}
|
||||
|
||||
if data.voice_channel.is_some() && data.remove.contains(&FieldsMember::VoiceChannel) {
|
||||
return Err(create_error!(InvalidOperation))
|
||||
return Err(create_error!(InvalidOperation));
|
||||
}
|
||||
|
||||
if data.voice_channel.is_some() || data.remove.contains(&FieldsMember::VoiceChannel) {
|
||||
@@ -217,8 +219,19 @@ pub async fn edit(
|
||||
}
|
||||
};
|
||||
|
||||
set_user_moved_from_voice(&channel, new_voice_channel.id(), &target_user.id).await?;
|
||||
set_user_moved_to_voice(new_voice_channel.id(), &channel, &target_user.id).await?;
|
||||
let new_user_voice_channel = UserVoiceChannel::from_channel(&new_voice_channel);
|
||||
let old_user_voice_channel = UserVoiceChannel {
|
||||
id: channel.clone(),
|
||||
server_id: new_user_voice_channel.server_id.clone(),
|
||||
};
|
||||
|
||||
set_user_moved_from_voice(&channel, &new_user_voice_channel, &target_user.id).await?;
|
||||
set_user_moved_to_voice(
|
||||
new_voice_channel.id(),
|
||||
&old_user_voice_channel,
|
||||
&target_user.id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let mut query = perms(db, &target_user).channel(&new_voice_channel);
|
||||
let permissions = calculate_channel_permissions(&mut query).await;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use revolt_database::{
|
||||
util::{permissions::DatabasePermissionQuery, reference::Reference},
|
||||
voice::{get_user_voice_channel_in_server, remove_user_from_voice_channel, VoiceClient},
|
||||
voice::{
|
||||
get_user_voice_channel_in_server, remove_user_from_voice_channel, UserVoiceChannel,
|
||||
VoiceClient,
|
||||
},
|
||||
Database, RemovalIntention, User,
|
||||
};
|
||||
use revolt_permissions::{calculate_server_permissions, ChannelPermission};
|
||||
@@ -46,8 +49,16 @@ pub async fn kick(
|
||||
.remove(db, &server, RemovalIntention::Kick, false)
|
||||
.await?;
|
||||
|
||||
if let Some(channel_id) = get_user_voice_channel_in_server(&target.id, &server.id).await? {
|
||||
remove_user_from_voice_channel(db, voice_client, &channel_id, &target.id).await?;
|
||||
if let Some(channel_id) = get_user_voice_channel_in_server(target.id, &server.id).await? {
|
||||
remove_user_from_voice_channel(
|
||||
voice_client,
|
||||
&UserVoiceChannel {
|
||||
id: channel_id,
|
||||
server_id: Some(server.id.clone()),
|
||||
},
|
||||
target.id,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
|
||||
Ok(EmptyResponse)
|
||||
|
||||
@@ -2,7 +2,7 @@ use revolt_database::{
|
||||
util::reference::Reference,
|
||||
voice::{
|
||||
delete_voice_channel, get_user_voice_channel_in_server, remove_user_from_voice_channel,
|
||||
VoiceClient,
|
||||
UserVoiceChannel, VoiceClient,
|
||||
},
|
||||
Database, RemovalIntention, User,
|
||||
};
|
||||
@@ -29,13 +29,28 @@ pub async fn delete(
|
||||
|
||||
if server.owner == user.id {
|
||||
for channel_id in &server.channels {
|
||||
delete_voice_channel(voice_client, channel_id, Some(&server.id)).await?;
|
||||
delete_voice_channel(
|
||||
voice_client,
|
||||
&UserVoiceChannel {
|
||||
id: channel_id.clone(),
|
||||
server_id: Some(server.id.clone()),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
server.delete(db).await
|
||||
} else {
|
||||
if let Some(channel_id) = get_user_voice_channel_in_server(&user.id, &server.id).await? {
|
||||
remove_user_from_voice_channel(db, voice_client, &channel_id, &user.id).await?;
|
||||
remove_user_from_voice_channel(
|
||||
voice_client,
|
||||
&UserVoiceChannel {
|
||||
id: channel_id,
|
||||
server_id: Some(server.id.clone()),
|
||||
},
|
||||
&user.id,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
|
||||
member
|
||||
|
||||
Reference in New Issue
Block a user