feat(market): host and publish the cover photo with each offer
Wire the Blossom MediaTransport into publishing: shareable lots carry their varietyId, publishLots uploads the lot's cover photo and puts the returned URL on the offer (best-effort — a hosting failure still publishes the offer, just without a photo). Add a configurable media server (Comunes default, empty to opt out) to settings and the market advanced config.
This commit is contained in:
parent
5bc1715637
commit
fa53295439
17 changed files with 280 additions and 22 deletions
|
|
@ -39,20 +39,34 @@ class SocialService {
|
|||
/// Opens a session against [relayUrls]: one fault-tolerant pool carrying all
|
||||
/// three transports (offers, messaging, trust). Relays that are down are
|
||||
/// skipped; throws only when none are reachable. Caller closes it.
|
||||
Future<SocialSession> openSession(List<String> relayUrls) async {
|
||||
///
|
||||
/// [mediaServerUrl] (a Blossom endpoint) enables offer photos: when set, the
|
||||
/// session exposes a [MediaTransport] to host images. It rides HTTP, not the
|
||||
/// relay pool, so it's independent of relay reachability.
|
||||
Future<SocialSession> openSession(
|
||||
List<String> relayUrls, {
|
||||
String? mediaServerUrl,
|
||||
}) async {
|
||||
final pool = await RelayPool.connect(relayUrls, identity: identity);
|
||||
return SocialSession(pool);
|
||||
return SocialSession(pool, mediaServerUrl: mediaServerUrl);
|
||||
}
|
||||
}
|
||||
|
||||
/// One relay channel with the three transports on top — the
|
||||
/// "one channel, three interfaces" shape, at the app layer.
|
||||
/// "one channel, three interfaces" shape, at the app layer. Media rides its own
|
||||
/// HTTP endpoint (Blossom), so it's a fourth transport but not on the channel.
|
||||
class SocialSession {
|
||||
SocialSession(this._channel)
|
||||
SocialSession(this._channel, {String? mediaServerUrl})
|
||||
: offers = NostrOfferTransport(_channel),
|
||||
messages = NostrMessageTransport(_channel),
|
||||
trust = NostrTrustTransport(_channel),
|
||||
profile = NostrProfileTransport(_channel);
|
||||
profile = NostrProfileTransport(_channel),
|
||||
media = (mediaServerUrl != null && mediaServerUrl.trim().isNotEmpty)
|
||||
? BlossomMediaTransport(
|
||||
Uri.parse(mediaServerUrl.trim()),
|
||||
_channel.privateKeyHex,
|
||||
)
|
||||
: null;
|
||||
|
||||
final NostrChannel _channel;
|
||||
|
||||
|
|
@ -61,7 +75,14 @@ class SocialSession {
|
|||
final TrustTransport trust;
|
||||
final ProfileTransport profile;
|
||||
|
||||
Future<void> close() => _channel.close();
|
||||
/// Hosts offer photos, or null when no media server is configured (offers then
|
||||
/// publish without images).
|
||||
final MediaTransport? media;
|
||||
|
||||
Future<void> close() async {
|
||||
await media?.close();
|
||||
await _channel.close();
|
||||
}
|
||||
}
|
||||
|
||||
Uint8List _hexToBytes(String hex) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class SocialSettings {
|
|||
static const _areaKey = 'tane.social.area_geohash';
|
||||
static const _relaysKey = 'tane.social.relays';
|
||||
static const _searchPrecisionKey = 'tane.social.search_precision';
|
||||
static const _mediaServerKey = 'tane.social.media_server';
|
||||
|
||||
/// How wide "your zone" searches, as a geohash prefix length: 5 ≈ ±2.4 km
|
||||
/// ("very close"), 4 ≈ ±20 km ("around here"), 3 ≈ ±78 km ("my region").
|
||||
|
|
@ -39,6 +40,11 @@ class SocialSettings {
|
|||
'wss://relay.primal.net',
|
||||
];
|
||||
|
||||
/// Blossom media server used to host offer photos so peers can see them. The
|
||||
/// Comunes-run server is the non-commercial default; the user can point this
|
||||
/// at any Blossom server, or clear it to publish offers without photos.
|
||||
static const String defaultMediaServer = 'https://blossom.comunes.org';
|
||||
|
||||
/// The user's coarse area as a low-precision geohash (may be empty). Set
|
||||
/// manually or from device location; the transport coarsens it further.
|
||||
Future<String> areaGeohash() async => (await _store.read(_areaKey)) ?? '';
|
||||
|
|
@ -73,6 +79,18 @@ class SocialSettings {
|
|||
Future<void> setSearchPrecision(int precision) =>
|
||||
_store.write(_searchPrecisionKey, '${_clampPrecision(precision)}');
|
||||
|
||||
/// The Blossom media server for offer photos. Falls back to
|
||||
/// [defaultMediaServer] until the user configures one; an explicitly saved
|
||||
/// empty value turns photo hosting off (offers still publish, without images).
|
||||
Future<String> mediaServerUrl() async {
|
||||
final raw = await _store.read(_mediaServerKey);
|
||||
if (raw == null) return defaultMediaServer; // never configured
|
||||
return raw.trim();
|
||||
}
|
||||
|
||||
Future<void> setMediaServerUrl(String url) =>
|
||||
_store.write(_mediaServerKey, url.trim());
|
||||
|
||||
int _clampPrecision(int p) => p < minSearchPrecision
|
||||
? minSearchPrecision
|
||||
: (p > maxSearchPrecision ? maxSearchPrecision : p);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue