mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-07-31 18:07:23 -04:00
refactor(sdk, ffi): rename events() to state_stream().
The subscription method is now `state_stream()`, matching the backups and recovery submodules; `events` was too overloaded a name in a Matrix client. Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -969,7 +969,7 @@ impl Encryption {
|
||||
&self,
|
||||
listener: Box<dyn DehydratedDeviceEventListener>,
|
||||
) -> Arc<TaskHandle> {
|
||||
let mut events = Box::pin(self.inner.dehydrated_devices().events());
|
||||
let mut events = Box::pin(self.inner.dehydrated_devices().state_stream());
|
||||
Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move {
|
||||
while let Some(event) = events.next().await {
|
||||
let Ok(event) = event else { continue };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Add `Encryption::dehydrated_devices()`, a high-level [MSC3814] dehydrated-device
|
||||
manager that wraps the crypto-crate primitives: probe support, create,
|
||||
rehydrate, delete, weekly rotation, a Secret Storage round trip for the pickle
|
||||
key, and a lifecycle event stream. `MatrixMockServer` gains `mock_*` helpers for
|
||||
key, and a lifecycle state stream. `MatrixMockServer` gains `mock_*` helpers for
|
||||
the four MSC3814 endpoints.
|
||||
|
||||
[MSC3814]: https://github.com/matrix-org/matrix-spec-proposals/pull/3814
|
||||
|
||||
@@ -144,7 +144,7 @@ fn pickle_key_secret_name() -> SecretName {
|
||||
|
||||
/// Lifecycle events emitted by [`DehydratedDevices`].
|
||||
///
|
||||
/// Subscribe with [`DehydratedDevices::events`] to observe creation,
|
||||
/// Subscribe with [`DehydratedDevices::state_stream`] to observe creation,
|
||||
/// rehydration progress, and rotation outcomes. [`Self::RehydrationCompleted`]
|
||||
/// carries the final imported counts so a caller does not have to fold over the
|
||||
/// [`Self::RehydrationProgress`] events, and [`Self::RotationError`] surfaces
|
||||
@@ -263,7 +263,7 @@ struct DownloadedDevice {
|
||||
}
|
||||
|
||||
impl DehydratedDevices {
|
||||
/// Subscribe to [`DehydratedDeviceEvent`]s.
|
||||
/// Subscribe to the stream of [`DehydratedDeviceEvent`]s.
|
||||
///
|
||||
/// Each call returns a fresh stream. If a subscriber is slow enough to
|
||||
/// fall behind the channel's buffer, it receives a
|
||||
@@ -277,13 +277,13 @@ impl DehydratedDevices {
|
||||
/// # use futures_util::StreamExt;
|
||||
/// # async fn example(client: Client) -> anyhow::Result<()> {
|
||||
/// let dehydrated = client.encryption().dehydrated_devices();
|
||||
/// let mut events = dehydrated.events();
|
||||
/// while let Some(Ok(event)) = events.next().await {
|
||||
/// let mut stream = dehydrated.state_stream();
|
||||
/// while let Some(Ok(event)) = stream.next().await {
|
||||
/// println!("dehydrated devices: {event:?}");
|
||||
/// }
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
pub fn events(
|
||||
pub fn state_stream(
|
||||
&self,
|
||||
) -> impl Stream<Item = Result<DehydratedDeviceEvent, BroadcastStreamRecvError>> + use<> {
|
||||
BroadcastStream::new(self.state().event_sender.subscribe())
|
||||
|
||||
@@ -129,7 +129,7 @@ async fn test_create_with_explicit_display_name() {
|
||||
|
||||
server.mock_put_dehydrated_device().ok_echo().mock_once().mount().await;
|
||||
|
||||
let mut events = client.encryption().dehydrated_devices().events();
|
||||
let mut events = client.encryption().dehydrated_devices().state_stream();
|
||||
let pickle_key = DehydratedDeviceKey::new();
|
||||
let device_id = client
|
||||
.encryption()
|
||||
@@ -189,7 +189,7 @@ async fn test_delete_emits_event_on_success() {
|
||||
.mount()
|
||||
.await;
|
||||
|
||||
let mut events = client.encryption().dehydrated_devices().events();
|
||||
let mut events = client.encryption().dehydrated_devices().state_stream();
|
||||
client.encryption().dehydrated_devices().delete().await.unwrap();
|
||||
|
||||
assert_let!(Some(Ok(DehydratedDeviceEvent::Deleted)) = events.next().await);
|
||||
@@ -202,7 +202,7 @@ async fn test_delete_silent_on_not_found() {
|
||||
|
||||
server.mock_delete_dehydrated_device().not_found().mock_once().mount().await;
|
||||
|
||||
let mut events = client.encryption().dehydrated_devices().events();
|
||||
let mut events = client.encryption().dehydrated_devices().state_stream();
|
||||
client.encryption().dehydrated_devices().delete().await.unwrap();
|
||||
|
||||
// No event should have fired; the broadcast channel must remain empty.
|
||||
@@ -216,7 +216,7 @@ async fn test_delete_silent_on_unrecognized() {
|
||||
|
||||
server.mock_delete_dehydrated_device().error_unrecognized().mock_once().mount().await;
|
||||
|
||||
let mut events = client.encryption().dehydrated_devices().events();
|
||||
let mut events = client.encryption().dehydrated_devices().state_stream();
|
||||
client.encryption().dehydrated_devices().delete().await.unwrap();
|
||||
|
||||
assert!(events.next().now_or_never().is_none());
|
||||
@@ -249,7 +249,7 @@ async fn test_rehydrate_round_trip() {
|
||||
.await;
|
||||
server.mock_delete_dehydrated_device().ok(&uploaded_id).mock_once().mount().await;
|
||||
|
||||
let mut events = client.encryption().dehydrated_devices().events();
|
||||
let mut events = client.encryption().dehydrated_devices().state_stream();
|
||||
let outcome = client.encryption().dehydrated_devices().rehydrate(&pickle_key).await.unwrap();
|
||||
assert!(outcome);
|
||||
|
||||
@@ -315,7 +315,7 @@ async fn test_rehydrate_empty_server() {
|
||||
|
||||
server.mock_get_dehydrated_device().not_found().mock_once().mount().await;
|
||||
|
||||
let mut events = client.encryption().dehydrated_devices().events();
|
||||
let mut events = client.encryption().dehydrated_devices().state_stream();
|
||||
let pickle_key = DehydratedDeviceKey::new();
|
||||
let outcome = client.encryption().dehydrated_devices().rehydrate(&pickle_key).await.unwrap();
|
||||
assert!(!outcome);
|
||||
|
||||
Reference in New Issue
Block a user