Skip to content

feat(ui): consider unthreaded read receipts when computing the user's latest on thread aware timeline instances #5442

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 10 additions & 7 deletions crates/matrix-sdk-ui/src/timeline/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,13 +1225,16 @@ impl<P: RoomDataProvider, D: Decryptor> TimelineController<P, D> {
&self,
user_id: &UserId,
) -> Option<(OwnedEventId, Receipt)> {
let receipt_thread = self.focus.receipt_thread();

self.state
.read()
.await
.latest_user_read_receipt(user_id, receipt_thread, &self.room_data_provider)
.await
self.items().await.iter().rev().find_map(|item| {
if let Some(event) = item.as_event()
&& let Some(event_id) = event.event_id()
&& let Some(receipt) = event.read_receipts().get(user_id)
{
Some((event_id.to_owned(), receipt.clone()))
} else {
None
}
})
}

/// Get the ID of the timeline event with the latest read receipt for the
Expand Down
67 changes: 62 additions & 5 deletions crates/matrix-sdk-ui/src/timeline/controller/read_receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,9 @@ impl<P: RoomDataProvider> TimelineStateTransaction<'_, P> {
}

for (user_id, receipt) in receipts {
if own_receipt_thread == ReceiptThread::Unthreaded {
// If the own receipt thread is unthreaded, we maintain maximal
if matches!(own_receipt_thread, ReceiptThread::Unthreaded | ReceiptThread::Main)
{
// If the own receipt thread is unthreaded or main, we maintain maximal
// compatibility with clients using either unthreaded or main-thread read
// receipts by allowing both here.
if !matches!(
Expand Down Expand Up @@ -710,7 +711,7 @@ impl<P: RoomDataProvider> TimelineState<P> {
) -> Option<(OwnedEventId, Receipt)> {
let all_remote_events = self.items.all_remote_events();

let public_read_receipt = self
let threaded_public_read_receipt = self
.meta
.user_receipt(
user_id,
Expand All @@ -721,17 +722,73 @@ impl<P: RoomDataProvider> TimelineState<P> {
)
.await;

let private_read_receipt = self
// If the current client is thread aware and the own receipt thread is main,
// we maintain maximal compatibility with other clients using either unthreaded
// or main-thread read receipts by allowing both here and taking the
// most recent one.
let unthreaded_public_read_receipt = if receipt_thread == ReceiptThread::Main {
self.meta
.user_receipt(
user_id,
ReceiptType::Read,
ReceiptThread::Unthreaded,
room_data_provider,
all_remote_events,
)
.await
} else {
None
};

let public_read_receipt = match self.meta.compare_optional_receipts(
threaded_public_read_receipt.as_ref(),
unthreaded_public_read_receipt.as_ref(),
all_remote_events,
) {
Ordering::Greater => threaded_public_read_receipt,
Ordering::Less => unthreaded_public_read_receipt,
_ => unreachable!(),
};

let threaded_private_read_receipt = self
.meta
.user_receipt(
user_id,
ReceiptType::ReadPrivate,
receipt_thread,
receipt_thread.clone(),
room_data_provider,
all_remote_events,
)
.await;

// If the current client is thread aware and the own receipt thread is main,
// we maintain maximal compatibility with other clients using either unthreaded
// or main-thread read receipts by allowing both here and taking the
// most recent one.
let unthreaded_private_read_receipt = if receipt_thread == ReceiptThread::Main {
self.meta
.user_receipt(
user_id,
ReceiptType::ReadPrivate,
ReceiptThread::Unthreaded,
room_data_provider,
all_remote_events,
)
.await
} else {
None
};

let private_read_receipt = match self.meta.compare_optional_receipts(
threaded_private_read_receipt.as_ref(),
unthreaded_private_read_receipt.as_ref(),
all_remote_events,
) {
Ordering::Greater => threaded_private_read_receipt,
Ordering::Less => unthreaded_private_read_receipt,
_ => unreachable!(),
};

// Let's assume that a private read receipt should be more recent than a public
// read receipt (otherwise there's no point in the private read receipt),
// and use it as the default.
Expand Down
Loading
Loading