wip(app): chat-cmd-session (retained from the failed lane tree)
This commit is contained in:
@@ -141,6 +141,21 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
return Map<String, dynamic>.from(session);
|
||||
}
|
||||
|
||||
/// Lists a session the server just created at the head of the loaded rows,
|
||||
/// so the row is present before its conversation opens; the caller re-reads
|
||||
/// the list from the server afterwards. A row with the same id is replaced,
|
||||
/// never duplicated.
|
||||
void insertCreated(JsonMap session) {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
_sessions = [
|
||||
session,
|
||||
for (final row in _sessions)
|
||||
if ('${row['id'] ?? ''}' != id) row,
|
||||
];
|
||||
_seedLocal();
|
||||
_notify();
|
||||
}
|
||||
|
||||
/// Records that this device has read [session]'s current recency.
|
||||
Future<void> markOpened(JsonMap session) async {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
|
||||
@@ -23,6 +23,7 @@ class ChatSessionsScreen extends StatefulWidget {
|
||||
this.syncToken = 0,
|
||||
this.onSessions,
|
||||
this.localStore,
|
||||
this.controller,
|
||||
});
|
||||
final ApiGateway gateway;
|
||||
final void Function(JsonMap session) onOpen;
|
||||
@@ -42,15 +43,23 @@ class ChatSessionsScreen extends StatefulWidget {
|
||||
/// Overrides the device-local hidden/read store in tests.
|
||||
final ChatSessionLocalStore? localStore;
|
||||
|
||||
/// A list controller the destination owns and keeps across this screen's
|
||||
/// life, so a session created from an open conversation can be listed here.
|
||||
/// Null makes this screen own its own.
|
||||
final ChatSessionsController? controller;
|
||||
|
||||
@override
|
||||
State<ChatSessionsScreen> createState() => _ChatSessionsScreenState();
|
||||
}
|
||||
|
||||
class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
late final ChatSessionsController _controller = ChatSessionsController(
|
||||
ChatRepository(widget.gateway),
|
||||
localStore: widget.localStore,
|
||||
)..refresh();
|
||||
late final ChatSessionsController _controller =
|
||||
(widget.controller ??
|
||||
ChatSessionsController(
|
||||
ChatRepository(widget.gateway),
|
||||
localStore: widget.localStore,
|
||||
))
|
||||
..refresh();
|
||||
final _search = TextEditingController();
|
||||
Timer? _undoTimer;
|
||||
|
||||
@@ -84,7 +93,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
void dispose() {
|
||||
_undoTimer?.cancel();
|
||||
_controller.removeListener(_reportSessions);
|
||||
_controller.dispose();
|
||||
if (widget.controller == null) _controller.dispose();
|
||||
_search.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user