fix(app): mark deep-linked chat sessions read

This commit is contained in:
2026-10-22 23:59:13 +01:00
parent b82bdd327a
commit fd496a7b20
2 changed files with 71 additions and 0 deletions
@@ -68,6 +68,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
..refresh();
final _search = TextEditingController();
Timer? _undoTimer;
String? _markedActiveSessionId;
@override
void initState() {
@@ -78,6 +79,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
/// Reports the loaded rows at the end of the frame: the destination learns a
/// routed row without this screen calling back inside its own build.
void _reportSessions() {
_markActiveSessionRead();
if (widget.onSessions == null) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
@@ -85,10 +87,28 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
});
}
void _markActiveSessionRead() {
final id = widget.activeSessionId;
if (id == null) {
_markedActiveSessionId = null;
return;
}
if (id == _markedActiveSessionId) return;
for (final session in _controller.sessions) {
if (_sessionId(session) != id) continue;
// Mark synchronously so row activation and subsequent list notifications
// cannot write the same read watermark twice.
_markedActiveSessionId = id;
unawaited(_controller.markOpened(session));
return;
}
}
@override
void didUpdateWidget(covariant ChatSessionsScreen oldWidget) {
super.didUpdateWidget(oldWidget);
_controller.activeSessionId = widget.activeSessionId;
_markActiveSessionRead();
if (oldWidget.gateway != widget.gateway) {
_controller.replaceRepository(ChatRepository(widget.gateway));
} else if (oldWidget.syncToken != widget.syncToken) {
@@ -141,6 +161,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
}
void _open(JsonMap session) {
_markedActiveSessionId = _sessionId(session);
unawaited(_controller.markOpened(session));
widget.onOpen(session);
}