Add optional SMAZ compression indicator icon on messages
This commit is contained in:
1 parent
ae967ec21f
commit
d76d488e45
36 files changed
+1321
-38
No files matched your search
@@ -5171,9 +5171,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
}) async {
|
||||
if (!isConnected || text.isEmpty) return;
|
||||
|
||||
final outboundBytes = utf8.encode(
|
||||
prepareContactOutboundText(contact, text),
|
||||
);
|
||||
final prepared = prepareContactOutbound(contact, text);
|
||||
final outboundBytes = utf8.encode(prepared.text);
|
||||
if (outboundBytes.length > maxTextPayloadBytes) {
|
||||
debugPrint(
|
||||
'sendMessage: dropping overlong message '
|
||||
@@ -5222,6 +5221,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
originalText: originalText,
|
||||
translatedLanguageCode: translatedLanguageCode,
|
||||
translationModelId: translationModelId,
|
||||
isSmazCompressed: prepared.isSmazCompressed,
|
||||
);
|
||||
} else {
|
||||
// Fallback to old behavior if retry service not initialized
|
||||
@@ -5234,11 +5234,11 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
originalText: originalText,
|
||||
translatedLanguageCode: translatedLanguageCode,
|
||||
translationModelId: translationModelId,
|
||||
isSmazCompressed: prepared.isSmazCompressed,
|
||||
);
|
||||
_addMessage(contact.publicKeyHex, message); // recipient as "sender"
|
||||
notifyListeners();
|
||||
final outboundText = prepareContactOutboundText(contact, text);
|
||||
await sendFrame(buildSendTextMsgFrame(contact.publicKey, outboundText));
|
||||
await sendFrame(buildSendTextMsgFrame(contact.publicKey, prepared.text));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5661,6 +5661,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
// we continue to process it normally.
|
||||
}
|
||||
|
||||
final prepared = prepareChannelOutbound(channel.index, text);
|
||||
final message = ChannelMessage.outgoing(
|
||||
text,
|
||||
_selfName ?? 'Me',
|
||||
@@ -5670,12 +5671,13 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
translationModelId: translationModelId,
|
||||
region: sendRegion,
|
||||
replyTo: replyTo,
|
||||
isSmazCompressed: prepared.isSmazCompressed,
|
||||
);
|
||||
_addChannelMessage(channel.index, message);
|
||||
_pendingChannelSentQueue.add(message.messageId);
|
||||
notifyListeners();
|
||||
|
||||
final outboundText = prepareChannelOutboundText(channel.index, text);
|
||||
final outboundText = prepared.text;
|
||||
// Resends reuse the timestamp, so they are the same packet: repeaters
|
||||
// that already forwarded it drop the copy and recipients see it once.
|
||||
Future<void> transmit({bool isResend = false}) =>
|
||||
@@ -8333,9 +8335,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
appLogger.warn('Received message with empty text, ignoring');
|
||||
return null;
|
||||
}
|
||||
final decodedText = isCli
|
||||
? msgText
|
||||
: (Smaz.tryDecodePrefixed(msgText) ?? msgText);
|
||||
final smazDecoded = isCli ? null : Smaz.tryDecodePrefixed(msgText);
|
||||
final decodedText = smazDecoded ?? msgText;
|
||||
|
||||
final contact = _contacts.cast<Contact?>().firstWhere(
|
||||
(c) => c != null && _matchesPrefix(c.publicKey, senderPrefix),
|
||||
@@ -8355,6 +8356,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
receivedAt: DateTime.now(),
|
||||
isOutgoing: false,
|
||||
isCli: isCli,
|
||||
isSmazCompressed: smazDecoded != null,
|
||||
status: MessageStatus.delivered,
|
||||
pathLength: pathLength == 0xFF ? null : (pathLength & 0x3F),
|
||||
pathBytes: Uint8List(0),
|
||||
@@ -8484,7 +8486,13 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
|
||||
/// Prepares contact outbound text by applying SMAZ encoding if enabled.
|
||||
/// This should be used to transform text before computing ACK hashes.
|
||||
String prepareContactOutboundText(Contact contact, String text) {
|
||||
String prepareContactOutboundText(Contact contact, String text) =>
|
||||
prepareContactOutbound(contact, text).text;
|
||||
|
||||
({String text, bool isSmazCompressed}) prepareContactOutbound(
|
||||
Contact contact,
|
||||
String text,
|
||||
) {
|
||||
final trimmed = text.trim();
|
||||
final isStructuredPayload =
|
||||
trimmed.startsWith('g:') ||
|
||||
@@ -8492,7 +8500,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
trimmed.startsWith('V1|');
|
||||
if (!isStructuredPayload) {
|
||||
if (isContactSmazEnabled(contact.publicKeyHex)) {
|
||||
return Smaz.encodeIfSmaller(text);
|
||||
final encoded = Smaz.encodeIfSmaller(text);
|
||||
return (text: encoded, isSmazCompressed: encoded != text);
|
||||
} else if (isContactCyr2LatEnabled(contact.publicKeyHex)) {
|
||||
final profileId = getContactCyr2LatProfileId(contact.publicKeyHex);
|
||||
final profile = profileId != null && _appSettingsService != null
|
||||
@@ -8508,19 +8517,26 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
Cyr2Lat.setCharMap(globalProfile.charMap);
|
||||
}
|
||||
}
|
||||
return Cyr2Lat.encode(text);
|
||||
return (text: Cyr2Lat.encode(text), isSmazCompressed: false);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
return (text: text, isSmazCompressed: false);
|
||||
}
|
||||
|
||||
String prepareChannelOutboundText(int channelIndex, String text) {
|
||||
String prepareChannelOutboundText(int channelIndex, String text) =>
|
||||
prepareChannelOutbound(channelIndex, text).text;
|
||||
|
||||
({String text, bool isSmazCompressed}) prepareChannelOutbound(
|
||||
int channelIndex,
|
||||
String text,
|
||||
) {
|
||||
final trimmed = text.trim();
|
||||
final isStructuredPayload =
|
||||
trimmed.startsWith('g:') || trimmed.startsWith('m:');
|
||||
if (!isStructuredPayload) {
|
||||
if (isChannelSmazEnabled(channelIndex)) {
|
||||
return Smaz.encodeIfSmaller(text);
|
||||
final encoded = Smaz.encodeIfSmaller(text);
|
||||
return (text: encoded, isSmazCompressed: encoded != text);
|
||||
} else if (isChannelCyr2LatEnabled(channelIndex)) {
|
||||
final profileId = getChannelCyr2LatProfileId(channelIndex);
|
||||
final profile = profileId != null && _appSettingsService != null
|
||||
@@ -8536,10 +8552,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
Cyr2Lat.setCharMap(globalProfile.charMap);
|
||||
}
|
||||
}
|
||||
return Cyr2Lat.encode(text);
|
||||
return (text: Cyr2Lat.encode(text), isSmazCompressed: false);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
return (text: text, isSmazCompressed: false);
|
||||
}
|
||||
|
||||
// Falls back to the cached channel list, which stays populated while a
|
||||
@@ -8727,8 +8743,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
|
||||
final text = decrypted.readCString();
|
||||
final parsed = _splitSenderText(text);
|
||||
final decodedText =
|
||||
Smaz.tryDecodePrefixed(parsed.text) ?? parsed.text;
|
||||
final smazDecoded = Smaz.tryDecodePrefixed(parsed.text);
|
||||
final decodedText = smazDecoded ?? parsed.text;
|
||||
if (_shouldDropSelfChannelMessage(
|
||||
parsed.senderName,
|
||||
packet.pathBytes,
|
||||
@@ -8758,6 +8774,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(timestampRaw * 1000),
|
||||
receivedAt: DateTime.now(),
|
||||
isOutgoing: false,
|
||||
isSmazCompressed: smazDecoded != null,
|
||||
status: ChannelMessageStatus.sent,
|
||||
pathLength: packet.isFlood ? packet.hopCount : 0,
|
||||
pathHashWidth: packet.pathHashWidth,
|
||||
@@ -9572,6 +9589,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
timestamp: message.timestamp,
|
||||
receivedAt: message.receivedAt,
|
||||
isOutgoing: message.isOutgoing,
|
||||
isSmazCompressed: message.isSmazCompressed,
|
||||
status: message.status,
|
||||
repeats: message.repeats,
|
||||
repeatCount: message.repeatCount,
|
||||
@@ -9620,6 +9638,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
existing.status == ChannelMessageStatus.pending;
|
||||
messages[existingIndex] = existing.copyWith(
|
||||
repeatCount: newRepeatCount,
|
||||
isSmazCompressed:
|
||||
existing.isSmazCompressed || processedMessage.isSmazCompressed,
|
||||
pathLength: mergedPathLength,
|
||||
pathHashWidth: existing.pathHashWidth ?? processedMessage.pathHashWidth,
|
||||
pathBytes: mergedPathBytes,
|
||||
|
||||
Reference in new issue
Block a user