#[cfg(feature = "async")]
use futures_util::StreamExt;
#[cfg(feature = "async")]
use jmap_client::{client::Client, DataType};
#[cfg(feature = "async")]
async fn event_source() {
let client = Client::new()
.credentials(("john@example.org", "secret"))
.connect("https://jmap.example.org")
.await
.unwrap();
let mut stream = client
.event_source(
[
DataType::Email,
DataType::EmailDelivery,
DataType::Mailbox,
DataType::EmailSubmission,
DataType::Identity,
]
.into(),
false,
60.into(),
None,
)
.await
.unwrap();
while let Some(event) = stream.next().await {
use jmap_client::event_source::PushNotification;
match event.unwrap() {
PushNotification::StateChange(changes) => {
println!("-> Change id: {:?}", changes.id());
for account_id in changes.changed_accounts() {
println!(" Account {} has changes:", account_id);
if let Some(account_changes) = changes.changes(account_id) {
for (type_state, state_id) in account_changes {
println!(" Type {:?} has a new state {}.", type_state, state_id);
}
}
}
}
PushNotification::CalendarAlert(calendar_alert) => {
println!(
"-> Calendar alert received for event {} (alert id {}).",
calendar_alert.calendar_event_id, calendar_alert.alert_id
);
}
}
}
}
fn main() {
#[cfg(feature = "async")]
let _c = event_source();
}