forked from jmug/stoatchat
fix: no node state set on channel creation (#653)
* fix: no node state set on channel creation Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * Update "join_call" logic to handle issue of "user is already connected to a channel that cannot be found" Fixes stoatchat/for-web#951 Signed-off-by: Chris Hultin <chris.hultin@gmail.com> * feat: remove node key when channel is empty or deleted --------- Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> Signed-off-by: Chris Hultin <chris.hultin@gmail.com> Co-authored-by: Chris Hultin <chris.hultin@gmail.com>
This commit is contained in:
@@ -16,7 +16,9 @@ mod voice_client;
|
|||||||
pub use voice_client::VoiceClient;
|
pub use voice_client::VoiceClient;
|
||||||
|
|
||||||
async fn get_connection() -> Result<Conn> {
|
async fn get_connection() -> Result<Conn> {
|
||||||
_get_connection().await.map_err(|_| create_error!(InternalError))
|
_get_connection()
|
||||||
|
.await
|
||||||
|
.map_err(|_| create_error!(InternalError))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn raise_if_in_voice(user: &User, channel_id: &str) -> Result<()> {
|
pub async fn raise_if_in_voice(user: &User, channel_id: &str) -> Result<()> {
|
||||||
@@ -59,6 +61,14 @@ pub async fn get_channel_node(channel: &str) -> Result<Option<String>> {
|
|||||||
.to_internal_error()
|
.to_internal_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_channel_node(channel: &str) -> Result<()> {
|
||||||
|
get_connection()
|
||||||
|
.await?
|
||||||
|
.del(format!("node:{channel}"))
|
||||||
|
.await
|
||||||
|
.to_internal_error()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_user_voice_channels(user_id: &str) -> Result<Vec<String>> {
|
pub async fn get_user_voice_channels(user_id: &str) -> Result<Vec<String>> {
|
||||||
get_connection()
|
get_connection()
|
||||||
.await?
|
.await?
|
||||||
@@ -226,6 +236,7 @@ pub async fn delete_channel_voice_state(
|
|||||||
|
|
||||||
let mut pipeline = Pipeline::new();
|
let mut pipeline = Pipeline::new();
|
||||||
pipeline.del(format!("vc_members:{channel_id}"));
|
pipeline.del(format!("vc_members:{channel_id}"));
|
||||||
|
pipeline.del(format!("node:{channel_id}"));
|
||||||
|
|
||||||
for user_id in user_ids {
|
for user_id in user_ids {
|
||||||
let unique_key = format!("{user_id}:{parent_id}");
|
let unique_key = format!("{user_id}:{parent_id}");
|
||||||
@@ -567,15 +578,24 @@ pub async fn get_call_notification_recipients(
|
|||||||
.to_internal_error()
|
.to_internal_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_user_from_voice_channels(db: &Database, voice_client: &VoiceClient, user_id: &str) -> Result<()> {
|
pub async fn remove_user_from_voice_channels(
|
||||||
|
db: &Database,
|
||||||
|
voice_client: &VoiceClient,
|
||||||
|
user_id: &str,
|
||||||
|
) -> Result<()> {
|
||||||
for channel_id in get_user_voice_channels(user_id).await? {
|
for channel_id in get_user_voice_channels(user_id).await? {
|
||||||
remove_user_from_voice_channel(db, voice_client, &channel_id, user_id).await?;
|
remove_user_from_voice_channel(db, voice_client, &channel_id, user_id).await?;
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_user_from_voice_channel(db: &Database, voice_client: &VoiceClient, channel_id: &str, user_id: &str) -> Result<()> {
|
pub async fn remove_user_from_voice_channel(
|
||||||
|
db: &Database,
|
||||||
|
voice_client: &VoiceClient,
|
||||||
|
channel_id: &str,
|
||||||
|
user_id: &str,
|
||||||
|
) -> Result<()> {
|
||||||
if let Some(node) = get_channel_node(channel_id).await? {
|
if let Some(node) = get_channel_node(channel_id).await? {
|
||||||
let _ = voice_client.remove_user(&node, user_id, channel_id).await;
|
let _ = voice_client.remove_user(&node, user_id, channel_id).await;
|
||||||
}
|
}
|
||||||
@@ -587,7 +607,11 @@ pub async fn remove_user_from_voice_channel(db: &Database, voice_client: &VoiceC
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_voice_channel(voice_client: &VoiceClient, channel_id: &str, server_id: Option<&str>) -> Result<()> {
|
pub async fn delete_voice_channel(
|
||||||
|
voice_client: &VoiceClient,
|
||||||
|
channel_id: &str,
|
||||||
|
server_id: Option<&str>,
|
||||||
|
) -> Result<()> {
|
||||||
if let Some(users) = get_voice_channel_members(channel_id).await? {
|
if let Some(users) = get_voice_channel_members(channel_id).await? {
|
||||||
let node = get_channel_node(channel_id).await?.unwrap();
|
let node = get_channel_node(channel_id).await?.unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ use revolt_database::{
|
|||||||
iso8601_timestamp::{Duration, Timestamp},
|
iso8601_timestamp::{Duration, Timestamp},
|
||||||
util::reference::Reference,
|
util::reference::Reference,
|
||||||
voice::{
|
voice::{
|
||||||
create_voice_state, delete_voice_state,
|
create_voice_state, delete_channel_node, delete_voice_state, get_user_moved_from_voice,
|
||||||
get_user_moved_from_voice, get_user_moved_to_voice,
|
get_user_moved_to_voice, get_voice_channel_members, update_voice_state_tracks, VoiceClient,
|
||||||
update_voice_state_tracks, VoiceClient,
|
|
||||||
},
|
},
|
||||||
Database, AMQP,
|
Database, AMQP,
|
||||||
};
|
};
|
||||||
@@ -160,6 +159,8 @@ pub async fn ingress(
|
|||||||
// let members = get_voice_channel_members(channel_id).await?;
|
// let members = get_voice_channel_members(channel_id).await?;
|
||||||
|
|
||||||
// if members.is_none_or(|m| m.is_empty()) {
|
// if members.is_none_or(|m| m.is_empty()) {
|
||||||
|
// delete_channel_node(channel_id).await?;
|
||||||
|
//
|
||||||
// // The channel is empty so send out an "end" message for ringing
|
// // The channel is empty so send out an "end" message for ringing
|
||||||
// if let Err(e) = amqp
|
// if let Err(e) = amqp
|
||||||
// .dm_call_updated(user_id, channel_id, None, true, None)
|
// .dm_call_updated(user_id, channel_id, None, true, None)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use revolt_database::{
|
|||||||
util::{permissions::perms, reference::Reference},
|
util::{permissions::perms, reference::Reference},
|
||||||
voice::{
|
voice::{
|
||||||
delete_voice_state, get_channel_node, get_user_voice_channels, get_voice_channel_members,
|
delete_voice_state, get_channel_node, get_user_voice_channels, get_voice_channel_members,
|
||||||
raise_if_in_voice, set_call_notification_recipients, VoiceClient,
|
raise_if_in_voice, set_call_notification_recipients, set_channel_node, VoiceClient,
|
||||||
},
|
},
|
||||||
Database, User,
|
Database, User,
|
||||||
};
|
};
|
||||||
@@ -60,6 +60,7 @@ pub async fn call(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let existing_node = get_channel_node(channel.id()).await?;
|
let existing_node = get_channel_node(channel.id()).await?;
|
||||||
|
let has_existing_node = existing_node.is_some(); // we move existing_node in the next statement so this is the quickest way to know if we need to set it.
|
||||||
|
|
||||||
let node = existing_node
|
let node = existing_node
|
||||||
.or(node)
|
.or(node)
|
||||||
@@ -86,9 +87,11 @@ pub async fn call(
|
|||||||
|
|
||||||
let channel = Reference::from_unchecked(&channel_id)
|
let channel = Reference::from_unchecked(&channel_id)
|
||||||
.as_channel(db)
|
.as_channel(db)
|
||||||
.await?;
|
.await;
|
||||||
|
|
||||||
delete_voice_state(&channel_id, channel.server(), &user.id).await?;
|
if channel.is_ok() {
|
||||||
|
delete_voice_state(&channel_id, channel.unwrap().server(), &user.id).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
raise_if_in_voice(&user, channel.id()).await?;
|
raise_if_in_voice(&user, channel.id()).await?;
|
||||||
@@ -100,6 +103,10 @@ pub async fn call(
|
|||||||
|
|
||||||
let room = voice_client.create_room(&node, &channel).await?;
|
let room = voice_client.create_room(&node, &channel).await?;
|
||||||
|
|
||||||
|
if !has_existing_node {
|
||||||
|
set_channel_node(channel.id(), &node).await?;
|
||||||
|
}
|
||||||
|
|
||||||
log::debug!("Created room {}", room.name);
|
log::debug!("Created room {}", room.name);
|
||||||
|
|
||||||
if let Some(recipients) = recipients {
|
if let Some(recipients) = recipients {
|
||||||
|
|||||||
Reference in New Issue
Block a user