Refactor LoRa airtime tests and add new functionality
- Updated LoRa airtime calculations in `lora_airtime_test.dart` to reflect new reference values. - Introduced new tests for LDRO behavior and preamble symbol calculations. - Added `contact_path_width_test.dart` to validate path hash width handling in contacts. - Enhanced `model_changes_test.dart` to ensure legacy data migration works correctly. - Created `remote_node_stats_test.dart` to decode and validate remote node statistics. - Implemented `map_marker_parse_test.dart` for parsing marker text with coordinate validation. - Developed `map_tile_cache_key_test.dart` to ensure API keys are excluded from cache keys. - Added `message_retry_failure_test.dart` to test message retry service behavior on failures. - Extended `path_history_service_test.dart` to preserve learned state across path attempts. - Enhanced `received_image_store_test.dart` to handle concurrent writes and review fixes. - Implemented `repeater_command_service_test.dart` to validate command response handling. - Created `store_tolerant_parsing_test.dart` to ensure stores skip malformed records gracefully. - Cleared untranslated JSON file for localization updates.
This commit is contained in:
1 parent
d5f54dfa11
commit
d74587c167
105 files changed
+6419
-2072
No files matched your search
@@ -68,13 +68,24 @@ class ChannelMessageStore {
|
||||
if (jsonString == null || jsonString.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
final List<dynamic> jsonList;
|
||||
try {
|
||||
final jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
return jsonList.map((json) => _messageFromJson(json)).toList();
|
||||
jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
} catch (e) {
|
||||
// If parsing fails, return empty list
|
||||
appLogger.warn(
|
||||
'Stored messages for channel $channelIndex are unreadable: $e',
|
||||
);
|
||||
return [];
|
||||
}
|
||||
final messages = <ChannelMessage>[];
|
||||
for (final json in jsonList) {
|
||||
try {
|
||||
messages.add(_messageFromJson(json as Map<String, dynamic>));
|
||||
} catch (e) {
|
||||
appLogger.warn('Skipping malformed stored channel message: $e');
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
/// Clear messages for a specific channel
|
||||
@@ -163,7 +174,7 @@ class ChannelMessageStore {
|
||||
senderKey: json['senderKey'] != null
|
||||
? Uint8List.fromList(base64Decode(json['senderKey']))
|
||||
: null,
|
||||
senderName: json['senderName'] as String,
|
||||
senderName: json['senderName'] as String? ?? 'Unknown',
|
||||
text: decodedText,
|
||||
originalText: json['originalText'] as String?,
|
||||
translatedText: json['translatedText'] as String?,
|
||||
@@ -173,8 +184,12 @@ class ChannelMessageStore {
|
||||
),
|
||||
translationModelId: json['translationModelId'] as String?,
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp'] as int),
|
||||
isOutgoing: json['isOutgoing'] as bool,
|
||||
status: ChannelMessageStatus.values[json['status'] as int],
|
||||
isOutgoing: json['isOutgoing'] as bool? ?? false,
|
||||
status:
|
||||
ChannelMessageStatus.values.elementAtOrNull(
|
||||
json['status'] as int? ?? -1,
|
||||
) ??
|
||||
ChannelMessageStatus.failed,
|
||||
repeatCount: (json['repeatCount'] as int?) ?? 0,
|
||||
pathLength: decodedPathLength,
|
||||
pathHashWidth: decodedPathHashWidth,
|
||||
|
||||
@@ -45,15 +45,22 @@ class CommunityStore {
|
||||
return [];
|
||||
}
|
||||
|
||||
final List<dynamic> jsonList;
|
||||
try {
|
||||
final jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
return jsonList
|
||||
.map((json) => Community.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
} catch (e) {
|
||||
// If JSON is corrupted, return empty list
|
||||
appLogger.warn('Stored communities are unreadable: $e');
|
||||
return [];
|
||||
}
|
||||
final communities = <Community>[];
|
||||
for (final json in jsonList) {
|
||||
try {
|
||||
communities.add(Community.fromJson(json as Map<String, dynamic>));
|
||||
} catch (e) {
|
||||
appLogger.warn('Skipping malformed stored community: $e');
|
||||
}
|
||||
}
|
||||
return communities;
|
||||
}
|
||||
|
||||
/// Save all communities to storage
|
||||
|
||||
@@ -2,30 +2,54 @@ import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../models/contact.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import 'prefs_manager.dart';
|
||||
|
||||
class ContactDiscoveryStore {
|
||||
static const String _keyPrefix = 'discovered_contacts';
|
||||
|
||||
String publicKeyHex = '';
|
||||
set setPublicKeyHex(String value) =>
|
||||
publicKeyHex = value.length > 10 ? value.substring(0, 10) : '';
|
||||
|
||||
String get keyFor => '$_keyPrefix$publicKeyHex';
|
||||
|
||||
Future<List<Contact>> loadContacts() async {
|
||||
if (publicKeyHex.isEmpty) return [];
|
||||
final prefs = PrefsManager.instance;
|
||||
final jsonStr = prefs.getString(_keyPrefix);
|
||||
var jsonStr = prefs.getString(keyFor);
|
||||
if (jsonStr == null) {
|
||||
jsonStr = prefs.getString(_keyPrefix);
|
||||
if (jsonStr != null) {
|
||||
await prefs.setString(keyFor, jsonStr);
|
||||
await prefs.remove(_keyPrefix);
|
||||
}
|
||||
}
|
||||
if (jsonStr == null) return [];
|
||||
|
||||
final List<dynamic> jsonList;
|
||||
try {
|
||||
final jsonList = jsonDecode(jsonStr) as List<dynamic>;
|
||||
return jsonList
|
||||
.map((entry) => _fromJson(entry as Map<String, dynamic>))
|
||||
.toList();
|
||||
} catch (_) {
|
||||
jsonList = jsonDecode(jsonStr) as List<dynamic>;
|
||||
} catch (e) {
|
||||
appLogger.warn('Stored discovered contacts are unreadable: $e');
|
||||
return [];
|
||||
}
|
||||
final contacts = <Contact>[];
|
||||
for (final entry in jsonList) {
|
||||
try {
|
||||
contacts.add(_fromJson(entry as Map<String, dynamic>));
|
||||
} catch (e) {
|
||||
appLogger.warn('Skipping malformed discovered contact: $e');
|
||||
}
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
Future<void> saveContacts(List<Contact> contacts) async {
|
||||
if (publicKeyHex.isEmpty) return;
|
||||
final prefs = PrefsManager.instance;
|
||||
final jsonList = contacts.map(_toJson).toList();
|
||||
await prefs.setString(_keyPrefix, jsonEncode(jsonList));
|
||||
await prefs.setString(keyFor, jsonEncode(jsonList));
|
||||
}
|
||||
|
||||
Map<String, dynamic> _toJson(Contact contact) {
|
||||
@@ -36,6 +60,7 @@ class ContactDiscoveryStore {
|
||||
'flags': contact.flags,
|
||||
'pathLength': contact.pathLength,
|
||||
'path': base64Encode(contact.path),
|
||||
'pathHashWidth': contact.pathHashWidth,
|
||||
'pathOverride': contact.pathOverride,
|
||||
'pathOverrideBytes': contact.pathOverrideBytes != null
|
||||
? base64Encode(contact.pathOverrideBytes!)
|
||||
@@ -63,6 +88,7 @@ class ContactDiscoveryStore {
|
||||
|
||||
int decodedPathLength = rawPathLength;
|
||||
Uint8List decodedPath = rawPath;
|
||||
int? decodedPathHashWidth = json['pathHashWidth'] as int?;
|
||||
|
||||
if (rawPathLength == 0xFF || rawPathLength < 0) {
|
||||
decodedPathLength = -1;
|
||||
@@ -73,6 +99,7 @@ class ContactDiscoveryStore {
|
||||
final width = mode + 1;
|
||||
final byteLen = hopCount * width;
|
||||
decodedPathLength = hopCount;
|
||||
decodedPathHashWidth = width;
|
||||
if (byteLen <= rawPath.length) {
|
||||
decodedPath = rawPath.sublist(0, byteLen);
|
||||
} else {
|
||||
@@ -89,6 +116,9 @@ class ContactDiscoveryStore {
|
||||
flags: json['flags'] as int? ?? 0,
|
||||
pathLength: decodedPathLength,
|
||||
path: decodedPath,
|
||||
pathHashWidth:
|
||||
decodedPathHashWidth ??
|
||||
Contact.inferPathHashWidth(decodedPathLength, decodedPath.length),
|
||||
pathOverride: json['pathOverride'] as int?,
|
||||
pathOverrideBytes: json['pathOverrideBytes'] != null
|
||||
? Uint8List.fromList(
|
||||
|
||||
@@ -40,14 +40,22 @@ class ContactStore {
|
||||
return [];
|
||||
}
|
||||
|
||||
final List<dynamic> jsonList;
|
||||
try {
|
||||
final jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
return jsonList
|
||||
.map((entry) => _fromJson(entry as Map<String, dynamic>))
|
||||
.toList();
|
||||
} catch (_) {
|
||||
jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
} catch (e) {
|
||||
appLogger.warn('Stored contacts are unreadable: $e');
|
||||
return [];
|
||||
}
|
||||
final contacts = <Contact>[];
|
||||
for (final entry in jsonList) {
|
||||
try {
|
||||
contacts.add(_fromJson(entry as Map<String, dynamic>));
|
||||
} catch (e) {
|
||||
appLogger.warn('Skipping malformed stored contact: $e');
|
||||
}
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
Future<void> saveContacts(List<Contact> contacts) async {
|
||||
@@ -68,6 +76,7 @@ class ContactStore {
|
||||
'flags': contact.flags,
|
||||
'pathLength': contact.pathLength,
|
||||
'path': base64Encode(contact.path),
|
||||
'pathHashWidth': contact.pathHashWidth,
|
||||
'pathOverride': contact.pathOverride,
|
||||
'pathOverrideBytes': contact.pathOverrideBytes != null
|
||||
? base64Encode(contact.pathOverrideBytes!)
|
||||
@@ -96,6 +105,7 @@ class ContactStore {
|
||||
|
||||
int decodedPathLength = rawPathLength;
|
||||
Uint8List decodedPath = rawPath;
|
||||
int? decodedPathHashWidth = json['pathHashWidth'] as int?;
|
||||
|
||||
if (rawPathLength == 0xFF || rawPathLength < 0) {
|
||||
decodedPathLength = -1;
|
||||
@@ -106,6 +116,7 @@ class ContactStore {
|
||||
final width = mode + 1;
|
||||
final byteLen = hopCount * width;
|
||||
decodedPathLength = hopCount;
|
||||
decodedPathHashWidth = width;
|
||||
if (byteLen <= rawPath.length) {
|
||||
decodedPath = rawPath.sublist(0, byteLen);
|
||||
} else {
|
||||
@@ -122,6 +133,9 @@ class ContactStore {
|
||||
flags: json['flags'] as int? ?? 0,
|
||||
pathLength: decodedPathLength,
|
||||
path: decodedPath,
|
||||
pathHashWidth:
|
||||
decodedPathHashWidth ??
|
||||
Contact.inferPathHashWidth(decodedPathLength, decodedPath.length),
|
||||
pathOverride: json['pathOverride'] as int?,
|
||||
pathOverrideBytes: json['pathOverrideBytes'] != null
|
||||
? Uint8List.fromList(
|
||||
|
||||
@@ -57,12 +57,22 @@ class MessageStore {
|
||||
return [];
|
||||
}
|
||||
|
||||
final List<dynamic> jsonList;
|
||||
try {
|
||||
final jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
return jsonList.map((json) => _messageFromJson(json)).toList();
|
||||
jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
} catch (e) {
|
||||
appLogger.warn('Stored messages for $contactKeyHex are unreadable: $e');
|
||||
return [];
|
||||
}
|
||||
final messages = <Message>[];
|
||||
for (final json in jsonList) {
|
||||
try {
|
||||
messages.add(_messageFromJson(json as Map<String, dynamic>));
|
||||
} catch (e) {
|
||||
appLogger.warn('Skipping malformed stored message: $e');
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
Future<void> clearMessages(String contactKeyHex) async {
|
||||
@@ -146,9 +156,11 @@ class MessageStore {
|
||||
senderKey: Uint8List.fromList(base64Decode(json['senderKey'] as String)),
|
||||
text: decodedText,
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp'] as int),
|
||||
isOutgoing: json['isOutgoing'] as bool,
|
||||
isOutgoing: json['isOutgoing'] as bool? ?? false,
|
||||
isCli: isCli,
|
||||
status: MessageStatus.values[json['status'] as int],
|
||||
status:
|
||||
MessageStatus.values.elementAtOrNull(json['status'] as int? ?? -1) ??
|
||||
MessageStatus.failed,
|
||||
messageId: json['messageId'] as String?,
|
||||
originalText: json['originalText'] as String?,
|
||||
translatedText: json['translatedText'] as String?,
|
||||
|
||||
Reference in new issue
Block a user