mirror of
https://github.com/block/buzz.git
synced 2026-10-27 04:30:52 +00:00
## Summary Returning to a previously visited community shows its saved channel list immediately, including offline, while membership and unread state refresh in the background. Initial revalidation failures keep the list visible and retry every 60 seconds without overlapping background attempts. After successful history revalidation, ordinary reconnects use metadata-only refreshes. A reconnect arriving during a background request queues one follow-up attempt; timer ticks never queue overlapping work. History deadlines retain the full-revalidation retry until history succeeds. Snapshots are disposable, versioned and scoped by canonical relay URL and signing identity, capped at 2 MB / 2,000 member channels. They include hidden-DM IDs and prefer fresher in-memory state. Community removal and identity replacement retire outstanding writes; re-adding unchanged credentials preserves the current cache and writer. Startup sweeps orphan snapshots without waiting for disk acknowledgement; community mutations also sweep orphan snapshots, including data restored without secure community records. Cache-delete failures do not block sign-out or strand push revocation; deletion is attempted before journaling and retried by orphan cleanup. Successfully persisted unchanged snapshots skip disk writes; failed writes remain retryable. The cold path reuses fetched membership rosters, overlaps profile/latest-message requests, shares verified DM profiles with avatars, and fetches the own profile once per authenticated connection. Community connection work overlaps the switching animation; avatar hydration no longer gates landing. Full channel refreshes also revalidate cached DM participant profiles so relay-side name changes reach labels and avatars; metadata-only reconnects and background refreshes reuse admitted profiles. Me-chat and invite starter recovery use an explicit fresh membership fetch that propagates errors while leaving the cached list visible. Cached layout/read preferences permit immediate landing; newer cross-device preferences may update ordering or badges after reveal. Integrated with main’s #8490 idle/resume changes: hidden chats detach live subscriptions, background membership polling stays quiet, and each resume reconciles once. Chat history follows main’s live-admission-first ordering to avoid missing messages committed during relay admission; cached community landing remains immediate. ## Validation - `just mobile-install mobile-check mobile-test`: clean analysis; 3,778 tests passed, 19 skipped; four checks for builds without push configuration passed. File-size and diff checks passed. - Provider/storage journeys cover offline startup, failed initial revalidation recovering live delivery, bounded retries, lightweight reconnects, scope isolation, default-port URLs, padded/mismatched stored credentials, credential replacement, backup-restored orphan data, removal races, failed platform deletes and failed writes. - Follow-up regressions cover interrupted native Me-chat lookup, invite failure propagation, retry after an initial list failure, history deadlines, queued reconnects, escaped-path keys, unchanged credential re-adds and non-blocking startup cleanup. Reverting each of the eight behavior/caller/cleanup-order fixes fails its corresponding regression. - DM-name regression changes only the relay profile, verifies a full refresh updates the channel label and shared profile cache, and confirms ordinary reconnects avoid another profile request. The original cache-only implementation fails this regression. - Original signed-in iPhone 18 Pro debug simulator measurements: Buzz's 413 channels went from 6.26–6.30 s to approximately 1.5 s on returning; all three warmed communities switched in 1.47–1.54 s. Real socket pause restored the cached list offline and retained it on reconnect. These are debug simulator observations, not release-device benchmarks. - Integration with current main also passes the real-session resume/background/AUTH and live-admission/detach journeys. - Follow-up failure paths were exercised with deterministic provider/storage tests and widget journeys; the running simulator was not modified during this follow-up. Human acceptance remains pending; this PR stays draft. Try switching among previously visited communities, opening a channel, restarting and repeating. First visits and oversized snapshots require network loading. Cached metadata can be stale until refresh; it lives in ordinary preferences without additional application-level encryption. The snapshot contains no message bodies or credentials. Persistent disk-deletion failures can leave metadata until a later cleanup succeeds. --------- Signed-off-by: Star Lord <b89298dbe87c6b3fd8a425b535d9d161f23c88d555a47925ae0b04dfe02b201e@buzz.block.builderlab.xyz> Co-authored-by: Star Lord <b89298dbe87c6b3fd8a425b535d9d161f23c88d555a47925ae0b04dfe02b201e@buzz.block.builderlab.xyz> Co-authored-by: Rocket <0c41329ade659e01801116549bc617351689892a382bc864a1186dc9191293a7@buzz.block.builderlab.xyz> Co-authored-by: Groot <f4c08302591916fb4b80926bf7e18d22eef8aa0c877e4e841acc46405a45700b@buzz.block.builderlab.xyz> Co-authored-by: Mantis <530af7635ef7d0e1a5189d234338db88cb4ef1ede7119b4ebb4fb05c3eafe3b1@buzz.block.builderlab.xyz>
71 lines
2.2 KiB
Dart
71 lines
2.2 KiB
Dart
part of 'channels_provider.dart';
|
|
|
|
extension _ChannelSnapshots on ChannelsNotifier {
|
|
ChannelListSnapshotStorage? _snapshotStorage() =>
|
|
_lifecycleRef.read(channelListSnapshotStorageProvider);
|
|
|
|
List<Channel>? _restoreSnapshot(String? pubkey, String relay) {
|
|
if (pubkey == null) return null;
|
|
final storage = _snapshotStorage();
|
|
final snapshot = storage?.read(pubkey, relay);
|
|
if (snapshot == null) return null;
|
|
try {
|
|
final channels = snapshot.channels
|
|
.map(Channel.fromJson)
|
|
.where(
|
|
(channel) =>
|
|
channel.isMember && !snapshot.hiddenDmIds.contains(channel.id),
|
|
)
|
|
.toList();
|
|
_hiddenDmIds = Set.unmodifiable(snapshot.hiddenDmIds);
|
|
_hasLoaded = true;
|
|
_hasCachedSnapshot = true;
|
|
_needsSnapshotRevalidation = true;
|
|
return channels;
|
|
} catch (_) {
|
|
unawaited(
|
|
storage!.remove(pubkey, relay).catchError((Object error) {
|
|
debugPrint(
|
|
'[ChannelsNotifier] invalid snapshot removal failed: $error',
|
|
);
|
|
}),
|
|
);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
void Function(List<Channel>, Set<String>)? _captureSnapshotWriter(
|
|
String pubkey,
|
|
String relay,
|
|
) {
|
|
final storage = _snapshotStorage();
|
|
if (storage == null) return null;
|
|
// Capture removal ownership before network I/O. Community removal retires
|
|
// this token even while the active provider is still being torn down.
|
|
final token = storage.capture(pubkey, relay);
|
|
return (channels, hiddenDmIds) {
|
|
final snapshot = ChannelListSnapshot(
|
|
channels: [
|
|
for (final channel in channels)
|
|
if (channel.isMember) channel.toJson(),
|
|
],
|
|
hiddenDmIds: hiddenDmIds,
|
|
);
|
|
unawaited(
|
|
storage
|
|
.write(token, snapshot)
|
|
.then(
|
|
(saved) {
|
|
if (!saved) {
|
|
debugPrint('[ChannelsNotifier] snapshot was not saved');
|
|
}
|
|
},
|
|
onError: (Object error, StackTrace stack) {
|
|
debugPrint('[ChannelsNotifier] snapshot write failed: $error');
|
|
},
|
|
),
|
|
);
|
|
};
|
|
}
|
|
}
|