61 lines
1.9 KiB
Rust
61 lines
1.9 KiB
Rust
use std::str::FromStr;
|
|
|
|
use mitsein::vec1::Vec1;
|
|
use pyo3::{types::PyAnyMethods, IntoPyObject, Python};
|
|
|
|
use crate::{
|
|
object_id::ObjectId,
|
|
service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall},
|
|
};
|
|
|
|
use super::{
|
|
Action, NonSpecialMessage, NotifyMobileAppServiceData, NotifyMobileAppServiceDataData,
|
|
Visibility,
|
|
};
|
|
|
|
#[derive(Debug, Clone, typed_builder::TypedBuilder)]
|
|
pub struct StandardNotification {
|
|
pub object_id: ObjectId,
|
|
|
|
#[builder(default, setter(strip_option))]
|
|
pub title: Option<String>,
|
|
pub message: NonSpecialMessage,
|
|
|
|
#[builder(default, setter(strip_option))]
|
|
pub actions: Option<Vec1<Action>>,
|
|
|
|
#[builder(default, setter(strip_option))]
|
|
pub visibility: Option<Visibility>,
|
|
}
|
|
|
|
impl IntoServiceCall for StandardNotification {
|
|
type ServiceData = NotifyMobileAppServiceData;
|
|
|
|
fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) {
|
|
let StandardNotification {
|
|
object_id,
|
|
title,
|
|
message,
|
|
actions,
|
|
visibility,
|
|
} = 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()
|
|
.title_option(title)
|
|
.message(message.to_string())
|
|
.data(
|
|
NotifyMobileAppServiceDataData::builder()
|
|
.actions_option(actions.map(Into::into))
|
|
.visibility_option(visibility)
|
|
.build(),
|
|
)
|
|
.build();
|
|
|
|
(service_domain, service_id, service_data)
|
|
}
|
|
}
|