feat: make Channel::server return a reference

This commit is contained in:
Zomatree
2025-02-07 21:35:51 +00:00
parent 2593a4272b
commit 060b4c43f4
7 changed files with 12 additions and 12 deletions

View File

@@ -435,9 +435,9 @@ impl Channel {
} }
/// Clone this channel's server id /// Clone this channel's server id
pub fn server(&self) -> Option<String> { pub fn server(&self) -> Option<&str> {
match self { match self {
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => Some(server.clone()), Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => Some(server),
_ => None _ => None
} }
} }

View File

@@ -1,7 +1,7 @@
use livekit_protocol::ParticipantPermission; use livekit_protocol::ParticipantPermission;
use redis_kiss::{get_connection as _get_connection, Conn, redis::Pipeline, AsyncCommands}; use redis_kiss::{get_connection as _get_connection, Conn, redis::Pipeline, AsyncCommands};
use crate::{events::client::EventV1, models::{Channel, User}, util::{permissions::DatabasePermissionQuery, reference::Reference}, Database, Role, Server}; use crate::{events::client::EventV1, models::{Channel, User}, util::{permissions::DatabasePermissionQuery, reference::Reference}, Database, Server};
use revolt_models::v0::{self, PartialUserVoiceState, UserVoiceState}; use revolt_models::v0::{self, PartialUserVoiceState, UserVoiceState};
use revolt_permissions::{calculate_channel_permissions, ChannelPermission, PermissionValue}; use revolt_permissions::{calculate_channel_permissions, ChannelPermission, PermissionValue};
use revolt_result::{create_error, Result, ToRevoltError}; use revolt_result::{create_error, Result, ToRevoltError};

View File

@@ -54,7 +54,7 @@ impl VoiceClient {
.with_grants(VideoGrants { .with_grants(VideoGrants {
room_join: true, room_join: true,
can_publish: true, can_publish: true,
can_publish_sources: vec![], // allowed_sources.into_iter().map(ToString::to_string).collect(), can_publish_sources: allowed_sources.into_iter().map(ToString::to_string).collect(),
can_subscribe: permissions.has_channel_permission(ChannelPermission::Listen), can_subscribe: permissions.has_channel_permission(ChannelPermission::Listen),
room: channel.id().to_string(), room: channel.id().to_string(),
..Default::default() ..Default::default()

View File

@@ -50,7 +50,7 @@ async fn ingress(db: &State<Database>, voice_client: &State<VoiceClient>, body:
.as_channel(db) .as_channel(db)
.await?; .await?;
let voice_state = create_voice_state(channel_id, channel.server().as_deref(), user_id).await?; let voice_state = create_voice_state(channel_id, channel.server(), user_id).await?;
EventV1::VoiceChannelJoin { EventV1::VoiceChannelJoin {
id: channel_id.clone(), id: channel_id.clone(),
@@ -67,7 +67,7 @@ async fn ingress(db: &State<Database>, voice_client: &State<VoiceClient>, body:
.as_channel(db) .as_channel(db)
.await?; .await?;
delete_voice_state(channel_id, channel.server().as_deref(), user_id).await?; delete_voice_state(channel_id, channel.server(), user_id).await?;
EventV1::VoiceChannelLeave { EventV1::VoiceChannelLeave {
id: channel_id.clone(), id: channel_id.clone(),
@@ -93,12 +93,12 @@ async fn ingress(db: &State<Database>, voice_client: &State<VoiceClient>, body:
) )
{ {
voice_client.remove_user(user_id, channel_id).await?; voice_client.remove_user(user_id, channel_id).await?;
delete_voice_state(channel_id, channel.server().as_deref(), user_id).await?; delete_voice_state(channel_id, channel.server(), user_id).await?;
} }
let partial = update_voice_state_tracks( let partial = update_voice_state_tracks(
channel_id, channel_id,
channel.server().as_deref(), channel.server(),
user_id, user_id,
body.event == "track_published", // to avoid duplicating this entire case twice body.event == "track_published", // to avoid duplicating this entire case twice
track.source track.source

View File

@@ -55,7 +55,7 @@ pub async fn delete(
for user_id in get_voice_channel_members(channel.id()).await? { for user_id in get_voice_channel_members(channel.id()).await? {
voice_client.remove_user(&user_id, channel.id()).await?; voice_client.remove_user(&user_id, channel.id()).await?;
delete_voice_state(channel.id(), channel.server().as_deref(), &user.id).await?; delete_voice_state(channel.id(), channel.server(), &user.id).await?;
}; };
Ok(EmptyResponse) Ok(EmptyResponse)

View File

@@ -76,7 +76,7 @@ pub async fn set_default_permissions(
} }
let server = match channel.server() { let server = match channel.server() {
Some(server_id) => Some(Reference::from_unchecked(server_id).as_server(db).await?), Some(server_id) => Some(Reference::from_unchecked(server_id.to_string()).as_server(db).await?),
None => None None => None
}; };

View File

@@ -157,8 +157,8 @@ pub async fn edit(
roles, roles,
timeout, timeout,
remove, remove,
mut can_publish, can_publish,
mut can_receive, can_receive,
voice_channel, voice_channel,
} = data; } = data;