display Regions in received Messages and allow reply to same region.
This commit is contained in:
1 parent
d5f54dfa11
commit
20e01145e6
9 files changed
+177
-15
No files matched your search
@@ -3572,8 +3572,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
String? originalText,
|
String? originalText,
|
||||||
String? translatedLanguageCode,
|
String? translatedLanguageCode,
|
||||||
String? translationModelId,
|
String? translationModelId,
|
||||||
|
String? region,
|
||||||
}) async {
|
}) async {
|
||||||
if (!isConnected || text.isEmpty) return;
|
if (!isConnected || text.isEmpty) return;
|
||||||
|
final sendRegion = region ?? getChannelRegion(channel.index);
|
||||||
|
|
||||||
// Check if this is a reaction - if so, process it immediately instead of adding as a message
|
// Check if this is a reaction - if so, process it immediately instead of adding as a message
|
||||||
final reactionInfo = ReactionHelper.parseReaction(text);
|
final reactionInfo = ReactionHelper.parseReaction(text);
|
||||||
@@ -3631,6 +3633,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
originalText: originalText,
|
originalText: originalText,
|
||||||
translatedLanguageCode: translatedLanguageCode,
|
translatedLanguageCode: translatedLanguageCode,
|
||||||
translationModelId: translationModelId,
|
translationModelId: translationModelId,
|
||||||
|
region: sendRegion,
|
||||||
);
|
);
|
||||||
_addChannelMessage(channel.index, message);
|
_addChannelMessage(channel.index, message);
|
||||||
_pendingChannelSentQueue.add(message.messageId);
|
_pendingChannelSentQueue.add(message.messageId);
|
||||||
@@ -3645,7 +3648,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
expectsGenericAck: true,
|
expectsGenericAck: true,
|
||||||
successCode: respCodeSent,
|
successCode: respCodeSent,
|
||||||
);
|
);
|
||||||
}, region: getChannelRegion(channel.index));
|
}, region: sendRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Minimum companion firmware version code that implements
|
/// Minimum companion firmware version code that implements
|
||||||
@@ -5821,6 +5824,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
pathHashWidth: packet.pathHashWidth,
|
pathHashWidth: packet.pathHashWidth,
|
||||||
pathBytes: packet.pathBytes,
|
pathBytes: packet.pathBytes,
|
||||||
channelIndex: channel.index,
|
channelIndex: channel.index,
|
||||||
|
region: _resolveTransportRegion(packet),
|
||||||
packetHash: pktHash,
|
packetHash: pktHash,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -6423,10 +6427,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
final hasTransport =
|
final hasTransport =
|
||||||
routeType == _routeTransportFlood ||
|
routeType == _routeTransportFlood ||
|
||||||
routeType == _routeTransportDirect;
|
routeType == _routeTransportDirect;
|
||||||
if (hasTransport) {
|
final transportCodes = hasTransport ? reader.readBytes(4) : null;
|
||||||
// Skip reserved bytes in transport header made up of two u16 fields
|
|
||||||
reader.skipBytes(4);
|
|
||||||
}
|
|
||||||
final pathLenRaw = reader.readByte();
|
final pathLenRaw = reader.readByte();
|
||||||
final pathByteLen = _decodePathByteLen(pathLenRaw);
|
final pathByteLen = _decodePathByteLen(pathLenRaw);
|
||||||
final pathBytes = reader.readBytes(pathByteLen);
|
final pathBytes = reader.readBytes(pathByteLen);
|
||||||
@@ -6438,6 +6439,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
payloadType: (header >> _phTypeShift) & _phTypeMask,
|
payloadType: (header >> _phTypeShift) & _phTypeMask,
|
||||||
payloadVer: (header >> _phVerShift) & _phVerMask,
|
payloadVer: (header >> _phVerShift) & _phVerMask,
|
||||||
pathLenRaw: pathLenRaw,
|
pathLenRaw: pathLenRaw,
|
||||||
|
transportCodes: transportCodes,
|
||||||
pathBytes: pathBytes,
|
pathBytes: pathBytes,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
);
|
);
|
||||||
@@ -6452,6 +6454,30 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
return digest[0];
|
return digest[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? _resolveTransportRegion(_RawPacket packet) {
|
||||||
|
if (packet.routeType != _routeTransportFlood ||
|
||||||
|
packet.transportCodes == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final candidates = <String>{
|
||||||
|
...RegionStore().loadRegions(),
|
||||||
|
..._channelRegions.values,
|
||||||
|
}.where((region) => region.trim().isNotEmpty).toList()..sort();
|
||||||
|
String? match;
|
||||||
|
for (final region in candidates) {
|
||||||
|
final code = floodTransportCode(
|
||||||
|
scopeKey: floodScopeKeyForRegion(region),
|
||||||
|
payloadType: packet.payloadType,
|
||||||
|
payload: packet.payload,
|
||||||
|
);
|
||||||
|
if (!_pathsEqual(code, packet.transportCodes!.sublist(0, 2))) continue;
|
||||||
|
if (match != null) return null;
|
||||||
|
match = region;
|
||||||
|
}
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
/// Firmware-compatible packet hash: SHA256(payloadType + payload) -> first 8 bytes as hex.
|
/// Firmware-compatible packet hash: SHA256(payloadType + payload) -> first 8 bytes as hex.
|
||||||
String _computePacketHash(int payloadType, Uint8List payload) {
|
String _computePacketHash(int payloadType, Uint8List payload) {
|
||||||
final input = Uint8List(1 + payload.length);
|
final input = Uint8List(1 + payload.length);
|
||||||
@@ -6599,6 +6625,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
pathBytes: message.pathBytes,
|
pathBytes: message.pathBytes,
|
||||||
pathVariants: message.pathVariants,
|
pathVariants: message.pathVariants,
|
||||||
channelIndex: message.channelIndex,
|
channelIndex: message.channelIndex,
|
||||||
|
region: message.region,
|
||||||
messageId: message.messageId,
|
messageId: message.messageId,
|
||||||
replyToMessageId: originalMessage.messageId,
|
replyToMessageId: originalMessage.messageId,
|
||||||
replyToSenderName: originalMessage.senderName,
|
replyToSenderName: originalMessage.senderName,
|
||||||
@@ -6635,6 +6662,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
pathHashWidth: existing.pathHashWidth ?? processedMessage.pathHashWidth,
|
pathHashWidth: existing.pathHashWidth ?? processedMessage.pathHashWidth,
|
||||||
pathBytes: mergedPathBytes,
|
pathBytes: mergedPathBytes,
|
||||||
pathVariants: mergedPathVariants,
|
pathVariants: mergedPathVariants,
|
||||||
|
region: existing.region ?? processedMessage.region,
|
||||||
packetHash: existing.packetHash ?? processedMessage.packetHash,
|
packetHash: existing.packetHash ?? processedMessage.packetHash,
|
||||||
// Mark as sent when first repeat is heard
|
// Mark as sent when first repeat is heard
|
||||||
status: promotedFromPending
|
status: promotedFromPending
|
||||||
@@ -7586,6 +7614,7 @@ class _RawPacket {
|
|||||||
final int payloadType;
|
final int payloadType;
|
||||||
final int payloadVer;
|
final int payloadVer;
|
||||||
final int pathLenRaw;
|
final int pathLenRaw;
|
||||||
|
final Uint8List? transportCodes;
|
||||||
final Uint8List pathBytes;
|
final Uint8List pathBytes;
|
||||||
final Uint8List payload;
|
final Uint8List payload;
|
||||||
|
|
||||||
@@ -7595,6 +7624,7 @@ class _RawPacket {
|
|||||||
required this.payloadType,
|
required this.payloadType,
|
||||||
required this.payloadVer,
|
required this.payloadVer,
|
||||||
required this.pathLenRaw,
|
required this.pathLenRaw,
|
||||||
|
required this.transportCodes,
|
||||||
required this.pathBytes,
|
required this.pathBytes,
|
||||||
required this.payload,
|
required this.payload,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1040,9 +1040,29 @@ Uint8List buildSetFloodScopeFrame(String region) {
|
|||||||
return Uint8List.fromList([cmdSetFloodScope, 0]);
|
return Uint8List.fromList([cmdSetFloodScope, 0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
final name = region.startsWith('#') ? region : '#$region';
|
final scope = floodScopeKeyForRegion(region);
|
||||||
final hash = crypto.sha256.convert(utf8.encode(name)).bytes;
|
|
||||||
final scope = Uint8List.fromList(hash.sublist(0, 16));
|
|
||||||
|
|
||||||
return Uint8List.fromList([cmdSetFloodScope, 0, ...scope]);
|
return Uint8List.fromList([cmdSetFloodScope, 0, ...scope]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uint8List floodScopeKeyForRegion(String region) {
|
||||||
|
final name = region.startsWith('#') ? region : '#$region';
|
||||||
|
final hash = crypto.sha256.convert(utf8.encode(name)).bytes;
|
||||||
|
return Uint8List.fromList(hash.sublist(0, 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8List floodTransportCode({
|
||||||
|
required Uint8List scopeKey,
|
||||||
|
required int payloadType,
|
||||||
|
required Uint8List payload,
|
||||||
|
}) {
|
||||||
|
final input = Uint8List(1 + payload.length)
|
||||||
|
..[0] = payloadType
|
||||||
|
..setRange(1, 1 + payload.length, payload);
|
||||||
|
final code = crypto.Hmac(crypto.sha256, scopeKey).convert(input).bytes;
|
||||||
|
if (code[0] == 0 && code[1] == 0) return Uint8List.fromList([1, 0]);
|
||||||
|
if (code[0] == 0xFF && code[1] == 0xFF) {
|
||||||
|
return Uint8List.fromList([0xFE, 0xFF]);
|
||||||
|
}
|
||||||
|
return Uint8List.fromList(code.sublist(0, 2));
|
||||||
|
}
|
||||||
@@ -45,6 +45,7 @@ class ChannelMessage {
|
|||||||
final Uint8List pathBytes;
|
final Uint8List pathBytes;
|
||||||
final List<Uint8List> pathVariants;
|
final List<Uint8List> pathVariants;
|
||||||
final int? channelIndex;
|
final int? channelIndex;
|
||||||
|
final String? region;
|
||||||
final String messageId;
|
final String messageId;
|
||||||
final String? packetHash;
|
final String? packetHash;
|
||||||
final String? replyToMessageId;
|
final String? replyToMessageId;
|
||||||
@@ -71,6 +72,7 @@ class ChannelMessage {
|
|||||||
Uint8List? pathBytes,
|
Uint8List? pathBytes,
|
||||||
List<Uint8List>? pathVariants,
|
List<Uint8List>? pathVariants,
|
||||||
this.channelIndex,
|
this.channelIndex,
|
||||||
|
this.region,
|
||||||
String? messageId,
|
String? messageId,
|
||||||
this.packetHash,
|
this.packetHash,
|
||||||
this.replyToMessageId,
|
this.replyToMessageId,
|
||||||
@@ -98,6 +100,7 @@ class ChannelMessage {
|
|||||||
int? pathHashWidth,
|
int? pathHashWidth,
|
||||||
Uint8List? pathBytes,
|
Uint8List? pathBytes,
|
||||||
List<Uint8List>? pathVariants,
|
List<Uint8List>? pathVariants,
|
||||||
|
Object? region = _unset,
|
||||||
String? packetHash,
|
String? packetHash,
|
||||||
String? replyToMessageId,
|
String? replyToMessageId,
|
||||||
String? replyToSenderName,
|
String? replyToSenderName,
|
||||||
@@ -136,6 +139,7 @@ class ChannelMessage {
|
|||||||
pathBytes: pathBytes ?? this.pathBytes,
|
pathBytes: pathBytes ?? this.pathBytes,
|
||||||
pathVariants: pathVariants ?? this.pathVariants,
|
pathVariants: pathVariants ?? this.pathVariants,
|
||||||
channelIndex: channelIndex,
|
channelIndex: channelIndex,
|
||||||
|
region: region == _unset ? this.region : region as String?,
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
packetHash: packetHash ?? this.packetHash,
|
packetHash: packetHash ?? this.packetHash,
|
||||||
replyToMessageId: replyToMessageId ?? this.replyToMessageId,
|
replyToMessageId: replyToMessageId ?? this.replyToMessageId,
|
||||||
@@ -238,6 +242,7 @@ class ChannelMessage {
|
|||||||
String? originalText,
|
String? originalText,
|
||||||
String? translatedLanguageCode,
|
String? translatedLanguageCode,
|
||||||
String? translationModelId,
|
String? translationModelId,
|
||||||
|
String? region,
|
||||||
}) {
|
}) {
|
||||||
return ChannelMessage(
|
return ChannelMessage(
|
||||||
senderKey: null,
|
senderKey: null,
|
||||||
@@ -253,6 +258,7 @@ class ChannelMessage {
|
|||||||
pathBytes: Uint8List(0),
|
pathBytes: Uint8List(0),
|
||||||
pathVariants: const [],
|
pathVariants: const [],
|
||||||
channelIndex: channelIndex,
|
channelIndex: channelIndex,
|
||||||
|
region: region,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
final ChatScrollController _scrollController = ChatScrollController();
|
final ChatScrollController _scrollController = ChatScrollController();
|
||||||
final FocusNode _textFieldFocusNode = FocusNode();
|
final FocusNode _textFieldFocusNode = FocusNode();
|
||||||
ChannelMessage? _replyingToMessage;
|
ChannelMessage? _replyingToMessage;
|
||||||
|
bool _useReplyRegion = false;
|
||||||
final CommunityStore _communityStore = CommunityStore();
|
final CommunityStore _communityStore = CommunityStore();
|
||||||
final CommunityPskIndex _communityIndex = CommunityPskIndex();
|
final CommunityPskIndex _communityIndex = CommunityPskIndex();
|
||||||
final Map<String, GlobalKey> _messageKeys = {};
|
final Map<String, GlobalKey> _messageKeys = {};
|
||||||
@@ -210,12 +211,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
void _setReplyingTo(ChannelMessage message) {
|
void _setReplyingTo(ChannelMessage message) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_replyingToMessage = message;
|
_replyingToMessage = message;
|
||||||
|
_useReplyRegion = message.region?.isNotEmpty ?? false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _cancelReply() {
|
void _cancelReply() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_replyingToMessage = null;
|
_replyingToMessage = null;
|
||||||
|
_useReplyRegion = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -809,9 +812,41 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
RouteChip(
|
Column(
|
||||||
isDirect: (message.pathLength ?? -1) >= 0,
|
mainAxisSize: MainAxisSize.min,
|
||||||
hops: displayHopCount,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
RouteChip(
|
||||||
|
isDirect: (message.pathLength ?? -1) >= 0,
|
||||||
|
hops: displayHopCount,
|
||||||
|
),
|
||||||
|
if (message.region?.isNotEmpty ?? false)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 2),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 6,
|
||||||
|
vertical: 2,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: scheme.surfaceContainerHigh,
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
MeshRadii.xs,
|
||||||
|
),
|
||||||
|
border: Border.all(
|
||||||
|
color: scheme.outlineVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
_displayRegion(message.region!),
|
||||||
|
style: MeshTheme.mono(
|
||||||
|
fontSize: 8.5 * textScale,
|
||||||
|
color: metaColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Flexible(
|
Flexible(
|
||||||
@@ -1670,6 +1705,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
Widget _buildReplyBanner(double textScale) {
|
Widget _buildReplyBanner(double textScale) {
|
||||||
final message = _replyingToMessage!;
|
final message = _replyingToMessage!;
|
||||||
final scheme = Theme.of(context).colorScheme;
|
final scheme = Theme.of(context).colorScheme;
|
||||||
|
final replyRegion = message.region;
|
||||||
return Container(
|
return Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
@@ -1707,6 +1743,40 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (replyRegion?.isNotEmpty ?? false)
|
||||||
|
InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(MeshRadii.xs),
|
||||||
|
onTap: () => setState(() => _useReplyRegion = !_useReplyRegion),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: _useReplyRegion
|
||||||
|
? scheme.primaryContainer
|
||||||
|
: scheme.surfaceContainerHighest,
|
||||||
|
borderRadius: BorderRadius.circular(MeshRadii.xs),
|
||||||
|
border: Border.all(
|
||||||
|
color: _useReplyRegion
|
||||||
|
? scheme.primary
|
||||||
|
: scheme.outlineVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
context.l10n.channels_regionSetTo(replyRegion!),
|
||||||
|
style:
|
||||||
|
MeshTheme.mono(
|
||||||
|
fontSize: 10 * textScale,
|
||||||
|
color: _useReplyRegion
|
||||||
|
? scheme.onPrimaryContainer
|
||||||
|
: scheme.onSurfaceVariant,
|
||||||
|
).copyWith(
|
||||||
|
decoration: _useReplyRegion
|
||||||
|
? null
|
||||||
|
: TextDecoration.lineThrough,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.close, size: 18),
|
icon: const Icon(Icons.close, size: 18),
|
||||||
onPressed: _cancelReply,
|
onPressed: _cancelReply,
|
||||||
@@ -2032,6 +2102,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
if (_replyingToMessage != null) {
|
if (_replyingToMessage != null) {
|
||||||
messageText = '@[${_replyingToMessage!.senderName}] $messageText';
|
messageText = '@[${_replyingToMessage!.senderName}] $messageText';
|
||||||
}
|
}
|
||||||
|
final replyRegion = _useReplyRegion ? _replyingToMessage?.region : null;
|
||||||
|
|
||||||
final maxBytes = maxChannelMessageBytes(connector.selfName);
|
final maxBytes = maxChannelMessageBytes(connector.selfName);
|
||||||
final outboundText = connector.prepareChannelOutboundText(
|
final outboundText = connector.prepareChannelOutboundText(
|
||||||
@@ -2064,6 +2135,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
originalText: originalText,
|
originalText: originalText,
|
||||||
translatedLanguageCode: translatedLanguageCode,
|
translatedLanguageCode: translatedLanguageCode,
|
||||||
translationModelId: translationModelId,
|
translationModelId: translationModelId,
|
||||||
|
region: replyRegion,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2282,6 +2354,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
return PathHelper.splitPathBytes(pathBytes, pathHashByteWidth).length;
|
return PathHelper.splitPathBytes(pathBytes, pathHashByteWidth).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _displayRegion(String region) {
|
||||||
|
return region.startsWith('#') ? region.substring(1) : region;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> openRegionSelectDialog(Channel channel) async {
|
Future<void> openRegionSelectDialog(Channel channel) async {
|
||||||
// The AppBar subtitle reads the region from the connector inside a
|
// The AppBar subtitle reads the region from the connector inside a
|
||||||
// Consumer, so setChannelRegion's notifyListeners refreshes it directly —
|
// Consumer, so setChannelRegion's notifyListeners refreshes it directly —
|
||||||
|
|||||||
@@ -211,6 +211,13 @@ class ChannelMessagePathScreen extends StatelessWidget {
|
|||||||
observedLabel,
|
observedLabel,
|
||||||
scheme: scheme,
|
scheme: scheme,
|
||||||
),
|
),
|
||||||
|
if (message.region?.isNotEmpty ?? false)
|
||||||
|
_buildDetailRow(
|
||||||
|
context,
|
||||||
|
l10n.settings_regionName,
|
||||||
|
message.region!,
|
||||||
|
scheme: scheme,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import '../connector/meshcore_protocol.dart';
|
|||||||
/// do the same so the repeater always gets the phone's time.
|
/// do the same so the repeater always gets the phone's time.
|
||||||
String normalizeRepeaterClockSyncCommand(String command, {int? nowSeconds}) {
|
String normalizeRepeaterClockSyncCommand(String command, {int? nowSeconds}) {
|
||||||
final epoch = nowSeconds ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
final epoch = nowSeconds ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||||
return command.trim().toLowerCase() == 'clock sync'
|
return command.trim().toLowerCase() == 'clock sync' ? 'time $epoch' : command;
|
||||||
? 'time $epoch'
|
|
||||||
: command;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class RepeaterCommandService {
|
class RepeaterCommandService {
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ class ChannelMessageStore {
|
|||||||
'isOutgoing': msg.isOutgoing,
|
'isOutgoing': msg.isOutgoing,
|
||||||
'status': msg.status.index,
|
'status': msg.status.index,
|
||||||
'channelIndex': msg.channelIndex,
|
'channelIndex': msg.channelIndex,
|
||||||
|
'region': msg.region,
|
||||||
'repeatCount': msg.repeatCount,
|
'repeatCount': msg.repeatCount,
|
||||||
'pathLength': msg.pathLength,
|
'pathLength': msg.pathLength,
|
||||||
'pathHashWidth': msg.pathHashWidth,
|
'pathHashWidth': msg.pathHashWidth,
|
||||||
@@ -188,6 +189,7 @@ class ChannelMessageStore {
|
|||||||
.toList() ??
|
.toList() ??
|
||||||
const [],
|
const [],
|
||||||
channelIndex: json['channelIndex'] as int?,
|
channelIndex: json['channelIndex'] as int?,
|
||||||
|
region: json['region'] as String?,
|
||||||
messageId: json['messageId'] as String?,
|
messageId: json['messageId'] as String?,
|
||||||
packetHash: json['packetHash'] as String?,
|
packetHash: json['packetHash'] as String?,
|
||||||
replyToMessageId: json['replyToMessageId'] as String?,
|
replyToMessageId: json['replyToMessageId'] as String?,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:crypto/crypto.dart' as crypto;
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||||
import 'package:meshcore_open/models/channel_message.dart';
|
import 'package:meshcore_open/models/channel_message.dart';
|
||||||
@@ -148,6 +149,25 @@ void main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('flood transport code uses the scope key HMAC', () {
|
||||||
|
final scopeKey = floodScopeKeyForRegion('Europe');
|
||||||
|
final payload = Uint8List.fromList([0xA1, 0xB2, 0xC3]);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
floodTransportCode(
|
||||||
|
scopeKey: scopeKey,
|
||||||
|
payloadType: 0x05,
|
||||||
|
payload: payload,
|
||||||
|
),
|
||||||
|
orderedEquals(
|
||||||
|
crypto.Hmac(
|
||||||
|
crypto.sha256,
|
||||||
|
scopeKey,
|
||||||
|
).convert([0x05, ...payload]).bytes.sublist(0, 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
group('Contact.fromFrame — pathLen mapping', () {
|
group('Contact.fromFrame — pathLen mapping', () {
|
||||||
test('pathLen == 0 → pathLength == 0 (direct, NOT flood)', () {
|
test('pathLen == 0 → pathLength == 0 (direct, NOT flood)', () {
|
||||||
final frame = _buildContactFrame(pathLen: 0);
|
final frame = _buildContactFrame(pathLen: 0);
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('passes other commands through unchanged', () {
|
test('passes other commands through unchanged', () {
|
||||||
expect(normalizeRepeaterClockSyncCommand('clock', nowSeconds: 1), 'clock');
|
expect(
|
||||||
|
normalizeRepeaterClockSyncCommand('clock', nowSeconds: 1),
|
||||||
|
'clock',
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
normalizeRepeaterClockSyncCommand('get radio', nowSeconds: 1),
|
normalizeRepeaterClockSyncCommand('get radio', nowSeconds: 1),
|
||||||
'get radio',
|
'get radio',
|
||||||
|
|||||||
Reference in new issue
Block a user