Merge branch 'claude/nostalgic-wright-acfc25': inline offer photos

Market offers carry a small base64 data-URI thumbnail embedded in the Nostr
event (no media server); full photo stays in the encrypted inventory. Blossom
alternative parked on branch parked/offer-photos-blossom.

# Conflicts:
#	apps/app_seeds/lib/i18n/strings.g.dart
This commit is contained in:
vjrj 2026-07-10 21:43:35 +02:00
commit e2b88b4f26
20 changed files with 520 additions and 16 deletions

View file

@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:commons_core/commons_core.dart';
import 'package:flutter_test/flutter_test.dart';
@ -269,12 +270,14 @@ void main() {
const [
ShareableLot(
lotId: 'lot-1',
varietyId: 'var-1',
summary: 'Tomate',
offerStatus: OfferStatus.shared,
category: 'Solanaceae',
),
ShareableLot(
lotId: 'lot-2',
varietyId: 'var-2',
summary: 'Judía',
offerStatus: OfferStatus.exchange,
),
@ -291,6 +294,88 @@ void main() {
await cubit.close();
});
test('publishLots embeds an inline thumbnail data-URI on the offer',
() async {
final transport = FakeOfferTransport();
var thumbnailed = 0;
final cubit = OffersCubit(
transport,
coverPhoto: (id) async => Uint8List.fromList([1, 2, 3]),
thumbnail: (bytes) {
thumbnailed++;
return 'data:image/jpeg;base64,AAAA';
},
);
await cubit.publishLots(
const [
ShareableLot(
lotId: 'lot-1',
varietyId: 'var-1',
summary: 'Tomate',
offerStatus: OfferStatus.shared,
),
],
authorPubkeyHex: 'ab' * 32,
areaGeohash: 'sp3e9',
);
await cubit.discover('sp3');
await pumpEventQueue();
expect(thumbnailed, 1);
expect(cubit.state.offers.single.imageUrl, 'data:image/jpeg;base64,AAAA');
await cubit.close();
});
test('publishLots still publishes (without image) when thumbnailing fails',
() async {
final transport = FakeOfferTransport();
final cubit = OffersCubit(
transport,
coverPhoto: (id) async => Uint8List.fromList([1, 2, 3]),
thumbnail: (bytes) => throw Exception('boom'),
);
final count = await cubit.publishLots(
const [
ShareableLot(
lotId: 'lot-1',
varietyId: 'var-1',
summary: 'Tomate',
offerStatus: OfferStatus.shared,
),
],
authorPubkeyHex: 'ab' * 32,
areaGeohash: 'sp3e9',
);
expect(count, 1); // the offer still went out
await cubit.discover('sp3');
await pumpEventQueue();
expect(cubit.state.offers.single.imageUrl, isNull);
await cubit.close();
});
test('publishLots without a thumbnailer publishes no image', () async {
final transport = FakeOfferTransport();
final cubit = OffersCubit(transport); // no thumbnail, no coverPhoto
await cubit.publishLots(
const [
ShareableLot(
lotId: 'lot-1',
varietyId: 'var-1',
summary: 'Tomate',
offerStatus: OfferStatus.shared,
),
],
authorPubkeyHex: 'ab' * 32,
areaGeohash: 'sp3e9',
);
await cubit.discover('sp3');
await pumpEventQueue();
expect(cubit.state.offers.single.imageUrl, isNull);
await cubit.close();
});
test('publishLots is a no-op offline or with no area', () async {
final offline = OffersCubit(null);
expect(
@ -298,6 +383,7 @@ void main() {
const [
ShareableLot(
lotId: 'x',
varietyId: 'vx',
summary: 'x',
offerStatus: OfferStatus.shared,
),
@ -315,6 +401,7 @@ void main() {
const [
ShareableLot(
lotId: 'x',
varietyId: 'vx',
summary: 'x',
offerStatus: OfferStatus.shared,
),
@ -336,13 +423,20 @@ void main() {
cubit: cubit,
shareableLots: const [
ShareableLot(
lotId: 'lot-1', summary: 'Tomate', offerStatus: OfferStatus.shared),
lotId: 'lot-1',
varietyId: 'var-1',
summary: 'Tomate',
offerStatus: OfferStatus.shared),
ShareableLot(
lotId: 'lot-2',
varietyId: 'var-2',
summary: 'Judía',
offerStatus: OfferStatus.exchange),
ShareableLot(
lotId: 'lot-3', summary: 'Otro', offerStatus: OfferStatus.shared),
lotId: 'lot-3',
varietyId: 'var-3',
summary: 'Otro',
offerStatus: OfferStatus.shared),
],
authorPubkeyHex: 'ab' * 32,
areaGeohash: 'sp3e9',