-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-858: Add ADR for how to detect unread message
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
docs/adr/0015-callback-for-when-messages-become-visible-or-scroll-out-of-view.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# 14. Add a callback for when messages become visible or scroll out of view | ||
|
||
Date: 2023-12-05 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
- We have a lot of unread messages in the room. | ||
- When we open the room, we need to set messages is read. | ||
|
||
## Decision | ||
|
||
- We use `visibility_detector` to detect when messages become visible or scroll out of view. | ||
- We use `onVisibilityChanged` to listen callback when messages become visible or scroll out of | ||
view. | ||
|
||
``` | ||
VisibilityDetector( | ||
key: Key(message.id), | ||
onVisibilityChanged: (visibilityInfo) { | ||
if (visibilityInfo.visibleFraction == 1.0) { | ||
/// set message is read | ||
handleMessageVisibilityChanged(message, true); | ||
} | ||
}, | ||
``` | ||
|
||
``` | ||
void handleMessageVisibilityChanged(Event event, bool visible) { | ||
if (_isJumpingToLastReadEvent) return; | ||
Logs().d( | ||
'Chat::handleMessageVisibilityChanged() - isVisible $visible', | ||
); | ||
final isUnreadEvent = _unreadEvents.toList().firstWhereOrNull( | ||
(event) => event?.eventId == event?.eventId, | ||
); | ||
final inputBarHasChange = inputFocus.hasFocus; | ||
if (isUnreadEvent != null && inputBarHasChange) { | ||
_setReadMarkerEvent(isUnreadEvent); | ||
} | ||
if (isUnreadEvent != null && visible && !_isJumpingToLastReadEvent) { | ||
Logs().d( | ||
'Chat::handleMessageVisibilityChanged() - Set read Event ${isUnreadEvent.eventId}', | ||
); | ||
_setReadMarkerEvent(isUnreadEvent); | ||
} | ||
} | ||
``` | ||
|
||
## Consequences | ||
|
||
- Continuous listening will affect the app's performance | ||
- The processing mechanism is not really effective because the SDK only supports setting markers for | ||
1 event | ||
|
||
## Docs | ||
|
||
https://pub.dev/packages/visibility_detector |