Skip to content

Commit

Permalink
fix: include voice states in servercreate event
Browse files Browse the repository at this point in the history
feat: call started system message in dms
  • Loading branch information
Zomatree committed Jan 27, 2025
1 parent 9de87a0 commit c55b5bf
Show file tree
Hide file tree
Showing 25 changed files with 237 additions and 220 deletions.
24 changes: 3 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/bonfire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ revolt-config = { path = "../core/config" }
revolt-database = { path = "../core/database" }
revolt-permissions = { version = "0.8.1", path = "../core/permissions" }
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
revolt-voice = { path = "../core/voice" }

# redis
fred = { version = "8.0.1", features = ["subscriber-client"] }
1 change: 1 addition & 0 deletions crates/bonfire/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl ProtocolConfiguration {
ReadyPayloadFields::Channels,
ReadyPayloadFields::Members,
ReadyPayloadFields::Emoji,
ReadyPayloadFields::VoiceStates,
]
}
}
Expand Down
33 changes: 3 additions & 30 deletions crates/bonfire/src/events/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::collections::HashSet;
use revolt_database::{
events::client::{EventV1, ReadyPayloadFields},
util::permissions::DatabasePermissionQuery,
voice::{delete_voice_state, get_voice_channel_members, get_voice_state, get_channel_voice_state},
Channel, Database, Member, MemberCompositeKey, Presence, RelationshipStatus,
};
use revolt_models::v0;
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
use revolt_presence::filter_online;
use revolt_result::Result;
use revolt_voice::{delete_voice_state, get_voice_channel_members, get_voice_state};


use super::state::{Cache, State};
Expand Down Expand Up @@ -236,7 +236,7 @@ impl State {
let mut voice_states = Vec::new();

for channel in &channels {
if let Ok(Some(voice_state)) = self.fetch_voice_state(channel).await {
if let Ok(Some(voice_state)) = get_channel_voice_state(channel).await {
voice_states.push(voice_state)
}
}
Expand Down Expand Up @@ -464,6 +464,7 @@ impl State {
server,
channels,
emojis: _,
voice_states: _,
} => {
self.insert_subscription(id.clone()).await;

Expand Down Expand Up @@ -637,32 +638,4 @@ impl State {

true
}

async fn fetch_voice_state(
&self,
channel: &Channel,
) -> Result<Option<v0::ChannelVoiceState>> {
let members = get_voice_channel_members(&channel.id()).await?;

if !members.is_empty() {
let mut participants = Vec::with_capacity(members.len());

for user_id in members {
if let Some(voice_state) = get_voice_state(&channel.id(), channel.server().as_deref(), &user_id).await? {
participants.push(voice_state);
} else {
log::info!("Voice state not found but member in voice channel members, removing.");

delete_voice_state(&channel.id(), channel.server().as_deref(), &user_id).await?;
}
}

Ok(Some(v0::ChannelVoiceState {
id: channel.id().to_string(),
participants,
}))
} else {
Ok(None)
}
}
}
2 changes: 1 addition & 1 deletion crates/bonfire/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{env, sync::Arc};
use async_std::net::TcpListener;
use revolt_presence::clear_region;
use once_cell::sync::OnceCell;
use revolt_voice::VoiceClient;
use revolt_database::voice::VoiceClient;

#[macro_use]
extern crate log;
Expand Down
5 changes: 5 additions & 0 deletions crates/core/database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ authifier = { version = "1.0.9", features = ["rocket_impl"] }

# RabbitMQ
amqprs = { version = "1.7.0" }

# Voice
livekit-api = "0.4.1"
livekit-protocol = "0.3.6"
livekit-runtime = { version = "0.3.1", features = ["tokio"] }
1 change: 1 addition & 0 deletions crates/core/database/src/events/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub enum EventV1 {
server: Server,
channels: Vec<Channel>,
emojis: Vec<Emoji>,
voice_states: Vec<ChannelVoiceState>
},

/// Update existing server
Expand Down
3 changes: 3 additions & 0 deletions crates/core/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ pub mod tasks;
mod amqp;
pub use amqp::amqp::AMQP;

pub mod voice;


/// Utility function to check if a boolean value is false
pub fn if_false(t: &bool) -> bool {
!t
Expand Down
5 changes: 5 additions & 0 deletions crates/core/database/src/models/messages/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ auto_derived!(
MessagePinned { id: String, by: String },
#[serde(rename = "message_unpinned")]
MessageUnpinned { id: String, by: String },
#[serde(rename = "call_started")]
CallStarted { by: String },
}

/// Name and / or avatar override information
Expand Down Expand Up @@ -658,6 +660,9 @@ impl Message {
v0::SystemMessage::MessageUnpinned { by, .. } => {
users.push(by.clone());
}
v0::SystemMessage::CallStarted { by } => {
users.push(by.clone())
}
}
}
users
Expand Down
10 changes: 10 additions & 0 deletions crates/core/database/src/models/server_members/model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use iso8601_timestamp::Timestamp;
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
use revolt_result::{create_error, Result};
use crate::voice::get_channel_voice_state;

use crate::{
events::client::EventV1, if_false, util::permissions::DatabasePermissionQuery, Channel,
Expand Down Expand Up @@ -132,6 +133,14 @@ impl Member {

let emojis = db.fetch_emoji_by_parent_id(&server.id).await?;

let mut voice_states = Vec::new();

for channel in &channels {
if let Ok(Some(voice_state)) = get_channel_voice_state(channel).await {
voice_states.push(voice_state)
}
}

EventV1::ServerMemberJoin {
id: server.id.clone(),
user: user.id.clone(),
Expand All @@ -148,6 +157,7 @@ impl Member {
.map(|channel| channel.into())
.collect(),
emojis: emojis.into_iter().map(|emoji| emoji.into()).collect(),
voice_states
}
.private(user.id.clone())
.await;
Expand Down
1 change: 1 addition & 0 deletions crates/core/database/src/util/bridge/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ impl From<crate::SystemMessage> for SystemMessage {
crate::SystemMessage::UserRemove { id, by } => Self::UserRemove { id, by },
crate::SystemMessage::MessagePinned { id, by } => Self::MessagePinned { id, by },
crate::SystemMessage::MessageUnpinned { id, by } => Self::MessageUnpinned { id, by },
crate::SystemMessage::CallStarted { by } => Self::CallStarted { by }
}
}
}
Expand Down
Loading

0 comments on commit c55b5bf

Please sign in to comment.