From de6632d70ecb69abe4eef46bbb2c81075c1d88a0 Mon Sep 17 00:00:00 2001 From: ZIER Date: Tue, 13 Oct 2026 11:19:29 +0200 Subject: [PATCH] fix crash in chat_screen.dart, try to resolve test error. --- lib/connector/meshcore_connector.dart | 16 +++++----- lib/screens/app_settings_screen.dart | 21 +++++++------ lib/screens/chat_screen.dart | 43 +++++++++++++++------------ 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 03b03944..57ef9fc1 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -3794,6 +3794,9 @@ class MeshCoreConnector extends ChangeNotifier { if (pendingAck != null) { _pendingGenericAckQueue.remove(pendingAck); } + if (_activeTransport == MeshCoreTransportType.tcp) { + unawaited(disconnect(manual: false)); + } rethrow; } @@ -5846,17 +5849,16 @@ class MeshCoreConnector extends ChangeNotifier { _findChannelByIndex(index)?.storageId ?? _slotChannelIds[index]; // Delete by setting empty name and zero PSK await sendFrame(buildSetChannelFrame(index, '', Uint8List(16))); + _channelMessages.remove(index); + _processedChannelReactions.remove(index); + // Refresh before clearing history so messages from an in-flight queue sync + // cannot recreate the channel's stored history after it has been deleted. + await getChannels(force: true); // Another slot holding the same PSK keeps the shared history. - final stillHeld = _channels.any( - (channel) => channel.index != index && channel.storageId == channelId, - ); + final stillHeld = _slotChannelIds.containsValue(channelId); if (channelId != null && !stillHeld) { await _clearChannelStorage(channelId); } - _channelMessages.remove(index); - _processedChannelReactions.remove(index); - // Refresh channels after deleting - await getChannels(force: true); } /// Removes everything persisted for [channelId]: messages, settings, diff --git a/lib/screens/app_settings_screen.dart b/lib/screens/app_settings_screen.dart index fd5065e8..16a21dc1 100644 --- a/lib/screens/app_settings_screen.dart +++ b/lib/screens/app_settings_screen.dart @@ -675,7 +675,16 @@ class AppSettingsScreen extends StatelessWidget { onChanged: settingsService.setChannelMinHopsCountRepeaters, ), ], - const Divider(height: 1, indent: 16), + ], + ); + } + + Widget _buildImageMessagesContent( + BuildContext context, + AppSettingsService settingsService, + ) { + return Column( + children: [ ListTile( contentPadding: const EdgeInsets.symmetric( horizontal: 16, @@ -688,16 +697,6 @@ class AppSettingsScreen extends StatelessWidget { onTap: () => _showIpfsImageLinksDialog(context, settingsService), ), const Divider(height: 1, indent: 16), - ], - ); - } - - Widget _buildImageMessagesContent( - BuildContext context, - AppSettingsService settingsService, - ) { - return Column( - children: [ _ScrollIntoViewOnce( enabled: focusImageMessages, child: SwitchListTile( diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index d0c6e9c0..5456ea55 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -507,9 +507,6 @@ class _ChatScreenState extends State { final useEncoder = connector.isContactSmazEnabled(keyHex) || connector.isContactCyr2LatEnabled(keyHex); - final showIpfsAction = context.select( - (s) => s.settings.uploadIpfsEndpoint.trim().isNotEmpty, - ); return ChatComposer( controller: _textController, focusNode: _textFieldFocusNode, @@ -525,24 +522,32 @@ class _ChatScreenState extends State { sendTooltip: context.l10n.chat_sendMessageTo( _resolveContact(connector).name, ), - actionsBuilder: () => [ - ChatComposerAction( - id: 'gif', - icon: Icons.gif_box, - label: context.l10n.chat_sendGif, - ), - if (showIpfsAction) + actionsBuilder: () { + final showIpfsAction = context + .read() + .settings + .uploadIpfsEndpoint + .trim() + .isNotEmpty; + return [ ChatComposerAction( - id: 'ipfs-image', - icon: Icons.cloud_upload_outlined, - label: context.l10n.chat_sendImageIpfs, + id: 'gif', + icon: Icons.gif_box, + label: context.l10n.chat_sendGif, ), - ChatComposerAction( - id: 'send-my-location', - icon: Icons.my_location, - label: context.l10n.chat_shareMyLocation, - ), - ], + if (showIpfsAction) + ChatComposerAction( + id: 'ipfs-image', + icon: Icons.cloud_upload_outlined, + label: context.l10n.chat_sendImageIpfs, + ), + ChatComposerAction( + id: 'send-my-location', + icon: Icons.my_location, + label: context.l10n.chat_shareMyLocation, + ), + ]; + }, onAction: (action) { if (!mounted) return; switch (action) {