feat: command do not disturb

This commit is contained in:
2026-07-08 14:38:17 -04:00
parent 22c5009d95
commit 09d9dcbfe8
3 changed files with 64 additions and 0 deletions

View File

@@ -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)
}
}

View File

@@ -1,3 +1,5 @@
mod do_not_disturb;
mod request_location_update;
pub use do_not_disturb::DoNotDisturb;
pub use request_location_update::RequestLocationUpdate;

View File

@@ -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>,