feat(block2): offline outbox — share now, publish when connected

Sender-side offline delivery hardening.
- OfferOutbox: a keystore-backed (no plaintext) queue of lot ids to publish
  later. Stores ids, not offers, so on flush each offer is rebuilt from the
  lot's CURRENT state — an offline edit is respected, a deleted lot drops out.
- flushOutbox(): on reconnect, republishes queued lots and clears them (no-op
  offline; drops ids whose lot is gone).
- Market screen: sharing offline parks the lots ('we'll share these when you're
  connected'); opening the market online auto-flushes the queue first.
- Wired via DI + TaneApp(outbox); i18n en/es/pt.

Tests: 4 outbox + 3 flush + market UI, 20 green. Analyzer clean for new code.
This commit is contained in:
vjrj 2026-07-10 10:45:53 +02:00
parent 2a6b4b0947
commit cf5d0243ee
15 changed files with 222 additions and 8 deletions

View file

@ -6,6 +6,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import '../data/variety_repository.dart';
import '../services/offer_mapper.dart';
import '../services/offer_outbox.dart';
import '../services/social_service.dart';
import '../services/social_settings.dart';
@ -178,3 +179,31 @@ Future<OffersCubit> createOffersCubit(
return OffersCubit(null); // offline / no relay reachable
}
}
/// Publishes any queued (offline-parked) lots now that we're online, then clears
/// them from the [outbox]. Rebuilds each offer from the lot's CURRENT state, so
/// since-deleted or now-private lots simply drop out. Returns how many published.
Future<int> flushOutbox({
required OfferOutbox outbox,
required OffersCubit cubit,
required List<ShareableLot> shareableLots,
required String authorPubkeyHex,
required String areaGeohash,
}) async {
if (!cubit.isOnline || areaGeohash.isEmpty) return 0;
final queued = await outbox.pending();
if (queued.isEmpty) return 0;
final toPublish =
shareableLots.where((l) => queued.contains(l.lotId)).toList();
var published = 0;
if (toPublish.isNotEmpty) {
published = await cubit.publishLots(
toPublish,
authorPubkeyHex: authorPubkeyHex,
areaGeohash: areaGeohash,
);
}
// Clear everything attempted (or gone) so we don't loop on it.
await outbox.remove(queued);
return published;
}