Merge upstream/dev (10 commits) [upstream-sync]
This commit is contained in:
commit
5a53e45e9a
68 files changed
+6375
-178
No files matched your search
@@ -49,6 +49,7 @@ const List<String> _scopedPreferencePrefixes = [
|
||||
..._contactPreferencePrefixes,
|
||||
..._channelPreferencePrefixes,
|
||||
'discovered_contacts',
|
||||
'message_bookmarks_',
|
||||
];
|
||||
|
||||
enum BackupSection {
|
||||
@@ -75,6 +76,7 @@ enum BackupItem {
|
||||
contactGroups,
|
||||
contactHistory,
|
||||
discoveredContacts,
|
||||
bookmarks,
|
||||
channels,
|
||||
channelFilters,
|
||||
ipfsKey,
|
||||
@@ -485,6 +487,12 @@ class BackupService {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (selectedItems.contains(BackupItem.appSettings)) {
|
||||
await appSettingsService.loadSettings();
|
||||
}
|
||||
if (selectedItems.contains(BackupItem.channelSettings)) {
|
||||
await connector.reloadChannelOrder();
|
||||
}
|
||||
if (!importingIdentity &&
|
||||
selectedItems.contains(BackupItem.discoveredContacts)) {
|
||||
await connector.reloadDiscoveredContacts();
|
||||
@@ -1055,7 +1063,8 @@ class BackupService {
|
||||
BackupItem.perContactSettings ||
|
||||
BackupItem.contactGroups ||
|
||||
BackupItem.contactHistory => BackupSection.contacts,
|
||||
BackupItem.discoveredContacts => BackupSection.discoveredContacts,
|
||||
BackupItem.discoveredContacts ||
|
||||
BackupItem.bookmarks => BackupSection.discoveredContacts,
|
||||
BackupItem.channels ||
|
||||
BackupItem.channelFilters ||
|
||||
BackupItem.channelSettings ||
|
||||
@@ -1108,6 +1117,10 @@ class BackupService {
|
||||
key.startsWith('discovered_contacts$devicePrefix')) {
|
||||
return true;
|
||||
}
|
||||
if (items.contains(BackupItem.bookmarks) &&
|
||||
key.startsWith('message_bookmarks_$devicePrefix')) {
|
||||
return true;
|
||||
}
|
||||
if (items.contains(BackupItem.channels) &&
|
||||
(key.startsWith('channels$devicePrefix') ||
|
||||
key.startsWith('channel_slot_ids_$devicePrefix'))) {
|
||||
@@ -1156,6 +1169,7 @@ class BackupService {
|
||||
case BackupSection.discoveredContacts:
|
||||
return _startsWithScopedPrefix(key, const [
|
||||
'discovered_contacts',
|
||||
'message_bookmarks_',
|
||||
], devicePrefix);
|
||||
case BackupSection.channels:
|
||||
return key.startsWith('message_filter_') ||
|
||||
@@ -1348,7 +1362,10 @@ class BackupService {
|
||||
if (sourcePrefix.isEmpty || destinationPrefix.isEmpty) return key;
|
||||
final prefixes = switch (section) {
|
||||
BackupSection.contacts => _contactPreferencePrefixes,
|
||||
BackupSection.discoveredContacts => const ['discovered_contacts'],
|
||||
BackupSection.discoveredContacts => const [
|
||||
'discovered_contacts',
|
||||
'message_bookmarks_',
|
||||
],
|
||||
BackupSection.channels => _channelPreferencePrefixes,
|
||||
_ => const <String>[],
|
||||
};
|
||||
@@ -1373,7 +1390,10 @@ class BackupService {
|
||||
if (devicePrefix.isEmpty) return false;
|
||||
final prefixes = switch (section) {
|
||||
BackupSection.contacts => _contactPreferencePrefixes,
|
||||
BackupSection.discoveredContacts => const ['discovered_contacts'],
|
||||
BackupSection.discoveredContacts => const [
|
||||
'discovered_contacts',
|
||||
'message_bookmarks_',
|
||||
],
|
||||
BackupSection.channels => _channelPreferencePrefixes,
|
||||
_ => const <String>[],
|
||||
};
|
||||
|
||||
@@ -970,15 +970,17 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
|
||||
/// [ImageSendCodec] entry point used by `ImageSendPreviewSheet`.
|
||||
///
|
||||
/// Takes the raw picked file (JPEG/PNG/HEIC/…), centre-crops and scales it to
|
||||
/// [kImageCodecSquareSize] square, then encodes. Throws on failure so the
|
||||
/// Takes the raw picked file (JPEG/PNG/HEIC/…), stretches the part of it
|
||||
/// that [variant] selects (see [rerollSourceRect]; 0 is the whole photo) to
|
||||
/// a [kImageCodecSquareSize] square, then encodes. Throws on failure so the
|
||||
/// sheet can surface it — unlike the nullable service-level methods below,
|
||||
/// whose contract is "null means not available".
|
||||
@override
|
||||
Future<Uint8List> encode(
|
||||
Uint8List imageBytes,
|
||||
ImageCodecRatePoint rate,
|
||||
) async {
|
||||
ImageCodecRatePoint rate, {
|
||||
int variant = 0,
|
||||
}) async {
|
||||
if (!kImageCodecBitstreamPathAvailable) {
|
||||
// Fail here rather than after a 512x512 raster and a session load, and
|
||||
// fail with the specific exception so the sheet can say why.
|
||||
@@ -990,7 +992,7 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
throw const ImageCodecBundleIncomplete();
|
||||
}
|
||||
final result = await encodeImage(
|
||||
rgbBytes: await _toSquareRgb(imageBytes),
|
||||
rgbBytes: await _toSquareRgb(imageBytes, variant: variant),
|
||||
ratePoint: aeicRatePointForUi(rate),
|
||||
);
|
||||
final bitstream = result?.bitstream;
|
||||
@@ -1300,14 +1302,18 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
|
||||
static const int _bytesPerPixel = 3;
|
||||
|
||||
/// Centre-crops [imageBytes] to a square and scales it to
|
||||
/// [kImageCodecSquareSize], returning packed 8-bit RGB.
|
||||
/// Stretches the [variant] region of [imageBytes] (see [rerollSourceRect];
|
||||
/// 0 is the whole frame) to a [kImageCodecSquareSize] square, returning
|
||||
/// packed 8-bit RGB.
|
||||
///
|
||||
/// Uses `dart:ui` rather than a decode package so this adds no dependency.
|
||||
/// It runs on the root isolate, which is acceptable: it is a single 512x512
|
||||
/// raster, three orders of magnitude cheaper than the 1385 GFLOP inference
|
||||
/// that follows in the worker.
|
||||
Future<Uint8List> _toSquareRgb(Uint8List imageBytes) async {
|
||||
Future<Uint8List> _toSquareRgb(
|
||||
Uint8List imageBytes, {
|
||||
int variant = 0,
|
||||
}) async {
|
||||
final codec = await ui.instantiateImageCodec(imageBytes);
|
||||
final frame = await codec.getNextFrame();
|
||||
final source = frame.image;
|
||||
@@ -1317,16 +1323,11 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
|
||||
// Aspect ratio is deliberately not preserved: the codec's graph is
|
||||
// statically 512x512, so something has to give, and losing 25% of a 4:3
|
||||
// photo (44% of 16:9, or the subject's head in a portrait) is worse than
|
||||
// distorting it. Nothing outside the frame is discarded this way.
|
||||
// NOTE: the aspect ratio is NOT transmitted, so the receiver cannot undo
|
||||
// the stretch — see the note in image_chunk_transport.dart on the
|
||||
// metadata byte.
|
||||
final src = ui.Rect.fromLTWH(
|
||||
0,
|
||||
0,
|
||||
source.width.toDouble(),
|
||||
source.height.toDouble(),
|
||||
);
|
||||
// distorting it. The source shape travels in the metadata byte's aspect
|
||||
// nibble, so the receiver un-stretches it. Re-roll variants trim at most
|
||||
// ~2% at an edge, so they keep the same shape and aspect code.
|
||||
final r = rerollSourceRect(source.width, source.height, variant);
|
||||
final src = ui.Rect.fromLTWH(r.left, r.top, r.width, r.height);
|
||||
final dstSize = kImageCodecSquareSize.toDouble();
|
||||
final recorder = ui.PictureRecorder();
|
||||
ui.Canvas(recorder).drawImageRect(
|
||||
|
||||
@@ -197,13 +197,30 @@ class ReceivedImageEntry {
|
||||
/// One chunk was rebuilt from the XOR parity chunk.
|
||||
final bool recoveredWithParity;
|
||||
|
||||
/// This is the local user's own send. Its PNG is their real 512x512 crop, so
|
||||
/// [synthesized] is false and the R6 label must NOT be shown.
|
||||
/// This is the local user's own send.
|
||||
final bool isOutgoing;
|
||||
|
||||
/// Whether the pixels are generative-model output. Derived, never supplied:
|
||||
/// `synthesized == !isOutgoing`.
|
||||
bool get synthesized => !isOutgoing;
|
||||
/// Whether the pixels are generative-model output, so the R6 label must be
|
||||
/// shown. Always true for received images. For the user's own send it is
|
||||
/// true when the PNG is the version they picked, decoded as recipients see
|
||||
/// it, and false only when it is the stretched original (a device that
|
||||
/// could not decode).
|
||||
final bool synthesized;
|
||||
|
||||
/// Our own image only: repeater echoes heard for each chunk, data chunks
|
||||
/// first and the parity chunk last. Null when not tracked.
|
||||
final List<int>? chunkEchoes;
|
||||
|
||||
/// The fewest echoes any data chunk got: every data chunk was heard
|
||||
/// repeated at least this many times. Null when not tracked.
|
||||
int? get minDataChunkEchoes {
|
||||
final echoes = chunkEchoes;
|
||||
if (echoes == null || echoes.isEmpty) return null;
|
||||
final data = echoes.length > totalChunks
|
||||
? echoes.sublist(0, totalChunks)
|
||||
: echoes;
|
||||
return data.reduce((a, b) => a < b ? a : b);
|
||||
}
|
||||
|
||||
final int? decodeMs;
|
||||
final String? error;
|
||||
@@ -237,6 +254,8 @@ class ReceivedImageEntry {
|
||||
this.metadataAssumed = true,
|
||||
this.recoveredWithParity = false,
|
||||
this.isOutgoing = false,
|
||||
bool? synthesized,
|
||||
this.chunkEchoes,
|
||||
this.decodeMs,
|
||||
this.error,
|
||||
this.needsManualDecode = false,
|
||||
@@ -245,7 +264,7 @@ class ReceivedImageEntry {
|
||||
this.bitstreamByteCount = 0,
|
||||
this.pngByteCount = 0,
|
||||
this.pngBytes,
|
||||
});
|
||||
}) : synthesized = synthesized ?? !isOutgoing;
|
||||
|
||||
ImageStreamKey get key => ImageStreamKey(
|
||||
senderPrefix: senderPrefix,
|
||||
@@ -282,6 +301,7 @@ class ReceivedImageEntry {
|
||||
int? bitstreamByteCount,
|
||||
int? pngByteCount,
|
||||
Object? pngBytes = _unset,
|
||||
List<int>? chunkEchoes,
|
||||
}) {
|
||||
return ReceivedImageEntry(
|
||||
streamId: streamId,
|
||||
@@ -299,6 +319,8 @@ class ReceivedImageEntry {
|
||||
metadataAssumed: metadataAssumed ?? this.metadataAssumed,
|
||||
recoveredWithParity: recoveredWithParity ?? this.recoveredWithParity,
|
||||
isOutgoing: isOutgoing,
|
||||
synthesized: synthesized,
|
||||
chunkEchoes: chunkEchoes ?? this.chunkEchoes,
|
||||
decodeMs: identical(decodeMs, _unset) ? this.decodeMs : decodeMs as int?,
|
||||
error: identical(error, _unset) ? this.error : error as String?,
|
||||
needsManualDecode: needsManualDecode ?? this.needsManualDecode,
|
||||
@@ -329,6 +351,7 @@ class ReceivedImageEntry {
|
||||
'recoveredWithParity': recoveredWithParity,
|
||||
'isOutgoing': isOutgoing,
|
||||
'synthesized': synthesized,
|
||||
if (chunkEchoes != null) 'chunkEchoes': chunkEchoes,
|
||||
'needsManualDecode': needsManualDecode,
|
||||
'bitstreamStored': bitstreamStored,
|
||||
'pngStored': pngStored,
|
||||
@@ -357,6 +380,10 @@ class ReceivedImageEntry {
|
||||
metadataAssumed: json['metadataAssumed'] as bool? ?? true,
|
||||
recoveredWithParity: json['recoveredWithParity'] as bool? ?? false,
|
||||
isOutgoing: json['isOutgoing'] as bool? ?? false,
|
||||
synthesized: json['synthesized'] as bool?,
|
||||
chunkEchoes: (json['chunkEchoes'] as List<dynamic>?)
|
||||
?.whereType<int>()
|
||||
.toList(),
|
||||
decodeMs: json['decodeMs'] as int?,
|
||||
error: json['error'] as String?,
|
||||
needsManualDecode: json['needsManualDecode'] as bool? ?? false,
|
||||
@@ -1041,6 +1068,9 @@ class ReceivedImageStore extends ChangeNotifier {
|
||||
required AeicRatePoint rate,
|
||||
required int chunkCount,
|
||||
int aspectCode = 0,
|
||||
bool synthesized = false,
|
||||
List<int>? chunkEchoes,
|
||||
int payloadBytes = 0,
|
||||
DateTime? at,
|
||||
}) async {
|
||||
final now = at ?? _clock();
|
||||
@@ -1069,6 +1099,11 @@ class ReceivedImageStore extends ChangeNotifier {
|
||||
aspectCode: aspectCode,
|
||||
metadataAssumed: false,
|
||||
isOutgoing: true,
|
||||
synthesized: synthesized,
|
||||
chunkEchoes: chunkEchoes,
|
||||
// The size of what was sent, for the caption and packet info. The
|
||||
// bitstream itself is not kept, so bitstreamStored stays false.
|
||||
bitstreamByteCount: payloadBytes,
|
||||
pngStored: pngWritten,
|
||||
pngByteCount: pngWritten ? previewPng.length : 0,
|
||||
pngBytes: previewPng,
|
||||
@@ -1078,6 +1113,31 @@ class ReceivedImageStore extends ChangeNotifier {
|
||||
return stored;
|
||||
}
|
||||
|
||||
/// Records repeater echoes of the user's own image (see
|
||||
/// `MeshCoreConnector.ownImageEchoes`). Echoes that land before the image is
|
||||
/// registered are passed to [registerOutgoing] instead.
|
||||
Future<void> setOutgoingEchoes({
|
||||
required int channelIndex,
|
||||
required int senderPrefix,
|
||||
required int imgId,
|
||||
required List<int> echoes,
|
||||
}) async {
|
||||
ReceivedImageEntry? match;
|
||||
for (final entry in _entries.values) {
|
||||
if (!entry.isOutgoing ||
|
||||
entry.imgId != imgId ||
|
||||
entry.channelIndex != channelIndex ||
|
||||
entry.senderPrefix != senderPrefix) {
|
||||
continue;
|
||||
}
|
||||
if (match == null || entry.firstSeen.isAfter(match.firstSeen)) {
|
||||
match = entry;
|
||||
}
|
||||
}
|
||||
if (match == null) return;
|
||||
await _store(match.copyWith(chunkEchoes: List<int>.unmodifiable(echoes)));
|
||||
}
|
||||
|
||||
// ---- decode scheduling ---------------------------------------------------
|
||||
|
||||
/// App lifecycle gate. Backgrounding cancels an in-flight decode and returns
|
||||
|
||||
@@ -109,6 +109,11 @@ class UiViewStateService extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> reload() async {
|
||||
await initialize();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setContactsSelectedGroupName(String value) {
|
||||
if (_contactsSelectedGroupName == value) return;
|
||||
_contactsSelectedGroupName = value;
|
||||
|
||||
Reference in new issue
Block a user