Compare commits
9
Commits
20251012-1
...
20251023-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db58818bab | ||
|
|
b4ea75cf1a | ||
|
|
8d8e8f2cf1 | ||
|
|
db19957de5 | ||
|
|
20a4816235 | ||
|
|
6ba48a0197 | ||
|
|
47002ec81c | ||
|
|
6ab264eb36 | ||
|
|
59af536e29 |
Generated
+1
@@ -6905,6 +6905,7 @@ dependencies = [
|
||||
"revolt_rocket_okapi",
|
||||
"rocket",
|
||||
"schemars 0.8.22",
|
||||
"sentry",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"utoipa",
|
||||
|
||||
@@ -295,7 +295,9 @@ pub enum EventV1 {
|
||||
},
|
||||
UserMoveVoiceChannel {
|
||||
node: String,
|
||||
token: String
|
||||
from: String,
|
||||
to: String,
|
||||
token: String,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ struct MigrationInfo {
|
||||
revision: i32,
|
||||
}
|
||||
|
||||
pub const LATEST_REVISION: i32 = 48; // MUST BE +1 to last migration
|
||||
pub const LATEST_REVISION: i32 = 49; // MUST BE +1 to last migration
|
||||
|
||||
pub async fn migrate_database(db: &MongoDb) {
|
||||
let migrations = db.col::<Document>("migrations");
|
||||
@@ -1246,8 +1246,8 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
||||
.expect("Failed to update voice channels");
|
||||
};
|
||||
|
||||
if revision <= 47 {
|
||||
info!("Running migration [revision 47 / 29-04-2025]: Add Video to default permissions");
|
||||
if revision <= 48 {
|
||||
info!("Running migration [revision 48 / 22-10-2025]: Add Video + Listen to default permissions");
|
||||
|
||||
db.col::<Document>("servers")
|
||||
.update_many(
|
||||
@@ -1255,7 +1255,7 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
||||
doc! {
|
||||
"$bit": {
|
||||
"default_permissions": {
|
||||
"or": ChannelPermission::Video as i64
|
||||
"or": (ChannelPermission::Video + ChannelPermission::Speak + ChannelPermission::Listen) as i64
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ mod voice_client;
|
||||
pub use voice_client::VoiceClient;
|
||||
|
||||
async fn get_connection() -> Result<Conn> {
|
||||
_get_connection().await.to_internal_error()
|
||||
_get_connection().await.map_err(|_| create_error!(InternalError))
|
||||
}
|
||||
|
||||
pub async fn raise_if_in_voice(user: &User, channel_id: &str) -> Result<()> {
|
||||
@@ -35,7 +35,7 @@ pub async fn raise_if_in_voice(user: &User, channel_id: &str) -> Result<()> {
|
||||
.to_internal_error()?
|
||||
> 0
|
||||
{
|
||||
Err(create_error!(NotConnected))
|
||||
Err(create_error!(AlreadyConnected))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@ utoipa = ["dep:utoipa"]
|
||||
rocket = ["dep:rocket", "dep:serde_json"]
|
||||
axum = ["dep:axum", "dep:serde_json"]
|
||||
okapi = ["dep:revolt_rocket_okapi", "dep:revolt_okapi", "schemas"]
|
||||
sentry = ["dep:sentry"]
|
||||
|
||||
default = ["serde"]
|
||||
default = ["serde", "sentry"]
|
||||
|
||||
[dependencies]
|
||||
# Serialisation
|
||||
@@ -36,3 +37,5 @@ revolt_okapi = { version = "0.9.1", optional = true }
|
||||
log = "0.4"
|
||||
# Axum
|
||||
axum = { version = "0.7.5", optional = true }
|
||||
|
||||
sentry = { version = "0.31.5", optional = true }
|
||||
@@ -226,7 +226,7 @@ pub trait ToRevoltError<T> {
|
||||
fn to_internal_error(self) -> Result<T, Error>;
|
||||
}
|
||||
|
||||
impl<T, E: std::fmt::Debug> ToRevoltError<T> for Result<T, E> {
|
||||
impl<T, E: std::fmt::Debug + std::error::Error> ToRevoltError<T> for Result<T, E> {
|
||||
#[track_caller]
|
||||
fn to_internal_error(self) -> Result<T, Error> {
|
||||
let loc = Location::caller();
|
||||
@@ -234,6 +234,8 @@ impl<T, E: std::fmt::Debug> ToRevoltError<T> for Result<T, E> {
|
||||
self
|
||||
.map_err(|e| {
|
||||
log::error!("{e:?}");
|
||||
#[cfg(feature = "sentry")]
|
||||
sentry::capture_error(&e);
|
||||
|
||||
Error {
|
||||
error_type: ErrorType::InternalError,
|
||||
|
||||
@@ -199,8 +199,8 @@ pub async fn ingress(
|
||||
};
|
||||
}
|
||||
}
|
||||
// Audio/video track was started/stopped
|
||||
"track_published" | "track_unpublished" => {
|
||||
// Audio/video track was started/stopped/unmuted/muted
|
||||
"track_published" | "track_unpublished" | "track_unmuted" | "track_muted" => {
|
||||
let channel_id = channel_id.to_internal_error()?;
|
||||
let user_id = user_id.to_internal_error()?;
|
||||
let track = event.track.as_ref().to_internal_error()?;
|
||||
@@ -214,42 +214,59 @@ pub async fn ingress(
|
||||
// forbid any size which goes over the limit and also limit the aspect ratio to stop people from making too tall or too wide and bypassing the limit.
|
||||
// TODO: figure out how to track audio stream quality
|
||||
|
||||
if event.event == "track_published"
|
||||
&& (track.r#type == TrackType::Data as i32
|
||||
|| (track.r#type == TrackType::Video as i32
|
||||
&& (user_limits.video_resolution[0] != 0
|
||||
&& user_limits.video_resolution[1] != 0
|
||||
&& track.width * track.height
|
||||
> user_limits.video_resolution[0]
|
||||
* user_limits.video_resolution[1])
|
||||
|| (user_limits.video_aspect_ratio[0]
|
||||
!= user_limits.video_aspect_ratio[1]
|
||||
&& !(user_limits.video_aspect_ratio[0]
|
||||
..=user_limits.video_aspect_ratio[1])
|
||||
.contains(&(track.width as f32 / track.height as f32)))))
|
||||
{
|
||||
log::debug!("Removing user {user_id} from channel {channel_id} {event:?} due to forbidden track.");
|
||||
if event.event == "track_published" {
|
||||
let mut disconnect = false;
|
||||
|
||||
voice_client.remove_user(node, user_id, channel_id).await?;
|
||||
delete_voice_state(channel_id, channel.server(), user_id).await?;
|
||||
} else {
|
||||
let partial = update_voice_state_tracks(
|
||||
channel_id,
|
||||
channel.server(),
|
||||
user_id,
|
||||
event.event == "track_published", // to avoid duplicating this entire case twice
|
||||
track.source,
|
||||
)
|
||||
.await?;
|
||||
if track.r#type == TrackType::Data as i32 {
|
||||
log::debug!("User published data");
|
||||
disconnect = true;
|
||||
};
|
||||
|
||||
EventV1::UserVoiceStateUpdate {
|
||||
id: user_id.clone(),
|
||||
channel_id: channel_id.clone(),
|
||||
data: partial,
|
||||
}
|
||||
.p(channel_id.clone())
|
||||
.await;
|
||||
if track.r#type == TrackType::Video as i32 {
|
||||
if user_limits.video_resolution[0] != 0
|
||||
&& user_limits.video_resolution[1] != 0
|
||||
&& track.width * track.height
|
||||
> user_limits.video_resolution[0] * user_limits.video_resolution[1]
|
||||
{
|
||||
log::debug!("User published video with out of bounds resolution");
|
||||
disconnect = true;
|
||||
};
|
||||
|
||||
if user_limits.video_aspect_ratio[0] != user_limits.video_aspect_ratio[1]
|
||||
&& !(user_limits.video_aspect_ratio[0]..=user_limits.video_aspect_ratio[1])
|
||||
.contains(&(track.width as f32 / track.height as f32))
|
||||
{
|
||||
log::debug!("User published video with out of bounds aspect ratio");
|
||||
disconnect = true;
|
||||
};
|
||||
};
|
||||
|
||||
if disconnect {
|
||||
log::debug!("Removing user {user_id} from channel {channel_id} {event:?} due to forbidden track.");
|
||||
|
||||
let _ = voice_client.remove_user(node, user_id, channel_id).await;
|
||||
delete_voice_state(channel_id, channel.server(), user_id).await?;
|
||||
|
||||
return Ok(EmptyResponse);
|
||||
};
|
||||
};
|
||||
|
||||
let partial = update_voice_state_tracks(
|
||||
channel_id,
|
||||
channel.server(),
|
||||
user_id,
|
||||
event.event == "track_published" || event.event == "track_unmuted", // to avoid duplicating this entire case twice
|
||||
track.source,
|
||||
)
|
||||
.await?;
|
||||
|
||||
EventV1::UserVoiceStateUpdate {
|
||||
id: user_id.clone(),
|
||||
channel_id: channel_id.clone(),
|
||||
data: partial,
|
||||
}
|
||||
.p(channel_id.clone())
|
||||
.await;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
@@ -22,10 +22,11 @@ pub async fn delete_bot(
|
||||
bot.delete(db).await?;
|
||||
|
||||
for channel_id in get_user_voice_channels(&bot.id).await? {
|
||||
let node = get_channel_node(&channel_id).await?.unwrap();
|
||||
let channel = Reference::from_unchecked(&channel_id).as_channel(db).await?;
|
||||
if let Some(node) = get_channel_node(&channel_id).await? {
|
||||
let _ = voice_client.remove_user(&node, &bot.id, &channel_id).await;
|
||||
}
|
||||
|
||||
voice_client.remove_user(&node, &bot.id, &channel_id).await?;
|
||||
let channel = Reference::from_unchecked(&channel_id).as_channel(db).await?;
|
||||
|
||||
delete_voice_state(&channel_id, channel.server(), &bot.id).await?;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,10 @@ pub async fn remove_member(
|
||||
};
|
||||
|
||||
if is_in_voice_channel(&user.id, channel.id()).await? {
|
||||
let node = get_channel_node(channel.id()).await?.unwrap();
|
||||
if let Some(node) = get_channel_node(channel.id()).await? {
|
||||
let _ = voice_client.remove_user(&node, &user.id, channel.id()).await;
|
||||
}
|
||||
|
||||
voice_client.remove_user(&node, &user.id, channel.id()).await?;
|
||||
delete_voice_state(channel.id(), None, &user.id).await?;
|
||||
};
|
||||
|
||||
|
||||
@@ -79,15 +79,15 @@ pub async fn call(
|
||||
// should only ever loop once but just to cover our backs.
|
||||
|
||||
for channel_id in get_user_voice_channels(&user.id).await? {
|
||||
let node = get_channel_node(&channel_id).await?.unwrap();
|
||||
if let Some(node) = get_channel_node(&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 channel = Reference::from_unchecked(&channel_id)
|
||||
.as_channel(db)
|
||||
.await?;
|
||||
|
||||
voice_client
|
||||
.remove_user(&node, &user.id, &channel_id)
|
||||
.await?;
|
||||
|
||||
delete_voice_state(&channel_id, channel.server(), &user.id).await?;
|
||||
}
|
||||
} else {
|
||||
@@ -103,7 +103,7 @@ pub async fn call(
|
||||
log::debug!("Created room {}", room.name);
|
||||
|
||||
if let Some(recipients) = recipients {
|
||||
if room.num_participants == 0 {
|
||||
if room.num_participants == 0 && !recipients.is_empty() {
|
||||
set_call_notification_recipients(channel.id(), &user.id, &recipients).await?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ pub async fn ban(
|
||||
|
||||
// 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(&user.id, &server.id).await? {
|
||||
let node = get_channel_node(&channel_id).await?.unwrap();
|
||||
|
||||
voice_client.remove_user(&node, &user.id, &channel_id).await?;
|
||||
if let Some(node) = get_channel_node(&channel_id).await? {
|
||||
let _ = voice_client.remove_user(&node, &user.id, &channel_id).await;
|
||||
}
|
||||
|
||||
delete_voice_state(&channel_id, Some(&server.id), &user.id).await?
|
||||
}
|
||||
|
||||
@@ -217,9 +217,11 @@ pub async fn edit(
|
||||
|
||||
EventV1::UserMoveVoiceChannel {
|
||||
node: new_node,
|
||||
from: channel,
|
||||
to: new_voice_channel.id().to_string(),
|
||||
token,
|
||||
}
|
||||
.p_user(target_user.id.clone(), db)
|
||||
.private(target_user.id.clone())
|
||||
.await;
|
||||
};
|
||||
} else if can_publish.is_some() || can_receive.is_some() || remove_contains_voice {
|
||||
|
||||
@@ -47,9 +47,9 @@ pub async fn kick(
|
||||
.await?;
|
||||
|
||||
if let Some(channel_id) = get_user_voice_channel_in_server(&user.id, &server.id).await? {
|
||||
let node = get_channel_node(&channel_id).await?.unwrap();
|
||||
|
||||
voice_client.remove_user(&node, &user.id, &channel_id).await?;
|
||||
if let Some(node) = get_channel_node(&channel_id).await? {
|
||||
let _ = voice_client.remove_user(&node, &user.id, &channel_id).await;
|
||||
}
|
||||
|
||||
delete_voice_state(&channel_id, Some(&server.id), &user.id).await?;
|
||||
};
|
||||
|
||||
@@ -39,9 +39,9 @@ pub async fn delete(
|
||||
} else {
|
||||
if let Some(channel_id) = get_user_voice_channel_in_server(&user.id, &server.id).await? {
|
||||
if server.channels.iter().any(|c| c == &channel_id) {
|
||||
let node = get_channel_node(&channel_id).await?.unwrap();
|
||||
|
||||
voice_client.remove_user(&node, &user.id, &channel_id).await?;
|
||||
if let Some(node) = get_channel_node(&channel_id).await? {
|
||||
let _ = voice_client.remove_user(&node, &user.id, &channel_id).await;
|
||||
}
|
||||
|
||||
delete_voice_state(&channel_id, Some(&server.id), &user.id).await?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user