refactor(sdk): Create non-generic fn call_event_handlers
Extracted out of handle_sync_events_wrapped_with.
@@ -412,6 +412,21 @@ impl Client {
let (ev_kind, ev_type) = get_id(raw_event)?;
let ev_type: &str = ev_type.as_ref();
+ self.call_event_handlers(room, raw_event.json(), ev_kind, ev_type, encryption_info)
+ .await;
+ }
+
+ Ok(())
+ }
+
+ async fn call_event_handlers(
+ &self,
+ room: &Option<room::Room>,
+ raw: &RawJsonValue,
+ ev_kind: EventKind,
+ ev_type: &str,
+ encryption_info: Option<&EncryptionInfo>,
+ ) {
// Construct event handler futures
let futures: Vec<_> = {
let handlers_lock = self.event_handlers().await;
@@ -432,13 +447,11 @@ impl Client {
non_room_event_handlers
.chain(room_event_handlers)
.map(|handler_wrapper| {
- let data = EventHandlerData {
- client: self.clone(),
- room: room.clone(),
- raw: raw_event.json(),
- encryption_info,
- handle: handler_wrapper.handle,
- };
+ let client = self.clone();
+ let room = room.clone();
+ let handle = handler_wrapper.handle;
+ let data = EventHandlerData { client, room, raw, encryption_info, handle };
+
(handler_wrapper.handler_fn)(data)
})
.collect()
@@ -450,9 +463,6 @@ impl Client {
fut.await;
}
}
-
- Ok(())
- }
}
macro_rules! impl_event_handler {
