State machine work

This commit is contained in:
Christien Rioux 2025-05-23 11:30:26 -04:00
parent 61855521dc
commit be8014c97a
34 changed files with 703 additions and 505 deletions

View file

@ -54,10 +54,9 @@ class ChatComponentWidget extends StatefulWidget {
final contactListCubit = context.watch<ContactListCubit>();
// Get the active conversation cubit
final activeConversationCubit = context
.select<ActiveConversationsBlocMapCubit, ActiveConversationCubit?>(
(x) => x.tryOperateSync(localConversationRecordKey,
closure: (cubit) => cubit));
final activeConversationCubit = context.select<
ActiveConversationsBlocMapCubit,
ActiveConversationCubit?>((x) => x.entry(localConversationRecordKey));
if (activeConversationCubit == null) {
return waitingPage(onCancel: onCancel);
}
@ -65,8 +64,7 @@ class ChatComponentWidget extends StatefulWidget {
// Get the messages cubit
final messagesCubit = context.select<ActiveSingleContactChatBlocMapCubit,
SingleContactMessagesCubit?>(
(x) => x.tryOperateSync(localConversationRecordKey,
closure: (cubit) => cubit));
(x) => x.entry(localConversationRecordKey));
if (messagesCubit == null) {
return waitingPage(onCancel: onCancel);
}
@ -106,10 +104,11 @@ class _ChatComponentWidgetState extends State<ChatComponentWidget> {
_textEditingController = TextEditingController();
_scrollController = ScrollController();
_chatStateProcessor = SingleStateProcessor<ChatComponentState>();
_focusNode = FocusNode();
final _chatComponentCubit = context.read<ChatComponentCubit>();
_chatStateProcessor.follow(_chatComponentCubit.stream,
_chatComponentCubit.state, _updateChatState);
final chatComponentCubit = context.read<ChatComponentCubit>();
_chatStateProcessor.follow(
chatComponentCubit.stream, chatComponentCubit.state, _updateChatState);
super.initState();
}
@ -118,6 +117,7 @@ class _ChatComponentWidgetState extends State<ChatComponentWidget> {
void dispose() {
unawaited(_chatStateProcessor.close());
_focusNode.dispose();
_chatController.dispose();
_scrollController.dispose();
_textEditingController.dispose();
@ -281,6 +281,7 @@ class _ChatComponentWidgetState extends State<ChatComponentWidget> {
// Composer builder
composerBuilder: (ctx) => VcComposerWidget(
autofocus: true,
focusNode: _focusNode,
textInputAction: isAnyMobile
? TextInputAction.newline
: TextInputAction.send,
@ -399,6 +400,8 @@ class _ChatComponentWidgetState extends State<ChatComponentWidget> {
}
void _handleSendPressed(ChatComponentCubit chatComponentCubit, String text) {
_focusNode.requestFocus();
if (text.startsWith('/')) {
chatComponentCubit.runCommand(text);
return;
@ -491,4 +494,5 @@ class _ChatComponentWidgetState extends State<ChatComponentWidget> {
late final TextEditingController _textEditingController;
late final ScrollController _scrollController;
late final SingleStateProcessor<ChatComponentState> _chatStateProcessor;
late final FocusNode _focusNode;
}