fix: include voice states in servercreate event

feat: call started system message in dms
This commit is contained in:
Zomatree
2025-01-27 20:46:29 +00:00
parent 9de87a01ab
commit c55b5bf75f
25 changed files with 239 additions and 222 deletions

View File

@@ -1,8 +1,7 @@
use revolt_models::v0;
use revolt_database::{util::{permissions::perms, reference::Reference}, Database, User};
use revolt_database::{util::{permissions::perms, reference::Reference}, voice::{raise_if_in_voice, VoiceClient}, Channel, Database, SystemMessage, User, AMQP};
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
use revolt_result::Result;
use revolt_voice::{VoiceClient, raise_if_in_voice};
use rocket::{serde::json::Json, State};
@@ -11,10 +10,10 @@ use rocket::{serde::json::Json, State};
/// Asks the voice server for a token to join the call.
#[openapi(tag = "Voice")]
#[post("/<target>/join_call")]
pub async fn call(db: &State<Database>, voice: &State<VoiceClient>, user: User, target: Reference) -> Result<Json<v0::CreateVoiceUserResponse>> {
pub async fn call(db: &State<Database>, amqp: &State<AMQP>, voice: &State<VoiceClient>, user: User, target: Reference) -> Result<Json<v0::CreateVoiceUserResponse>> {
let channel = target.as_channel(db).await?;
raise_if_in_voice(&user, &channel.id()).await?;
raise_if_in_voice(&user, channel.id()).await?;
let mut permissions = perms(db, &user).channel(&channel);
@@ -24,7 +23,28 @@ pub async fn call(db: &State<Database>, voice: &State<VoiceClient>, user: User,
let token = voice.create_token(&user, current_permissions, &channel)?;
let room = voice.create_room(&channel).await?;
log::debug!("created room {}", room.name);
log::debug!("Created room {}", room.name);
match &channel {
Channel::DirectMessage { .. } | Channel::Group { .. } => {
SystemMessage::CallStarted {
by: user.id.clone()
}
.into_message(channel.id().to_string())
.send(
db,
Some(amqp),
v0::MessageAuthor::System {
username: &user.username,
avatar: user.avatar.as_ref().map(|file| file.id.as_ref()),
},
None,
None,
&channel, false
).await?;
}
_ => {}
};
Ok(Json(v0::CreateVoiceUserResponse { token }))
}