From 2380af6ef59bd34ac2d9fdb68fec658fd7c88540 Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 13 Nov 2024 09:54:28 +0100 Subject: [PATCH 1/6] feat(WidgetDriver): Send state from state sync and not from timeline to widget --- crates/matrix-sdk/src/widget/matrix.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index 96a40d423aa..020dce2fa5c 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -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, @@ -164,13 +165,23 @@ 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| { - 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| { + 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| { + 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] } } } @@ -178,7 +189,7 @@ impl MatrixDriver { /// along with the drop guard for the room event handler. pub(crate) struct EventReceiver { rx: UnboundedReceiver>, - _drop_guard: EventHandlerDropGuard, + _drop_guards: [EventHandlerDropGuard; 2], } impl EventReceiver { From 8d8883c8204ea8cd5c9c18fa969b4551650ca799 Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 13 Nov 2024 10:29:45 +0100 Subject: [PATCH 2/6] add comments --- crates/matrix-sdk/src/widget/matrix.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index 020dce2fa5c..a25e00c6823 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -166,6 +166,7 @@ impl MatrixDriver { let (tx, rx) = unbounded_channel(); let room_id = self.room.room_id().to_owned(); + // 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 = @@ -175,12 +176,18 @@ impl MatrixDriver { }); 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| { 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); + // The receiver will get a combination of state and messgage like events. + // The state events will come from the state section of the sync. + // 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] } } } From 966c3e450dd5d0d4ac0492a936a4e6386097aada Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 13 Nov 2024 10:30:29 +0100 Subject: [PATCH 3/6] add comments --- crates/matrix-sdk/src/widget/matrix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index a25e00c6823..7d911975fc9 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -184,7 +184,7 @@ impl MatrixDriver { let drop_guard_state = self.room.client().event_handler_drop_guard(handle_state); // The receiver will get a combination of state and messgage like events. - // The state events will come from the state section of the sync. + // 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. From 71f6c9dc1b27fde2faaf0e72e9e12bc00fc5fd19 Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 13 Nov 2024 16:41:23 +0100 Subject: [PATCH 4/6] fmt --- crates/matrix-sdk/src/widget/matrix.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index 7d911975fc9..e0c56425c8f 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -184,10 +184,11 @@ impl MatrixDriver { let drop_guard_state = self.room.client().event_handler_drop_guard(handle_state); // The receiver will get a combination of state and messgage 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. + // 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] } } } From 43efc6a3dad4a2bbab015928de751b2175fcd8f0 Mon Sep 17 00:00:00 2001 From: Timo <16718859+toger5@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:15:01 +0100 Subject: [PATCH 5/6] Update crates/matrix-sdk/src/widget/matrix.rs Co-authored-by: Stefan Ceriu Signed-off-by: Timo <16718859+toger5@users.noreply.github.com> --- crates/matrix-sdk/src/widget/matrix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index e0c56425c8f..bf2af78effe 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -183,7 +183,7 @@ impl MatrixDriver { }); let drop_guard_state = self.room.client().event_handler_drop_guard(handle_state); - // The receiver will get a combination of state and messgage like events. + // 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. From ee7c80c234c10fd370c1e6c20656e57260d94f3d Mon Sep 17 00:00:00 2001 From: Timo <16718859+toger5@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:15:07 +0100 Subject: [PATCH 6/6] Update crates/matrix-sdk/src/widget/matrix.rs Co-authored-by: Stefan Ceriu Signed-off-by: Timo <16718859+toger5@users.noreply.github.com> --- crates/matrix-sdk/src/widget/matrix.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index bf2af78effe..d8f4bb3e58a 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -184,8 +184,8 @@ impl MatrixDriver { 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 + // 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.