update to zjs81/dev 98f6cf3745

This commit is contained in:
ericz committed 2026-08-04 17:43:52 +02:00
commit 1fc6a9bf68
128 files changed
+11006 -1179

No files matched your search

+36 -4
View File
@@ -110,6 +110,7 @@ class ChannelMessageStore {
'channelIndex': msg.channelIndex,
'repeatCount': msg.repeatCount,
'pathLength': msg.pathLength,
'pathHashWidth': msg.pathHashWidth,
'pathBytes': base64Encode(msg.pathBytes),
'pathVariants': msg.pathVariants.map(base64Encode).toList(),
'repeats': msg.repeats.map(_repeatToJson).toList(),
@@ -126,6 +127,38 @@ class ChannelMessageStore {
ChannelMessage _messageFromJson(Map<String, dynamic> json) {
final rawText = json['text'] as String;
final decodedText = Smaz.tryDecodePrefixed(rawText) ?? rawText;
final rawPathLength = json['pathLength'] as int?;
final rawPathBytes = json['pathBytes'] != null
? Uint8List.fromList(base64Decode(json['pathBytes'] as String))
: Uint8List(0);
final rawPathHashWidth = json['pathHashWidth'] as int?;
int? decodedPathLength = rawPathLength;
Uint8List decodedPathBytes = rawPathBytes;
int? decodedPathHashWidth = rawPathHashWidth;
if (rawPathLength != null) {
if (rawPathLength == 0xFF || rawPathLength < 0) {
decodedPathLength = -1;
decodedPathBytes = Uint8List(0);
} else if (rawPathLength >= 64) {
final mode = (rawPathLength & 0xC0) >> 6;
final hopCount = rawPathLength & 0x3F;
final width = mode + 1;
final byteLen = hopCount * width;
decodedPathLength = hopCount;
decodedPathHashWidth = width;
if (byteLen <= rawPathBytes.length) {
decodedPathBytes = rawPathBytes.sublist(0, byteLen);
} else {
decodedPathBytes = Uint8List(0);
}
} else if (rawPathLength == 0) {
decodedPathBytes = Uint8List(0);
}
}
return ChannelMessage(
senderKey: json['senderKey'] != null
? Uint8List.fromList(base64Decode(json['senderKey']))
@@ -143,10 +176,9 @@ class ChannelMessageStore {
isOutgoing: json['isOutgoing'] as bool,
status: ChannelMessageStatus.values[json['status'] as int],
repeatCount: (json['repeatCount'] as int?) ?? 0,
pathLength: json['pathLength'] as int?,
pathBytes: json['pathBytes'] != null
? Uint8List.fromList(base64Decode(json['pathBytes'] as String))
: Uint8List(0),
pathLength: decodedPathLength,
pathHashWidth: decodedPathHashWidth,
pathBytes: decodedPathBytes,
pathVariants: (json['pathVariants'] as List<dynamic>?)
?.map((entry) => Uint8List.fromList(base64Decode(entry as String)))
.toList(),
+39
View File
@@ -0,0 +1,39 @@
import '../utils/app_logger.dart';
import 'prefs_manager.dart';
class ChannelRegionStore {
static const String _keyPrefix = 'channel_region_';
String publicKeyHex = '';
set setPublicKeyHex(String value) =>
publicKeyHex = value.length >= 10 ? value.substring(0, 10) : '';
String get keyFor => '$_keyPrefix$publicKeyHex';
Future<String> loadRegion(int channelIndex) async {
if (publicKeyHex.isEmpty) {
appLogger.warn(
'Public key hex is not set. Cannot load channel settings.',
);
return '';
}
final prefs = PrefsManager.instance;
final key = '$keyFor$channelIndex';
String? region = prefs.getString(key);
return region ?? '';
}
Future<String> saveRegion(int channelIndex, String region) async {
if (publicKeyHex.isEmpty) {
appLogger.warn(
'Public key hex is not set. Cannot save channel settings.',
);
return '';
}
final prefs = PrefsManager.instance;
final key = '$keyFor$channelIndex';
await prefs.setString(key, region);
return region;
}
}
+29 -4
View File
@@ -105,15 +105,40 @@ class ContactDiscoveryStore {
final lastSeenMs = json['lastSeen'] as int? ?? 0;
final lastMessageMs = json['lastMessageAt'] as int?;
final lastModifiedMs = json['lastModified'] as int?;
final rawPathLength = json['pathLength'] as int? ?? -1;
final rawPath = json['path'] != null
? Uint8List.fromList(base64Decode(json['path'] as String))
: Uint8List(0);
int decodedPathLength = rawPathLength;
Uint8List decodedPath = rawPath;
if (rawPathLength == 0xFF || rawPathLength < 0) {
decodedPathLength = -1;
decodedPath = Uint8List(0);
} else if (rawPathLength >= 64) {
final mode = (rawPathLength & 0xC0) >> 6;
final hopCount = rawPathLength & 0x3F;
final width = mode + 1;
final byteLen = hopCount * width;
decodedPathLength = hopCount;
if (byteLen <= rawPath.length) {
decodedPath = rawPath.sublist(0, byteLen);
} else {
decodedPath = Uint8List(0);
}
} else if (rawPathLength == 0) {
decodedPath = Uint8List(0);
}
return Contact(
publicKey: Uint8List.fromList(base64Decode(json['publicKey'] as String)),
name: json['name'] as String? ?? 'Unknown',
type: json['type'] as int? ?? 0,
flags: json['flags'] as int? ?? 0,
pathLength: json['pathLength'] as int? ?? -1,
path: json['path'] != null
? Uint8List.fromList(base64Decode(json['path'] as String))
: Uint8List(0),
pathLength: decodedPathLength,
path: decodedPath,
pathOverride: json['pathOverride'] as int?,
pathOverrideBytes: json['pathOverrideBytes'] != null
? Uint8List.fromList(
+29 -4
View File
@@ -88,15 +88,40 @@ class ContactStore {
final lastSeenMs = json['lastSeen'] as int? ?? 0;
final lastMessageMs = json['lastMessageAt'] as int?;
final lastModifiedMs = json['lastModified'] as int?;
final rawPathLength = json['pathLength'] as int? ?? -1;
final rawPath = json['path'] != null
? Uint8List.fromList(base64Decode(json['path'] as String))
: Uint8List(0);
int decodedPathLength = rawPathLength;
Uint8List decodedPath = rawPath;
if (rawPathLength == 0xFF || rawPathLength < 0) {
decodedPathLength = -1;
decodedPath = Uint8List(0);
} else if (rawPathLength >= 64) {
final mode = (rawPathLength & 0xC0) >> 6;
final hopCount = rawPathLength & 0x3F;
final width = mode + 1;
final byteLen = hopCount * width;
decodedPathLength = hopCount;
if (byteLen <= rawPath.length) {
decodedPath = rawPath.sublist(0, byteLen);
} else {
decodedPath = Uint8List(0);
}
} else if (rawPathLength == 0) {
decodedPath = Uint8List(0);
}
return Contact(
publicKey: Uint8List.fromList(base64Decode(json['publicKey'] as String)),
name: json['name'] as String? ?? 'Unknown',
type: json['type'] as int? ?? 0,
flags: json['flags'] as int? ?? 0,
pathLength: json['pathLength'] as int? ?? -1,
path: json['path'] != null
? Uint8List.fromList(base64Decode(json['path'] as String))
: Uint8List(0),
pathLength: decodedPathLength,
path: decodedPath,
pathOverride: json['pathOverride'] as int?,
pathOverrideBytes: json['pathOverrideBytes'] != null
? Uint8List.fromList(
+31 -4
View File
@@ -113,6 +113,35 @@ class MessageStore {
final decodedText = isCli
? rawText
: (Smaz.tryDecodePrefixed(rawText) ?? rawText);
final rawPathLength = json['pathLength'] as int?;
final rawPathBytes = json['pathBytes'] != null
? Uint8List.fromList(base64Decode(json['pathBytes'] as String))
: Uint8List(0);
int? decodedPathLength = rawPathLength;
Uint8List decodedPathBytes = rawPathBytes;
if (rawPathLength != null) {
if (rawPathLength == 0xFF || rawPathLength < 0) {
decodedPathLength = -1;
decodedPathBytes = Uint8List(0);
} else if (rawPathLength >= 64) {
final mode = (rawPathLength & 0xC0) >> 6;
final hopCount = rawPathLength & 0x3F;
final width = mode + 1;
final byteLen = hopCount * width;
decodedPathLength = hopCount;
if (byteLen <= rawPathBytes.length) {
decodedPathBytes = rawPathBytes.sublist(0, byteLen);
} else {
decodedPathBytes = Uint8List(0);
}
} else if (rawPathLength == 0) {
decodedPathBytes = Uint8List(0);
}
}
return Message(
senderKey: Uint8List.fromList(base64Decode(json['senderKey'] as String)),
text: decodedText,
@@ -138,10 +167,8 @@ class MessageStore {
? DateTime.fromMillisecondsSinceEpoch(json['deliveredAt'] as int)
: null,
tripTimeMs: json['tripTimeMs'] as int?,
pathLength: json['pathLength'] as int?,
pathBytes: json['pathBytes'] != null
? Uint8List.fromList(base64Decode(json['pathBytes'] as String))
: Uint8List(0),
pathLength: decodedPathLength,
pathBytes: decodedPathBytes,
reactions:
(json['reactions'] as Map<String, dynamic>?)?.map(
(key, value) => MapEntry(key, value as int),
+53
View File
@@ -0,0 +1,53 @@
import 'package:meshcore_open/storage/channel_region_store.dart';
import 'package:meshcore_open/storage/channel_store.dart';
import 'prefs_manager.dart';
typedef Region = String;
class RegionStore {
static const String key = 'regions';
String publicKeyHex = '';
set setPublicKeyHex(String value) =>
publicKeyHex = value.length >= 10 ? value.substring(0, 10) : '';
List<Region> loadRegions() {
final prefs = PrefsManager.instance;
List<Region>? region = prefs.getStringList(key);
return region ?? [];
}
void saveRegions(List<Region> regions) {
final prefs = PrefsManager.instance;
var distinctRegions = [
...{...regions},
];
distinctRegions.sort();
prefs.setStringList(key, distinctRegions);
}
void addRegion(Region region) {
final regions = loadRegions();
regions.add(region);
saveRegions(regions);
}
Future<void> removeRegion(Region region) async {
final regions = loadRegions();
final channelStore = ChannelStore();
final channelRegionStore = ChannelRegionStore();
channelStore.setPublicKeyHex = publicKeyHex;
channelRegionStore.setPublicKeyHex = publicKeyHex;
for (var channel in await channelStore.loadChannels()) {
var channelRegion = await channelRegionStore.loadRegion(channel.index);
if (channelRegion == region) {
await channelRegionStore.saveRegion(channel.index, '');
}
}
regions.remove(region);
saveRegions(regions);
}
}