Files
continuwuity/src/api/client/sync/v5/to_device.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
800 B
Rust
Raw Normal View History

2025-10-05 19:48:07 +00:00
use futures::StreamExt;
use ruma::api::client::sync::sync_events::v5::response;
use tuwunel_core::{self, Result};
use super::{Connection, SyncInfo};
2025-10-05 19:48:07 +00:00
#[tracing::instrument(name = "to_device", level = "trace", skip_all)]
2025-10-05 19:48:07 +00:00
pub(super) async fn collect(
SyncInfo { services, sender_user, sender_device, .. }: SyncInfo<'_>,
conn: &Connection,
2025-10-05 19:48:07 +00:00
) -> Result<Option<response::ToDevice>> {
services
.users
.remove_to_device_events(sender_user, sender_device, conn.globalsince)
2025-10-05 19:48:07 +00:00
.await;
let events: Vec<_> = services
.users
.get_to_device_events(sender_user, sender_device, None, Some(conn.next_batch))
2025-10-05 19:48:07 +00:00
.collect()
.await;
let to_device = events
.is_empty()
.eq(&false)
.then(|| response::ToDevice {
next_batch: conn.next_batch.to_string().into(),
2025-10-05 19:48:07 +00:00
events,
});
Ok(to_device)
}