Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(WidgetDriver): Send state from state sync and not from timeline to widget #4254

Merged
merged 6 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 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,39 @@ 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));

// Get only message like events from the timeline section of the sync.
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);

// Get only all state events from the state section of the sync.
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 = self.room.client().event_handler_drop_guard(handle);
EventReceiver { rx, _drop_guard: drop_guard }
let drop_guard_state = self.room.client().event_handler_drop_guard(handle_state);

// The receiver will get a combination of state and message like events.
// The state events will come from the state section of the sync (to always
// represent current resolved state). All state events in the timeline
// section of the sync will not be forwarded to the widget.
// TODO annotate the events and send both timeline and state section state
// events.
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
Loading