feat(event cache): automatically request paginations when no receipt has been found when computing unread counts
This commit is contained in:
@@ -108,9 +108,10 @@ use ruma::{
|
||||
},
|
||||
serde::Raw,
|
||||
};
|
||||
use tokio::sync::mpsc::Sender;
|
||||
use tracing::{debug, instrument, trace, warn};
|
||||
|
||||
use crate::event_cache::caches::event_linked_chunk::EventLinkedChunk;
|
||||
use crate::event_cache::{caches::event_linked_chunk::EventLinkedChunk, tasks::BackgroundRequest};
|
||||
|
||||
trait RoomReadReceiptsExt {
|
||||
/// Update the [`RoomReadReceipts`] unread counts according to the new
|
||||
@@ -363,6 +364,7 @@ pub(crate) fn compute_unread_counts(
|
||||
linked_chunk: &EventLinkedChunk,
|
||||
read_receipts: &mut RoomReadReceipts,
|
||||
with_threading_support: bool,
|
||||
background_request_sender: Option<&Sender<BackgroundRequest>>,
|
||||
) {
|
||||
debug!(?read_receipts, "Starting");
|
||||
|
||||
@@ -375,6 +377,18 @@ pub(crate) fn compute_unread_counts(
|
||||
with_threading_support,
|
||||
);
|
||||
|
||||
if select_best_receipt_result.request_pagination {
|
||||
trace!("Requesting pagination to find a better receipt");
|
||||
// Note: we use `try_send` here to keep the method sync, as computing the
|
||||
// perfect receipt is best effort.
|
||||
if let Some(sender) = background_request_sender
|
||||
&& let Err(err) = sender
|
||||
.try_send(BackgroundRequest::PaginateRoomBackwards { room_id: room_id.to_owned() })
|
||||
{
|
||||
warn!(%err, "Failed to request pagination to find a better receipt");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(event_id) = select_best_receipt_result.receipt {
|
||||
// We've found the id of an event to which the receipt attaches. The associated
|
||||
// event may either come from the new batch of events associated to
|
||||
|
||||
@@ -1046,9 +1046,8 @@ impl<'a> RoomEventCacheStateLockWriteGuard<'a> {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let state = &mut *self.state;
|
||||
let user_id = &state.own_user_id;
|
||||
let room_id = &state.room_id;
|
||||
let user_id = &self.state.own_user_id;
|
||||
let room_id = &self.state.room_id;
|
||||
|
||||
let prev_read_receipts = room.read_receipts().clone();
|
||||
let mut read_receipts = prev_read_receipts.clone();
|
||||
@@ -1057,9 +1056,10 @@ impl<'a> RoomEventCacheStateLockWriteGuard<'a> {
|
||||
user_id,
|
||||
room_id,
|
||||
receipt_event,
|
||||
&state.room_linked_chunk,
|
||||
&self.state.room_linked_chunk,
|
||||
&mut read_receipts,
|
||||
state.enabled_thread_support,
|
||||
self.state.enabled_thread_support,
|
||||
self.state.background_request_sender.as_ref(),
|
||||
);
|
||||
|
||||
if prev_read_receipts != read_receipts {
|
||||
|
||||
Reference in New Issue
Block a user