From 91072bb9c603ec8930b49db1fc9b2efe63458f4f Mon Sep 17 00:00:00 2001 From: ericz Date: Thu, 12 Mar 2026 09:53:40 +0100 Subject: [PATCH] handling smaz for sending the same way, to fix displaying compressed text in channel history. --- lib/connector/meshcore_connector.dart | 18 +++++++++++------- lib/screens/channel_chat_screen.dart | 13 +++++-------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 89aeca0..ed0c237 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -1886,13 +1886,7 @@ class MeshCoreConnector extends ChangeNotifier { _pendingChannelSentQueue.add(message.messageId); notifyListeners(); - final trimmed = text.trim(); - final isStructuredPayload = - trimmed.startsWith('g:') || trimmed.startsWith('m:'); - final outboundText = - (isChannelSmazEnabled(channel.index) && !isStructuredPayload) - ? Smaz.encodeIfSmaller(text) - : text; + final outboundText = prepareChannelOutboundText(channel.index, text); await sendFrame( buildSendChannelTextMsgFrame(channel.index, outboundText), channelSendQueueId: message.messageId, @@ -3152,6 +3146,16 @@ class MeshCoreConnector extends ChangeNotifier { return text; } + String prepareChannelOutboundText(int channelIndex, String text) { + final trimmed = text.trim(); + final isStructuredPayload = + trimmed.startsWith('g:') || trimmed.startsWith('m:'); + if (!isStructuredPayload && isChannelSmazEnabled(channelIndex)) { + return Smaz.encodeIfSmaller(text); + } + return text; + } + String _channelDisplayName(int channelIndex) { for (final channel in _channels) { if (channel.index != channelIndex) continue; diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index ecacf49..5a17d89 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -1243,13 +1243,10 @@ class _ChannelChatScreenState extends State { } final maxBytes = maxChannelMessageBytes(connector.selfName); - final smazEnabled = connector.isChannelSmazEnabled(widget.channel.index); - final trimmed = messageText.trim(); - final isStructuredPayload = - trimmed.startsWith('g:') || trimmed.startsWith('m:'); - final outboundText = (smazEnabled && !isStructuredPayload) - ? Smaz.encodeIfSmaller(messageText) - : messageText; + final outboundText = connector.prepareChannelOutboundText( + widget.channel.index, + messageText, + ); if (utf8.encode(outboundText).length > maxBytes) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(context.l10n.chat_messageTooLong(maxBytes))), @@ -1257,7 +1254,7 @@ class _ChannelChatScreenState extends State { return; } - connector.sendChannelMessage(widget.channel, outboundText); + connector.sendChannelMessage(widget.channel, messageText); _textController.clear(); _cancelReply(); _textFieldFocusNode.requestFocus();