diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 52fc23c4c..201ef218c 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -587,7 +587,8 @@ impl Client { macro_rules! observe { ($t:ty, $cb: expr) => {{ // Using an Arc here is mandatory or else the subscriber will never trigger - let observer = Arc::new(self.inner.observe_events::<$t, ()>()); + let observer = + Arc::new(self.inner.observe_events::, ()>()); Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { let mut subscriber = observer.subscribe(); @@ -598,63 +599,47 @@ impl Client { } }))) }}; + + ($t:ty) => {{ + observe!($t, |event: RumaGlobalAccountDataEvent<$t>| { + listener.on_change(event.into()); + }) + }}; } match event_type { AccountDataEventType::Direct => { - observe!( - RumaGlobalAccountDataEvent, - |event: RumaGlobalAccountDataEvent| { - listener.on_change(event.into()); - } - ) + observe!(DirectEventContent) } AccountDataEventType::IdentityServer => { - observe!( - RumaGlobalAccountDataEvent, - |event: RumaGlobalAccountDataEvent| { - listener.on_change(event.into()); - } - ) + observe!(IdentityServerEventContent) } AccountDataEventType::IgnoredUserList => { - observe!( - RumaGlobalAccountDataEvent, - |event: RumaGlobalAccountDataEvent| { - listener.on_change(event.into()); - } - ) + observe!(IgnoredUserListEventContent) } AccountDataEventType::PushRules => { - observe!( - RumaGlobalAccountDataEvent, - |event: RumaGlobalAccountDataEvent| { - if let Ok(event) = event.try_into() { - listener.on_change(event); - } + observe!(PushRulesEventContent, |event: RumaGlobalAccountDataEvent< + PushRulesEventContent, + >| { + if let Ok(event) = event.try_into() { + listener.on_change(event); } - ) + }) } AccountDataEventType::SecretStorageDefaultKey => { - observe!( - RumaGlobalAccountDataEvent, - |event: RumaGlobalAccountDataEvent| { - listener.on_change(event.into()); - } - ) + observe!(SecretStorageDefaultKeyEventContent) } AccountDataEventType::SecretStorageKey { key_id } => { - observe!( - RumaGlobalAccountDataEvent, - |event: RumaGlobalAccountDataEvent| { - if event.content.key_id != key_id { - return; - } - if let Ok(event) = event.try_into() { - listener.on_change(event); - } + observe!(SecretStorageKeyEventContent, |event: RumaGlobalAccountDataEvent< + SecretStorageKeyEventContent, + >| { + if event.content.key_id != key_id { + return; } - ) + if let Ok(event) = event.try_into() { + listener.on_change(event); + } + }) } } } @@ -674,7 +659,9 @@ impl Client { ($t:ty, $cb: expr) => {{ // Using an Arc here is mandatory or else the subscriber will never trigger let observer = - Arc::new(self.inner.observe_room_events::<$t, ()>(&RoomId::parse(&room_id)?)); + Arc::new(self.inner.observe_room_events::, ()>( + &RoomId::parse(&room_id)?, + )); Ok(Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { let mut subscriber = observer.subscribe(); @@ -685,42 +672,30 @@ impl Client { } })))) }}; + + ($t:ty) => {{ + observe!($t, |event: RumaRoomAccountDataEvent<$t>| { + listener.on_change(event.into(), room_id.clone()); + }) + }}; } match event_type { RoomAccountDataEventType::FullyRead => { - observe!( - RumaRoomAccountDataEvent, - |event: RumaRoomAccountDataEvent| { - listener.on_change(event.into(), room_id.clone()); - } - ) + observe!(FullyReadEventContent) } RoomAccountDataEventType::MarkedUnread => { - observe!( - RumaRoomAccountDataEvent, - |event: RumaRoomAccountDataEvent| { - listener.on_change(event.into(), room_id.clone()); - } - ) + observe!(MarkedUnreadEventContent) } RoomAccountDataEventType::Tag => { - observe!( - RumaRoomAccountDataEvent, - |event: RumaRoomAccountDataEvent| { - if let Ok(event) = event.try_into() { - listener.on_change(event, room_id.clone()); - } + observe!(TagEventContent, |event: RumaRoomAccountDataEvent| { + if let Ok(event) = event.try_into() { + listener.on_change(event, room_id.clone()); } - ) + }) } RoomAccountDataEventType::UnstableMarkedUnread => { - observe!( - RumaRoomAccountDataEvent, - |event: RumaRoomAccountDataEvent| { - listener.on_change(event.into(), room_id.clone()); - } - ) + observe!(UnstableMarkedUnreadEventContent) } } }