Skip to content

Commit

Permalink
feat(WidgetDriver): Send state from state sync and not from timeline …
Browse files Browse the repository at this point in the history
…to widget
  • Loading branch information
toger5 committed Nov 13, 2024
1 parent ab61077 commit 2380af6
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions crates/matrix-sdk/src/widget/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ use ruma::{
},
assign,
events::{
AnyMessageLikeEventContent, AnyStateEventContent, AnySyncTimelineEvent, AnyTimelineEvent,
MessageLikeEventType, StateEventType, TimelineEventType,
AnyMessageLikeEventContent, AnyStateEventContent, AnySyncMessageLikeEvent,
AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, MessageLikeEventType,
StateEventType, TimelineEventType,
},
serde::Raw,
RoomId, TransactionId,
Expand Down Expand Up @@ -164,21 +165,31 @@ impl MatrixDriver {
pub(crate) fn events(&self) -> EventReceiver {
let (tx, rx) = unbounded_channel();
let room_id = self.room.room_id().to_owned();
let handle = self.room.add_event_handler(move |raw: Raw<AnySyncTimelineEvent>| {
let _ = tx.send(attach_room_id(&raw, &room_id));

let _tx = tx.clone();
let _room_id = room_id.clone();
let handle_msg_like =
self.room.add_event_handler(move |raw: Raw<AnySyncMessageLikeEvent>| {
let _ = _tx.send(attach_room_id(raw.cast_ref(), &_room_id));
async {}
});
let drop_guard_msg_like = self.room.client().event_handler_drop_guard(handle_msg_like);

let handle_state = self.room.add_event_handler(move |raw: Raw<AnySyncStateEvent>| {
let _ = tx.send(attach_room_id(raw.cast_ref(), &room_id));
async {}
});
let drop_guard_state = self.room.client().event_handler_drop_guard(handle_state);

let drop_guard = self.room.client().event_handler_drop_guard(handle);
EventReceiver { rx, _drop_guard: drop_guard }
EventReceiver { rx, _drop_guards: [drop_guard_msg_like, drop_guard_state] }
}
}

/// A simple entity that wraps an `UnboundedReceiver`
/// along with the drop guard for the room event handler.
pub(crate) struct EventReceiver {
rx: UnboundedReceiver<Raw<AnyTimelineEvent>>,
_drop_guard: EventHandlerDropGuard,
_drop_guards: [EventHandlerDropGuard; 2],
}

impl EventReceiver {
Expand Down

0 comments on commit 2380af6

Please sign in to comment.