fix(app): live New marks clear the active chat on leave; lint and regression tests
This commit is contained in:
@@ -128,6 +128,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
syncToken: widget.syncToken,
|
||||
onOpen: _open,
|
||||
onSessions: _adoptRows,
|
||||
activeSessionId: selected,
|
||||
),
|
||||
),
|
||||
if (selected != null)
|
||||
|
||||
@@ -55,8 +55,9 @@ class ChatSessionLocal {
|
||||
ChatSessionLocal read(String id, int updatedAt) {
|
||||
final nextUnseen = unseen.where((entry) => entry != id).toList();
|
||||
if (id.isEmpty ||
|
||||
(updatedAt <= watermark(id) && nextUnseen.length == unseen.length))
|
||||
(updatedAt <= watermark(id) && nextUnseen.length == unseen.length)) {
|
||||
return this;
|
||||
}
|
||||
return ChatSessionLocal(
|
||||
hidden: hidden,
|
||||
seenAt: updatedAt > watermark(id) ? {...seenAt, id: updatedAt} : seenAt,
|
||||
|
||||
@@ -23,6 +23,7 @@ class ChatSessionsScreen extends StatefulWidget {
|
||||
this.syncToken = 0,
|
||||
this.onSessions,
|
||||
this.localStore,
|
||||
this.activeSessionId,
|
||||
});
|
||||
final ApiGateway gateway;
|
||||
final void Function(JsonMap session) onOpen;
|
||||
@@ -39,6 +40,10 @@ class ChatSessionsScreen extends StatefulWidget {
|
||||
/// title and model facts as a tapped row without a second list request.
|
||||
final ValueChanged<List<JsonMap>>? onSessions;
|
||||
|
||||
/// The conversation open above this list, or null when the list is showing.
|
||||
/// Pushed activity for it is being read, so it never raises a New mark.
|
||||
final String? activeSessionId;
|
||||
|
||||
/// Overrides the device-local hidden/read store in tests.
|
||||
final ChatSessionLocalStore? localStore;
|
||||
|
||||
@@ -47,10 +52,13 @@ class ChatSessionsScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
late final ChatSessionsController _controller = ChatSessionsController(
|
||||
ChatRepository(widget.gateway),
|
||||
localStore: widget.localStore,
|
||||
)..refresh();
|
||||
late final ChatSessionsController _controller =
|
||||
ChatSessionsController(
|
||||
ChatRepository(widget.gateway),
|
||||
localStore: widget.localStore,
|
||||
)
|
||||
..activeSessionId = widget.activeSessionId
|
||||
..refresh();
|
||||
final _search = TextEditingController();
|
||||
Timer? _undoTimer;
|
||||
|
||||
@@ -73,6 +81,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatSessionsScreen oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_controller.activeSessionId = widget.activeSessionId;
|
||||
if (oldWidget.gateway != widget.gateway) {
|
||||
_controller.replaceRepository(ChatRepository(widget.gateway));
|
||||
} else if (oldWidget.syncToken != widget.syncToken) {
|
||||
|
||||
Reference in New Issue
Block a user