track current state

This commit is contained in:
Zomatree
2024-04-11 01:07:03 +01:00
parent ae87bc0b67
commit 7a4421089c
7 changed files with 199 additions and 46 deletions

View File

@@ -2,7 +2,7 @@ use authifier::AuthifierEvent;
use serde::{Deserialize, Serialize};
use revolt_models::v0::{
AppendMessage, Channel, ChannelVoiceState, Emoji, FieldsChannel, FieldsMember, FieldsRole, FieldsServer, FieldsUser, FieldsWebhook, Member, MemberCompositeKey, Message, PartialChannel, PartialMember, PartialMessage, PartialRole, PartialServer, PartialUser, PartialWebhook, Report, Server, User, UserSettings, UserVoiceState, Webhook
AppendMessage, Channel, ChannelVoiceState, Emoji, FieldsChannel, FieldsMember, FieldsRole, FieldsServer, FieldsUser, FieldsWebhook, Member, MemberCompositeKey, Message, PartialChannel, PartialMember, PartialMessage, PartialRole, PartialServer, PartialUser, PartialUserVoiceState, PartialWebhook, Report, Server, User, UserSettings, UserVoiceState, Webhook
};
use revolt_result::Error;
@@ -232,6 +232,11 @@ pub enum EventV1 {
VoiceChannelLeave {
id: String,
user: String,
},
UserVoiceStateUpdate {
id: String,
channel_id: String,
data: PartialUserVoiceState
}
}

View File

@@ -430,6 +430,14 @@ impl Channel {
}
}
/// Clone this channel's server id
pub fn server(&self) -> Option<String> {
match self {
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => Some(server.clone()),
_ => None
}
}
/// Set role permission on a channel
pub async fn set_role_permission(
&mut self,

View File

@@ -569,10 +569,14 @@ impl User {
}
/// Gets current voice channel
pub async fn current_voice_channel(&self) -> Result<Option<String>> {
let mut conn = get_connection().await.map_err(|_| create_error!(InternalError))?;
///
/// current_context: Either the channel id if a dm or group, or server_id if in a server
pub async fn current_voice_channel(&self, current_context: &str) -> Result<Option<String>> {
let mut conn = get_connection()
.await
.map_err(|_| create_error!(InternalError))?;
conn.get::<_, Option<String>>(format!("vc-{}", &self.id))
conn.get::<_, Option<String>>(format!("vc-{}-{current_context}", &self.id))
.await
.map_err(|_| create_error!(InternalError))
}