Skip to content
Closed
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
43 changes: 30 additions & 13 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,14 @@ class ChatController extends State<ChatPageWithRoom>
// We are already setting a read marker
if (_setReadMarkerFuture != null) return;

// We only set read marker if we are at the bottom
if (_scrolledUp) return;
// We only set read marker if we are at the bottom. Prefer the live
// scroll position, but fall back to the cached flag when no client is
// attached yet.
if (scrollController.hasClients
? scrollController.position.pixels > 0
: _scrolledUp) {
return;
}
Comment thread
ruka-hamanasu marked this conversation as resolved.

// We do not set read marker if we offer user the scroll up banner
if (scrollUpBannerEventId != null) return;
Expand All @@ -614,16 +620,21 @@ class ChatController extends State<ChatPageWithRoom>
}

final setOnLatestEvent = eventId == null;
// When we are viewing a context slice of older events, do not treat
// the newest loaded event as the room's latest event.
if (setOnLatestEvent && timeline.allowNewEvent == false) return;
// Target the latest message-like event. Do not gate this on push rule
// evaluation: read markers track what the user has seen, not what
// notifies them.
eventId ??= timeline.events
.firstWhereOrNull(
(event) => room.pushRuleState == PushRuleState.notify
? room.client.pushruleEvaluator.match(event).notify
: {
EventTypes.Message,
EventTypes.Encrypted,
EventTypes.Sticker,
}.contains(event.type) &&
event.eventId.isValidMatrixIdStrict(),
(event) =>
{
EventTypes.Message,
EventTypes.Encrypted,
EventTypes.Sticker,
}.contains(event.type) &&
event.eventId.isValidMatrixIdStrict(),
Comment thread
ruka-hamanasu marked this conversation as resolved.
)
?.eventId;

Expand All @@ -633,8 +644,10 @@ class ChatController extends State<ChatPageWithRoom>
// This is a sending event, we do not set a readmarker yet
if (eventId.isValidMatrixIdStrict() == false) return;

// Already set a read marker on this event
if (room.fullyRead == eventId) return;
// Already set a read marker on this event, unless the room still shows
// new messages: re-posting refreshes the receipts' timestamps, which the
// unread indicator depends on.
if (room.fullyRead == eventId && !room.hasNewMessages) return;
Comment thread
ruka-hamanasu marked this conversation as resolved.

// Set a readmarker on a specific event, not latest, but room is not unread
// at all.
Expand All @@ -651,7 +664,11 @@ class ChatController extends State<ChatPageWithRoom>
eventId: eventId,
public: AppSettings.sendPublicReadReceipts.value,
)
.then((_) {
.catchError((Object e, StackTrace s) {
Logs().w('Failed to set read marker', e, s);
})
.whenComplete(() {
// Always release the latch, even when the request fails.
Comment thread
ruka-hamanasu marked this conversation as resolved.
_setReadMarkerFuture = null;
});
}
Expand Down