feat: respect consent to be recorded
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
use crate::{OneToManyUniqueBTreeMap, VCs, command::State};
|
||||
use crate::{
|
||||
OneToManyUniqueBTreeMap, UserDataManager, VCs, command::State, option_ext::OptionExt as _,
|
||||
user_capnp::user::Consent, user_data::RECORD_IF_CONSENT_UNSPECIFIED,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use futures::FutureExt;
|
||||
use hound::{SampleFormat, WavSpec};
|
||||
use opendal::Operator;
|
||||
use snafu::{OptionExt, Snafu};
|
||||
use snafu::{OptionExt as _, Snafu};
|
||||
use songbird::{CoreEvent, Event, EventContext, EventHandler};
|
||||
use std::{
|
||||
io::Cursor,
|
||||
@@ -104,6 +108,8 @@ struct Handler {
|
||||
|
||||
audio_channels: u16,
|
||||
audio_sample_rate: u32,
|
||||
|
||||
user_data_manager: UserDataManager,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -134,6 +140,26 @@ impl EventHandler for Handler {
|
||||
tracing::info!(?user_id);
|
||||
|
||||
if let Some(pcm) = &voice_data.decoded_voice {
|
||||
let may_record = user_id
|
||||
.map_async(|user_id| {
|
||||
self.user_data_manager
|
||||
.with(user_id, |user_data| {
|
||||
user_data.get_voice_recording_consent().unwrap()
|
||||
})
|
||||
.map(|result| result.expect("TODO"))
|
||||
})
|
||||
.await
|
||||
.map_or(RECORD_IF_CONSENT_UNSPECIFIED, |consent| match consent {
|
||||
Consent::Unspecified => RECORD_IF_CONSENT_UNSPECIFIED,
|
||||
Consent::Granted => true,
|
||||
Consent::Withheld => false,
|
||||
});
|
||||
|
||||
if !may_record {
|
||||
tracing::warn!(?user_id, "may not be recorded");
|
||||
continue;
|
||||
}
|
||||
|
||||
let elapsed = self.start_instant.elapsed();
|
||||
let elapsed = elapsed.try_into().expect("TODO");
|
||||
|
||||
@@ -281,6 +307,8 @@ pub async fn handle(state: State, interaction: Interaction) {
|
||||
|
||||
audio_channels,
|
||||
audio_sample_rate,
|
||||
|
||||
user_data_manager: state.user_data_manager,
|
||||
};
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user