Skip to content

Commit 5960471

Browse files
pixlwaveHywan
authored andcommitted
chore: Re-use the existing track_read_receipts setting to hide receipts on state events.
# Conflicts: # bindings/matrix-sdk-ffi/CHANGELOG.md
1 parent d563ceb commit 5960471

File tree

16 files changed

+133
-74
lines changed

16 files changed

+133
-74
lines changed

benchmarks/benches/timeline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
22
use matrix_sdk::test_utils::mocks::MatrixMockServer;
33
use matrix_sdk_test::{JoinedRoomBuilder, StateTestEvent, event_factory::EventFactory};
4-
use matrix_sdk_ui::timeline::TimelineBuilder;
4+
use matrix_sdk_ui::timeline::{TimelineBuilder, TimelineReadReceiptTracking};
55
use ruma::{
66
EventId, events::room::message::RoomMessageEventContentWithoutRelation, owned_room_id,
77
owned_user_id,
@@ -103,7 +103,7 @@ pub fn create_timeline_with_initial_events(c: &mut Criterion) {
103103
|b| {
104104
b.to_async(&runtime).iter(|| async {
105105
let timeline = TimelineBuilder::new(&room)
106-
.track_read_marker_and_receipts()
106+
.track_read_marker_and_receipts(TimelineReadReceiptTracking::AllEvents)
107107
.build()
108108
.await
109109
.expect("Could not create timeline");

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ All notable changes to this project will be documented in this file.
88

99
### Breaking changes
1010

11+
- `TimelineConfiguration::track_read_receipts`'s type is now an enum to allow tracking to be enabled for all events
12+
(like before) or only for message-like events (which prevents read receipts from being placed on state events).
13+
([#5900](https://github.com/matrix-org/matrix-rust-sdk/pull/5900))
1114
- `Client::reset_server_info()` has been split into `reset_supported_versions()`
1215
and `reset_well_known()`.
1316
([#5910](https://github.com/matrix-org/matrix-rust-sdk/pull/5910))

bindings/matrix-sdk-ffi/src/room/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ impl Room {
234234
builder = builder
235235
.with_focus(configuration.focus.try_into()?)
236236
.with_date_divider_mode(configuration.date_divider_mode.into())
237-
.state_events_can_show_read_receipts(configuration.state_events_can_show_read_receipts);
238-
239-
if configuration.track_read_receipts {
240-
builder = builder.track_read_marker_and_receipts();
241-
}
237+
.track_read_marker_and_receipts(configuration.track_read_receipts);
242238

243239
match configuration.filter {
244240
TimelineFilter::All => {

bindings/matrix-sdk-ffi/src/timeline/configuration.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::sync::Arc;
22

3-
use matrix_sdk_ui::timeline::event_type_filter::TimelineEventTypeFilter as InnerTimelineEventTypeFilter;
3+
use matrix_sdk_ui::timeline::{
4+
event_type_filter::TimelineEventTypeFilter as InnerTimelineEventTypeFilter,
5+
TimelineReadReceiptTracking,
6+
};
47
use ruma::{
58
events::{AnySyncTimelineEvent, TimelineEventType},
69
EventId,
@@ -164,9 +167,6 @@ pub struct TimelineConfiguration {
164167
/// How should we filter out events from the timeline?
165168
pub filter: TimelineFilter,
166169

167-
/// Can read receipts be shown on state events or only on messages?
168-
pub state_events_can_show_read_receipts: bool,
169-
170170
/// An optional String that will be prepended to
171171
/// all the timeline item's internal IDs, making it possible to
172172
/// distinguish different timeline instances from each other.
@@ -176,11 +176,11 @@ pub struct TimelineConfiguration {
176176
pub date_divider_mode: DateDividerMode,
177177

178178
/// Should the read receipts and read markers be tracked for the timeline
179-
/// items in this instance?
179+
/// items in this instance and on which event types?
180180
///
181181
/// As this has a non negligible performance impact, make sure to enable it
182182
/// only when you need it.
183-
pub track_read_receipts: bool,
183+
pub track_read_receipts: TimelineReadReceiptTracking,
184184

185185
/// Whether this timeline instance should report UTDs through the client's
186186
/// delegate.

crates/matrix-sdk-ui/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
66

77
## [Unreleased] - ReleaseDate
88

9+
### Features
10+
11+
- [**breaking**] `TimelineBuilder::track_read_marker_and_receipts` now takes a parameter to allow tracking to be enabled
12+
for all events (like before) or only for message-like events (which prevents read receipts from being placed on state
13+
events).
14+
([#5900](https://github.com/matrix-org/matrix-rust-sdk/pull/5900))
15+
916
## [0.15.0] - 2025-11-27
1017

1118
### Features

crates/matrix-sdk-ui/src/timeline/builder.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use super::{
2525
};
2626
use crate::{
2727
timeline::{
28+
TimelineReadReceiptTracking,
2829
controller::spawn_crypto_tasks,
2930
tasks::{
3031
pinned_events_task, room_event_cache_updates_task, room_send_queue_update_task,
@@ -91,17 +92,17 @@ impl TimelineBuilder {
9192
self
9293
}
9394

94-
/// Chose when to insert the date separators, either in between each day
95+
/// Choose when to insert the date separators, either in between each day
9596
/// or each month.
9697
pub fn with_date_divider_mode(mut self, mode: DateDividerMode) -> Self {
9798
self.settings.date_divider_mode = mode;
9899
self
99100
}
100101

101-
/// Enable tracking of the fully-read marker and the read receipts on the
102-
/// timeline.
103-
pub fn track_read_marker_and_receipts(mut self) -> Self {
104-
self.settings.track_read_receipts = true;
102+
/// Choose whether to enable tracking of the fully-read marker and the read
103+
/// receipts and on which event types.
104+
pub fn track_read_marker_and_receipts(mut self, tracking: TimelineReadReceiptTracking) -> Self {
105+
self.settings.track_read_receipts = tracking;
105106
self
106107
}
107108

@@ -141,11 +142,6 @@ impl TimelineBuilder {
141142
self
142143
}
143144

144-
pub fn state_events_can_show_read_receipts(mut self, show: bool) -> Self {
145-
self.settings.state_events_can_show_read_receipts = show;
146-
self
147-
}
148-
149145
/// Whether to add events that failed to deserialize to the timeline.
150146
///
151147
/// Defaults to `true`.
@@ -159,7 +155,7 @@ impl TimelineBuilder {
159155
skip(self),
160156
fields(
161157
room_id = ?self.room.room_id(),
162-
track_read_receipts = self.settings.track_read_receipts,
158+
track_read_receipts = ?self.settings.track_read_receipts,
163159
)
164160
)]
165161
pub async fn build(self) -> Result<Timeline, Error> {

crates/matrix-sdk-ui/src/timeline/controller/mod.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub(super) use self::{
6161
use super::{
6262
DateDividerMode, EmbeddedEvent, Error, EventSendState, EventTimelineItem, InReplyToDetails,
6363
MediaUploadProgress, PaginationError, Profile, TimelineDetails, TimelineEventItemId,
64-
TimelineFocus, TimelineItem, TimelineItemContent, TimelineItemKind, VirtualTimelineItem,
64+
TimelineFocus, TimelineItem, TimelineItemContent, TimelineItemKind,
65+
TimelineReadReceiptTracking, VirtualTimelineItem,
6566
algorithms::{rfind_event_by_id, rfind_event_item},
6667
event_item::{ReactionStatus, RemoteEventOrigin},
6768
item::TimelineUniqueId,
@@ -265,11 +266,9 @@ pub(super) struct TimelineController<P: RoomDataProvider = Room> {
265266

266267
#[derive(Clone)]
267268
pub(super) struct TimelineSettings {
268-
/// Should the read receipts and read markers be handled?
269-
pub(super) track_read_receipts: bool,
270-
271-
/// Whether state events can show read receipts.
272-
pub(super) state_events_can_show_read_receipts: bool,
269+
/// Should the read receipts and read markers be handled and on which event
270+
/// types?
271+
pub(super) track_read_receipts: TimelineReadReceiptTracking,
273272

274273
/// Event filter that controls what's rendered as a timeline item (and thus
275274
/// what can carry read receipts).
@@ -287,7 +286,6 @@ impl fmt::Debug for TimelineSettings {
287286
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
288287
f.debug_struct("TimelineSettings")
289288
.field("track_read_receipts", &self.track_read_receipts)
290-
.field("state_events_can_show_read_receipts", &self.state_events_can_show_read_receipts)
291289
.field("add_failed_to_parse", &self.add_failed_to_parse)
292290
.finish_non_exhaustive()
293291
}
@@ -296,8 +294,7 @@ impl fmt::Debug for TimelineSettings {
296294
impl Default for TimelineSettings {
297295
fn default() -> Self {
298296
Self {
299-
track_read_receipts: false,
300-
state_events_can_show_read_receipts: true,
297+
track_read_receipts: TimelineReadReceiptTracking::Disabled,
301298
event_filter: Arc::new(default_event_filter),
302299
add_failed_to_parse: true,
303300
date_divider_mode: DateDividerMode::Daily,
@@ -986,8 +983,8 @@ impl<P: RoomDataProvider> TimelineController<P> {
986983
{
987984
let mut state = self.state.write().await;
988985

989-
let track_read_markers = self.settings.track_read_receipts;
990-
if track_read_markers {
986+
let track_read_markers = &self.settings.track_read_receipts;
987+
if track_read_markers.is_enabled() {
991988
state.populate_initial_user_receipt(&self.room_data_provider, ReceiptType::Read).await;
992989
state
993990
.populate_initial_user_receipt(&self.room_data_provider, ReceiptType::ReadPrivate)
@@ -1011,7 +1008,7 @@ impl<P: RoomDataProvider> TimelineController<P> {
10111008
.await;
10121009
}
10131010

1014-
if track_read_markers {
1011+
if track_read_markers.is_enabled() {
10151012
if let Some(fully_read_event_id) =
10161013
self.room_data_provider.load_fully_read_marker().await
10171014
{

crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ use super::{
3333
event_item::RemoteEventOrigin,
3434
traits::RoomDataProvider,
3535
},
36-
ObservableItems, ObservableItemsTransaction, TimelineMetadata, TimelineSettings,
36+
ObservableItems, ObservableItemsTransaction, TimelineMetadata, TimelineReadReceiptTracking,
37+
TimelineSettings,
3738
metadata::EventMeta,
3839
};
3940
use crate::timeline::{
@@ -468,8 +469,12 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
468469
event: &AnySyncTimelineEvent,
469470
) -> bool {
470471
match event {
471-
AnySyncTimelineEvent::State(_) => settings.state_events_can_show_read_receipts,
472-
AnySyncTimelineEvent::MessageLike(_) => true,
472+
AnySyncTimelineEvent::State(_) => {
473+
settings.track_read_receipts == TimelineReadReceiptTracking::AllEvents
474+
}
475+
AnySyncTimelineEvent::MessageLike(_) => {
476+
settings.track_read_receipts != TimelineReadReceiptTracking::Disabled
477+
}
473478
}
474479
}
475480

@@ -735,7 +740,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
735740
sender,
736741
sender_profile,
737742
timestamp,
738-
read_receipts: if settings.track_read_receipts
743+
read_receipts: if settings.track_read_receipts.is_enabled()
739744
&& should_add
740745
&& can_show_read_receipts
741746
{
@@ -920,7 +925,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
920925
event.visible = event_meta.visible;
921926
event.can_show_read_receipts = event_meta.can_show_read_receipts;
922927

923-
if settings.track_read_receipts {
928+
if settings.track_read_receipts.is_enabled() {
924929
// Since the event's visibility changed, we need to update the read
925930
// receipts of the previous visible event.
926931
self.maybe_update_read_receipts_of_prev_event(&event_meta.event_id);
@@ -929,7 +934,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
929934
}
930935
}
931936

932-
if settings.track_read_receipts
937+
if settings.track_read_receipts.is_enabled()
933938
&& matches!(
934939
position,
935940
TimelineItemPosition::Start { .. }

crates/matrix-sdk-ui/src/timeline/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,3 +1103,26 @@ impl TryFrom<GalleryItemInfo> for matrix_sdk::attachment::GalleryItemInfo {
11031103
})
11041104
}
11051105
}
1106+
1107+
#[derive(Clone, Debug, PartialEq)]
1108+
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
1109+
/// The level of read receipt tracking for the timeline.
1110+
pub enum TimelineReadReceiptTracking {
1111+
/// Track read receipts for all events.
1112+
AllEvents,
1113+
/// Track read receipts only for message-like events.
1114+
MessageLikeEvents,
1115+
/// Disable read receipt tracking.
1116+
Disabled,
1117+
}
1118+
1119+
impl TimelineReadReceiptTracking {
1120+
/// Whether or not read receipt tracking is enabled.
1121+
pub fn is_enabled(&self) -> bool {
1122+
match self {
1123+
TimelineReadReceiptTracking::AllEvents => true,
1124+
TimelineReadReceiptTracking::MessageLikeEvents => true,
1125+
TimelineReadReceiptTracking::Disabled => false,
1126+
}
1127+
}
1128+
}

crates/matrix-sdk-ui/src/timeline/tests/basic.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use stream_assert::{assert_next_matches, assert_pending};
4242
use super::TestTimeline;
4343
use crate::timeline::{
4444
MembershipChange, MsgLikeContent, MsgLikeKind, RoomExt, TimelineDetails, TimelineFocus,
45-
TimelineItemContent, TimelineItemKind, VirtualTimelineItem,
45+
TimelineItemContent, TimelineItemKind, TimelineReadReceiptTracking, VirtualTimelineItem,
4646
controller::TimelineSettings,
4747
event_item::{AnyOtherFullStateEventContent, RemoteEventOrigin},
4848
tests::{ReadReceiptMap, TestRoomDataProvider, TestTimelineBuilder},
@@ -99,8 +99,7 @@ async fn test_replace_with_initial_events_and_read_marker() {
9999
.with_initial_user_receipts(receipts),
100100
)
101101
.settings(TimelineSettings {
102-
track_read_receipts: true,
103-
state_events_can_show_read_receipts: true,
102+
track_read_receipts: TimelineReadReceiptTracking::AllEvents,
104103
..Default::default()
105104
})
106105
.build();
@@ -527,7 +526,7 @@ async fn test_latest_event_id_in_main_timeline() {
527526
let timeline = room
528527
.timeline_builder()
529528
.with_focus(TimelineFocus::Live { hide_threaded_events: true })
530-
.track_read_marker_and_receipts()
529+
.track_read_marker_and_receipts(TimelineReadReceiptTracking::AllEvents)
531530
.build()
532531
.await
533532
.expect("Could not build live timeline");

0 commit comments

Comments
 (0)