feat: command do not disturb
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
use std::str::FromStr;
|
||||
use strum::EnumString;
|
||||
|
||||
use crate::{
|
||||
notify::service::mobile_app::SpecialMessage,
|
||||
object_id::ObjectId,
|
||||
service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall},
|
||||
};
|
||||
|
||||
use super::super::{NotifyMobileAppServiceData, NotifyMobileAppServiceDataData};
|
||||
|
||||
#[derive(Debug, Clone, EnumString, strum::Display)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum Filter {
|
||||
/// Normal interruption filter -
|
||||
/// no notifications are suppressed
|
||||
Off,
|
||||
|
||||
/// Alarms only interruption filter -
|
||||
/// all notifications except those in the alarm category are suppressed.
|
||||
/// Some audio streams are muted
|
||||
AlarmsOnly,
|
||||
|
||||
/// Priority interruption filter -
|
||||
/// all notifications are suppressed except those that match the priority criteria.
|
||||
/// Some audio streams are muted
|
||||
PriorityOnly,
|
||||
|
||||
/// No interruptions filter -
|
||||
/// all notifications are suppressed and all audio streams (except those used for phone calls) and vibrations are muted
|
||||
TotalSilence,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, typed_builder::TypedBuilder)]
|
||||
pub struct DoNotDisturb {
|
||||
pub object_id: ObjectId,
|
||||
pub filter: Filter,
|
||||
}
|
||||
|
||||
impl IntoServiceCall for DoNotDisturb {
|
||||
type ServiceData = NotifyMobileAppServiceData;
|
||||
|
||||
fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) {
|
||||
let DoNotDisturb { object_id, filter } = self;
|
||||
|
||||
let service_domain = ServiceDomain::from_str("notify").expect("statically written and known to be a valid slug; hoping to get compiler checks instead in the future");
|
||||
|
||||
let service_id = ServiceId::from_str(&format!("mobile_app_{object_id}")).expect("statically written and known to be a valid slug; hoping to get compiler checks instead in the future");
|
||||
|
||||
let service_data = NotifyMobileAppServiceData::builder()
|
||||
.message(SpecialMessage::CommandDnd.to_string())
|
||||
.data(
|
||||
NotifyMobileAppServiceDataData::builder()
|
||||
.command(filter.to_string())
|
||||
.build(),
|
||||
)
|
||||
.build();
|
||||
|
||||
(service_domain, service_id, service_data)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
mod do_not_disturb;
|
||||
mod request_location_update;
|
||||
|
||||
pub use do_not_disturb::DoNotDisturb;
|
||||
pub use request_location_update::RequestLocationUpdate;
|
||||
|
||||
@@ -219,6 +219,7 @@ impl<'py> IntoPyObject<'py> for MediaStream {
|
||||
#[builder(field_defaults(default, setter(strip_option(fallback_suffix = "_option"))))]
|
||||
pub struct NotifyMobileAppServiceDataData {
|
||||
actions: Option<Vec<Action>>,
|
||||
command: Option<String>,
|
||||
media_stream: Option<MediaStream>,
|
||||
tts_text: Option<String>,
|
||||
visibility: Option<Visibility>,
|
||||
|
||||
Reference in New Issue
Block a user