mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
## What changes Recently opened mobile threads show saved replies in the timeline while relay history loads, including after an offline cold start. The thread keeps the visible reply in place when relay history takes over. Relay history supplies paging and reply counts. Until then, rows shown only from disk are excluded from read marking and nested navigation. Live rows remain interactive. After a fetch fails, a link can land on a saved reply while the app retries. A manual scroll supersedes a pending link jump. A deleted thread head keeps the reply status and Retry visible. Thread pages use the existing app-private cache, keyed by channel and outermost thread root. A completed scan supplies signed replies and auxiliary events. Before saving, the app reuses a loaded signed root when available. It queries the relay's primary database for a missing root and for rows that need verification based on observed mutations or the prior saved page. An additive table in the existing SQLite cache records exact pruned IDs by thread. A restart retains that evidence and an ordinary new reply uses the completed scan. The table is added alongside existing saved channel pages and follows their scope, purge and eviction rules. A channel-only prune skips the table allocation. At SQLite’s page cap, a thread prune can reclaim space using the cache’s existing eviction order. The cache verifies events before replacing a page and retains the prior page if an applicable edit or deletion fails verification. A saved root lets its link open offline when the channel cache holds only newer messages. Channel and identity purges include thread pages. Live edits and deletions remove affected saved rows whether the thread is open or closed. A confirmed thread query refusal marks the channel unavailable, clears the thread and announces the change. An empty legacy history response can also mean refusal, so it leaves a confirmed denial in place until channel history verifies access. A deletion from relay history or the saved page can also suppress the thread head. ## Thread cache limits The app attempts a save once per thread open, with up to 200 replies plus the root. The save makes at most one extra request, and a loaded root with no affected edit targets can skip it even if the thread has new replies. A first-time edit that the client has never seen can be delayed by replica lag. If a live edit targets a reply that never reached the saved page, the in-memory record is lost on app restart. A reopen during replica lag can then save its earlier text. Evicting a page also evicts its comparison evidence. Bigger threads still load all their replies online. An oversized initial scan clears the old saved page. Replies that arrive during a visit become eligible for saving on the next online visit. If an attempt fails or a live update retires it, the next attempt is on reopen. Links that identify only a nested parent still use the existing channel lookup. ## Simulator comparison iPhone 17e, iOS 27.0, debug build, same joined channel and seeded 40-reply thread. A local probe measured from dispatching the deep link on a cold launch to the first reply appearing in the widget tree. The offline runs used a stopped fixture relay. The candidate had opened the thread once online before measurement. It retains the existing 250 ms delay before starting a disk preview on a connected session. [Simulator screenshots](https://github.com/block/buzz/pull/9844#issuecomment-7053182318) | Reopen | `f9b18c7f3` | `49a071cad` | | --- | ---: | ---: | | Online, four runs per build | 978 ms median (915–990 ms) | 922 ms median (903–1,143 ms) | | Offline, three runs per build | No replies within 8 seconds in any run | 832 ms median (810–856 ms) | ## Cold link to an older thread I added 55 newer channel messages and verified in SQLite that the saved channel page held 50 messages and omitted the thread root. One cold run per condition on the same iPhone 17e fixture measured the first reply after dispatch. The bounded build carried only a lint cleanup into the published commit. | Condition | Previous PR head `9756f89ed` | Bounded build `34067e50b` | | --- | ---: | ---: | | Online | 1,451 ms | 1,432 ms | | Relay stopped | Opened the channel. No thread replies within 8 seconds. | Opened the thread and showed saved replies in 1,276 ms. | The two regression tests fail on `9756f89ed` and pass with the fix. The cache test reproduces an observed edit followed by a scan that returns pre-edit text. The provider tests also check the one-attempt budget across refresh and the 200-reply cutoff. ## Verification - `just mobile-install mobile-check mobile-test file-size-check` passed at `49a071cad`. 5,909 Flutter tests passed with 71 skipped, and all 27 crypto package tests passed. - Widget regressions cover saved-to-relay handoff, unread and count gating, live deletion, offline link arrival order, and refusal semantics. The simulator comparison used synthetic data. Device-level VoiceOver and TalkBack announcement behavior remains unverified. - The open offline thread switched to live history after the relay restarted. With the thread and channel then closed, a live edit and deletion removed the two stale saved rows and retained all 38 other replies in the cache. - The iPhone 17e build at `30bf26781` reopened a seeded 24-reply thread from a cold link in 1,105 ms online and 995 ms with the relay stopped, one run each. The channel reply count also opened the saved thread with the relay stopped. After scrolling back in the offline thread and restarting the relay, the same replies stayed in place and the saved label switched to the live reply count. - At `dca8250fa`, the normal mobile pre-push and file-size checks passed. The two SQLite page-cap regressions failed against `30bf26781` and passed with the fix. The simulator timings below the original comparison are from `30bf26781`. - Local SQLite tests cover restart with a previously saved edit, restart after live pruning removes the final row, rejection of a replacement containing an invalid edit, a deletion that survives replacement, zero extra writer requests when new replies arrive without edits, and targeted pruning at the SQLite page cap. Widget tests cover saved-link landing under the production retry policy and Retry beside a deleted head. Both failed on the earlier head and passed with the fix. ## Try it 1. Open a populated thread from its reply count while connected and let its replies load. Copy its link. 2. Force-quit, turn on airplane mode and reopen from the channel reply count and from the link. Confirm that the saved replies appear in the existing thread timeline. 3. Scroll away from Latest, then reconnect with the thread still open. Confirm the visible reply stays in place, the live count replaces the saved label, and read state follows the live replies. --------- Signed-off-by: Wes <wesb@block.xyz> Co-authored-by: Star Lord <b89298dbe87c6b3fd8a425b535d9d161f23c88d555a47925ae0b04dfe02b201e@buzz.block.builderlab.xyz>
540 lines
18 KiB
Dart
540 lines
18 KiB
Dart
import 'dart:async';
|
|
import 'dart:collection';
|
|
import 'dart:io';
|
|
|
|
import 'package:buzz/features/channels/channel_messages_provider.dart';
|
|
import 'package:buzz/features/channels/saved_channel_page.dart';
|
|
import 'package:buzz/features/channels/thread_replies_provider.dart';
|
|
import 'package:buzz/features/channels/timeline_message.dart';
|
|
import 'package:buzz/shared/channels/saved_message_store.dart';
|
|
import 'package:buzz/shared/crypto/event_signing.dart';
|
|
import 'package:buzz/shared/relay/relay.dart';
|
|
import 'package:buzz/shared/relay/relay_author_provider.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import '../../helpers/thread_ids.dart';
|
|
|
|
const _scope = (communityId: 'cache-test-community', pubkey: 'viewer');
|
|
const _args = ThreadRepliesArgs(channelId: 'channel', rootId: threadIdRoot);
|
|
const _otherArgs = ThreadRepliesArgs(channelId: 'other', rootId: threadIdRoot);
|
|
|
|
NostrEvent _event(
|
|
String content, {
|
|
ThreadRepliesArgs args = _args,
|
|
int kind = EventKind.streamMessage,
|
|
String? deletionTarget,
|
|
bool isRoot = false,
|
|
}) => NostrEvent.fromJson(
|
|
signNostrEvent(
|
|
secretKey:
|
|
'0000000000000000000000000000000000000000000000000000000000000001',
|
|
kind: kind,
|
|
content: content,
|
|
tags: [
|
|
['h', args.channelId],
|
|
if (deletionTarget != null)
|
|
['e', deletionTarget]
|
|
else if (!isRoot)
|
|
['e', args.rootId, '', 'reply'],
|
|
],
|
|
).toMap(),
|
|
);
|
|
|
|
class _Relay extends RelaySessionNotifier {
|
|
final threadQueries = Queue<Future<List<NostrEvent>>>();
|
|
List<NostrEvent> writerEvents = const [];
|
|
final writerFilters = <NostrFilter>[];
|
|
final channelQuery = Completer<List<NostrEvent>>();
|
|
final subscribed = Completer<void>();
|
|
late void Function(NostrEvent) emit;
|
|
late void Function(String) closeChannel;
|
|
|
|
@override
|
|
SessionState build() =>
|
|
const SessionState(status: SessionStatus.disconnected);
|
|
|
|
void connect() => state = const SessionState(status: SessionStatus.connected);
|
|
|
|
@override
|
|
Future<List<NostrEvent>> queryRelay(
|
|
List<NostrFilter> filters, {
|
|
Duration timeout = const Duration(seconds: 8),
|
|
}) async {
|
|
if (filters.first.extensions.containsKey('thread_cursor')) {
|
|
return threadQueries.removeFirst();
|
|
}
|
|
if (filters.every(
|
|
(filter) => filter.extensions['consistency'] == 'strong',
|
|
)) {
|
|
writerFilters.addAll(filters);
|
|
return writerEvents;
|
|
}
|
|
return channelQuery.future;
|
|
}
|
|
|
|
@override
|
|
Future<void Function()> subscribe(
|
|
NostrFilter filter,
|
|
void Function(NostrEvent) onEvent, {
|
|
void Function(String message)? onClosed,
|
|
}) async {
|
|
emit = onEvent;
|
|
closeChannel = onClosed!;
|
|
subscribed.complete();
|
|
return () {};
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
|
late Directory root;
|
|
late _Relay relay;
|
|
late ProviderContainer container;
|
|
late SavedMessageStore store;
|
|
|
|
void openCacheSession() {
|
|
relay = _Relay();
|
|
container = ProviderContainer(
|
|
retry: (_, _) => null,
|
|
overrides: [
|
|
relaySessionProvider.overrideWith(() => relay),
|
|
relayAuthorProvider.overrideWith((ref, url) => null),
|
|
savedMessageScopeProvider.overrideWithValue(_scope),
|
|
savedMessageRootProvider.overrideWith((ref) async => root),
|
|
],
|
|
);
|
|
store = container.read(savedMessageStoreProvider);
|
|
}
|
|
|
|
setUp(() async {
|
|
root = await Directory.systemTemp.createTemp('buzz-thread-cache');
|
|
openCacheSession();
|
|
});
|
|
|
|
tearDown(() async {
|
|
container.dispose();
|
|
await root.delete(recursive: true);
|
|
});
|
|
|
|
Future<void> paint() async {
|
|
await Future<void>.delayed(Duration.zero);
|
|
binding.handleBeginFrame(null);
|
|
binding.handleDrawFrame();
|
|
await Future<void>.delayed(Duration.zero);
|
|
}
|
|
|
|
Future<List<NostrEvent>?> waitForSaved(
|
|
SavedMessagePage page,
|
|
Iterable<NostrEvent> expected,
|
|
) async {
|
|
final ids = expected.map((event) => event.id).toSet();
|
|
final elapsed = Stopwatch()..start();
|
|
List<NostrEvent>? saved;
|
|
do {
|
|
saved = await store.read(store.capture(_scope, page));
|
|
if (saved != null &&
|
|
saved.length == ids.length &&
|
|
saved.every((event) => ids.contains(event.id))) {
|
|
return saved;
|
|
}
|
|
// Yield to the write worker while observing the durable result.
|
|
await Future<void>.delayed(const Duration(milliseconds: 1));
|
|
} while (elapsed.elapsed < const Duration(seconds: 2));
|
|
return saved;
|
|
}
|
|
|
|
for (final lateRefusal in [false, true]) {
|
|
test(
|
|
'an invalidated thread scan cannot ${lateRefusal ? 'purge' : 'overwrite'} the newer page',
|
|
() async {
|
|
final retired = Completer<List<NostrEvent>>();
|
|
final oldReply = _event('Old reply');
|
|
final newReply = _event('New reply');
|
|
relay.threadQueries.addAll([
|
|
retired.future,
|
|
Future.value([oldReply, newReply]),
|
|
]);
|
|
|
|
final replies = threadRepliesProvider(_args);
|
|
container.listen(replies, (_, _) {});
|
|
expect(relay.threadQueries, hasLength(1));
|
|
container.invalidate(replies);
|
|
expect(await container.read(replies.future), [oldReply, newReply]);
|
|
await paint();
|
|
|
|
Future<List<NostrEvent>?> readSaved() =>
|
|
store.read(store.capture(_scope, _args.savedPage));
|
|
expect(await waitForSaved(_args.savedPage, [oldReply, newReply]), [
|
|
oldReply,
|
|
newReply,
|
|
]);
|
|
|
|
final refusal = RelayException(403, 'restricted: not a channel member');
|
|
if (lateRefusal) {
|
|
retired.completeError(refusal);
|
|
} else {
|
|
retired.complete([oldReply]);
|
|
}
|
|
await paint();
|
|
expect(await readSaved(), [oldReply, newReply]);
|
|
|
|
// A refusal from the current scan still purges the page.
|
|
relay.threadQueries.add(
|
|
Future<List<NostrEvent>>.microtask(() => throw refusal),
|
|
);
|
|
container.invalidate(replies);
|
|
await expectLater(
|
|
container.read(replies.future),
|
|
throwsA(same(refusal)),
|
|
);
|
|
expect(await readSaved(), isNull);
|
|
},
|
|
);
|
|
}
|
|
|
|
test('a new scan saves the signed root and edits from the writer', () async {
|
|
final head = _event('Older thread head', isRoot: true);
|
|
final args = ThreadRepliesArgs(channelId: _args.channelId, rootId: head.id);
|
|
final reply = _event('Original reply', args: args);
|
|
final edit = _event(
|
|
'Edited reply',
|
|
args: args,
|
|
kind: EventKind.streamMessageEdit,
|
|
deletionTarget: reply.id,
|
|
);
|
|
Future<List<NostrEvent>?> readSaved() =>
|
|
store.read(store.capture(_scope, args.savedPage));
|
|
|
|
await store.save(store.capture(_scope, args.savedPage), [
|
|
reply,
|
|
], relayAuthor: null);
|
|
container.listen(channelMessagesProvider(args.channelId), (_, _) {});
|
|
relay.connect();
|
|
await relay.subscribed.future;
|
|
relay.emit(edit);
|
|
expect(await readSaved(), isNull);
|
|
|
|
relay.threadQueries.add(Future.value([reply]));
|
|
relay.writerEvents = [head, reply, edit];
|
|
final replies = threadRepliesProvider(args);
|
|
final openThread = container.listen(replies, (_, _) {});
|
|
expect(await container.read(replies.future), [reply]);
|
|
await paint();
|
|
|
|
final saved = await waitForSaved(args.savedPage, [head, reply, edit]);
|
|
expect(relay.writerFilters, hasLength(2));
|
|
expect(saved, [head, reply, edit]);
|
|
expect(
|
|
formatTimeline(
|
|
saved!,
|
|
).singleWhere((event) => event.id == reply.id).content,
|
|
'Edited reply',
|
|
);
|
|
expect(relay.writerFilters, hasLength(2));
|
|
expect(relay.writerFilters.first.ids, unorderedEquals([head.id, reply.id]));
|
|
expect(relay.writerFilters.last.tags['#e'], [reply.id]);
|
|
for (final filter in relay.writerFilters) {
|
|
expect(filter.tags['#h'], [args.channelId]);
|
|
}
|
|
|
|
final laterReply = _event('Arrived after opening', args: args);
|
|
relay.threadQueries.add(Future.value([reply, laterReply]));
|
|
container.invalidate(replies);
|
|
expect(await container.read(replies.future), [reply, laterReply]);
|
|
await paint();
|
|
expect(relay.writerFilters, hasLength(2));
|
|
expect(await readSaved(), saved);
|
|
|
|
openThread.close();
|
|
await container.pump();
|
|
relay.writerEvents = [head, reply, edit];
|
|
relay.threadQueries.add(Future.value([reply, laterReply]));
|
|
final reopenedThread = container.listen(replies, (_, _) {});
|
|
expect(await container.read(replies.future), [reply, laterReply]);
|
|
await paint();
|
|
expect(
|
|
await waitForSaved(args.savedPage, [head, reply, laterReply, edit]),
|
|
unorderedEquals([head, reply, laterReply, edit]),
|
|
);
|
|
expect(relay.writerFilters, hasLength(4));
|
|
expect(relay.writerFilters.last.tags['#e'], [reply.id]);
|
|
|
|
// The writer response is still untrusted. A forged edit cannot make the
|
|
// already superseded original eligible for the saved page.
|
|
final forged = NostrEvent.fromJson({...edit.toJson(), 'content': 'Forged'});
|
|
reopenedThread.close();
|
|
await container.pump();
|
|
relay.writerEvents = [head, reply, forged];
|
|
relay.threadQueries.add(Future.value([reply, laterReply]));
|
|
container.listen(replies, (_, _) {});
|
|
expect(await container.read(replies.future), [reply, laterReply]);
|
|
await paint();
|
|
expect(
|
|
await waitForSaved(args.savedPage, [head, reply, laterReply, edit]),
|
|
unorderedEquals([head, reply, laterReply, edit]),
|
|
);
|
|
});
|
|
|
|
test(
|
|
'a thread with a loaded root and no observed edits needs no extra query',
|
|
() async {
|
|
final head = _event('Loaded thread head', isRoot: true);
|
|
final args = ThreadRepliesArgs(
|
|
channelId: _args.channelId,
|
|
rootId: head.id,
|
|
);
|
|
final reply = _event('Original reply', args: args);
|
|
final channel = channelMessagesProvider(args.channelId);
|
|
container.listen(channel, (_, _) {});
|
|
relay.connect();
|
|
await relay.subscribed.future;
|
|
relay.emit(head);
|
|
expect(container.read(channel).value, contains(head));
|
|
relay.threadQueries.add(Future.value([reply]));
|
|
final replies = threadRepliesProvider(args);
|
|
final opened = container.listen(replies, (_, _) {});
|
|
expect(await container.read(replies.future), [reply]);
|
|
await paint();
|
|
expect(relay.writerFilters, isEmpty);
|
|
expect(await waitForSaved(args.savedPage, [head, reply]), [head, reply]);
|
|
|
|
opened.close();
|
|
await container.pump();
|
|
final later = _event('New reply', args: args);
|
|
relay.threadQueries.add(Future.value([reply, later]));
|
|
container.listen(replies, (_, _) {});
|
|
expect(await container.read(replies.future), [reply, later]);
|
|
await paint();
|
|
expect(await waitForSaved(args.savedPage, [head, reply, later]), [
|
|
head,
|
|
reply,
|
|
later,
|
|
]);
|
|
expect(relay.writerFilters, isEmpty);
|
|
},
|
|
);
|
|
|
|
for (final prunedBeforeRestart in [false, true]) {
|
|
test(
|
|
'a replica cannot restore the original after restart (pruned: $prunedBeforeRestart)',
|
|
() async {
|
|
final head = _event('Older head', isRoot: true);
|
|
final args = ThreadRepliesArgs(
|
|
channelId: _args.channelId,
|
|
rootId: head.id,
|
|
);
|
|
final reply = _event('Original', args: args);
|
|
final edit = _event(
|
|
'Revised',
|
|
args: args,
|
|
kind: EventKind.streamMessageEdit,
|
|
deletionTarget: reply.id,
|
|
);
|
|
final ticket = store.capture(_scope, args.savedPage);
|
|
await store.save(
|
|
ticket,
|
|
prunedBeforeRestart ? [reply] : [head, reply, edit],
|
|
relayAuthor: null,
|
|
);
|
|
if (prunedBeforeRestart) {
|
|
store.removeChannelEvents(_scope, args.channelId, {
|
|
reply.id,
|
|
}, edited: true);
|
|
expect(
|
|
await store.read(store.capture(_scope, args.savedPage)),
|
|
isNull,
|
|
);
|
|
}
|
|
container.dispose();
|
|
openCacheSession();
|
|
|
|
relay.threadQueries.add(Future.value([reply]));
|
|
relay.writerEvents = [head, reply, edit];
|
|
final provider = threadRepliesProvider(args);
|
|
container.listen(provider, (_, _) {});
|
|
expect(await container.read(provider.future), [reply]);
|
|
await paint();
|
|
expect(await waitForSaved(args.savedPage, [head, reply, edit]), [
|
|
head,
|
|
reply,
|
|
edit,
|
|
]);
|
|
expect(relay.writerFilters.last.tags['#e'], contains(reply.id));
|
|
},
|
|
);
|
|
}
|
|
|
|
test(
|
|
'a pruned deletion survives restart and a later page replacement',
|
|
() async {
|
|
final head = _event('Saved head', isRoot: true);
|
|
final args = ThreadRepliesArgs(
|
|
channelId: _args.channelId,
|
|
rootId: head.id,
|
|
);
|
|
final deleted = _event('Deleted reply', args: args);
|
|
final newer = _event('New reply', args: args);
|
|
await store.save(store.capture(_scope, args.savedPage), [
|
|
head,
|
|
deleted,
|
|
], relayAuthor: null);
|
|
store.removeChannelEvents(_scope, args.channelId, {deleted.id});
|
|
expect(
|
|
(await store.inspectThread(
|
|
store.capture(_scope, args.savedPage),
|
|
))?.pruned,
|
|
{deleted.id: false},
|
|
);
|
|
container.dispose();
|
|
openCacheSession();
|
|
final channel = channelMessagesProvider(args.channelId);
|
|
container.listen(channel, (_, _) {});
|
|
relay.connect();
|
|
await relay.subscribed.future;
|
|
relay.emit(head);
|
|
relay.threadQueries.add(Future.value([deleted, newer]));
|
|
final replies = threadRepliesProvider(args);
|
|
container.listen(replies, (_, _) {});
|
|
await container.read(replies.future);
|
|
await paint();
|
|
expect(await waitForSaved(args.savedPage, [head, newer]), [head, newer]);
|
|
expect(relay.writerFilters, isEmpty);
|
|
expect(
|
|
(await store.inspectThread(
|
|
store.capture(_scope, args.savedPage),
|
|
))?.pruned,
|
|
{deleted.id: false},
|
|
);
|
|
await store.removeChannel(_scope, args.channelId);
|
|
expect(
|
|
await store.inspectThread(store.capture(_scope, args.savedPage)),
|
|
isNull,
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'an invalid edit cannot replace a pruned thread after restart',
|
|
() async {
|
|
final head = _event('Older head', isRoot: true);
|
|
final args = ThreadRepliesArgs(
|
|
channelId: _args.channelId,
|
|
rootId: head.id,
|
|
);
|
|
final reply = _event('Original', args: args);
|
|
final edit = _event(
|
|
'Revised',
|
|
args: args,
|
|
kind: EventKind.streamMessageEdit,
|
|
deletionTarget: reply.id,
|
|
);
|
|
await store.save(store.capture(_scope, args.savedPage), [
|
|
reply,
|
|
], relayAuthor: null);
|
|
store.removeChannelEvents(_scope, args.channelId, {
|
|
reply.id,
|
|
}, edited: true);
|
|
final prunedPage = await store.inspectThread(
|
|
store.capture(_scope, args.savedPage),
|
|
);
|
|
expect(prunedPage?.events, isEmpty);
|
|
expect(prunedPage?.pruned, {reply.id: true});
|
|
container.dispose();
|
|
openCacheSession();
|
|
|
|
final ticket = store.capture(_scope, args.savedPage);
|
|
final forged = NostrEvent.fromJson({
|
|
...edit.toJson(),
|
|
'content': 'Forged',
|
|
});
|
|
await store.save(ticket, [head, reply, forged], relayAuthor: null);
|
|
expect(await store.read(ticket), isNull);
|
|
expect((await store.inspectThread(ticket))?.pruned, {reply.id: true});
|
|
},
|
|
);
|
|
|
|
test(
|
|
'an empty thread result cannot clear confirmed channel refusal',
|
|
() async {
|
|
final channel = channelMessagesProvider(_args.channelId);
|
|
container.listen(channel, (_, _) {});
|
|
relay.connect();
|
|
await relay.subscribed.future;
|
|
final response = Completer<List<NostrEvent>>();
|
|
relay.threadQueries.add(response.future);
|
|
final replies = threadRepliesProvider(_args);
|
|
container.listen(replies, (_, _) {});
|
|
final pending = container.read(replies.future);
|
|
relay.closeChannel('restricted: not a channel member');
|
|
expect(container.read(channel).error, isNotNull);
|
|
response.complete([]);
|
|
expect(await pending, isEmpty);
|
|
await paint();
|
|
expect(container.read(channel).error, isNotNull);
|
|
expect(relay.writerFilters, isEmpty);
|
|
expect(await store.read(store.capture(_scope, _args.savedPage)), isNull);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'oversized threads keep complete relay history and skip the writer',
|
|
() async {
|
|
final old = _event('Previously saved reply');
|
|
final ticket = store.capture(_scope, _args.savedPage);
|
|
await store.save(ticket, [old], relayAuthor: null);
|
|
final batch =
|
|
[
|
|
for (var index = 0; index < 201; index++)
|
|
_event('Large thread reply $index'),
|
|
]..sort((a, b) {
|
|
final time = a.createdAt.compareTo(b.createdAt);
|
|
return time == 0 ? a.id.compareTo(b.id) : time;
|
|
});
|
|
relay.threadQueries.addAll([
|
|
Future.value(batch.take(200).toList()),
|
|
Future.value([batch.last]),
|
|
]);
|
|
final replies = threadRepliesProvider(_args);
|
|
container.listen(replies, (_, _) {});
|
|
expect(await container.read(replies.future), batch);
|
|
await paint();
|
|
expect(relay.writerFilters, isEmpty);
|
|
expect(await store.read(ticket), isNull);
|
|
},
|
|
);
|
|
|
|
test('a live deletion retires an already displayed thread preview', () async {
|
|
final removed = _event('Deleted while history is pending');
|
|
final retained = _event('Same-channel neighbor');
|
|
final unrelated = _event('Other channel', args: _otherArgs);
|
|
final preview = savedThreadPreviewProvider(_args.savedPage);
|
|
final otherPreview = savedThreadPreviewProvider(_otherArgs.savedPage);
|
|
await store.save(store.capture(_scope, _args.savedPage), [
|
|
removed,
|
|
retained,
|
|
], relayAuthor: null);
|
|
await store.save(store.capture(_scope, _otherArgs.savedPage), [
|
|
unrelated,
|
|
], relayAuthor: null);
|
|
container.listen(preview, (_, _) {});
|
|
container.listen(otherPreview, (_, _) {});
|
|
expect(await container.read(preview.future), [removed, retained]);
|
|
expect(await container.read(otherPreview.future), [unrelated]);
|
|
final unaffected = container.read(otherPreview);
|
|
|
|
container.listen(channelMessagesProvider(_args.channelId), (_, _) {});
|
|
relay.connect();
|
|
await relay.subscribed.future;
|
|
relay.emit(
|
|
_event('', kind: EventKind.deletion, deletionTarget: removed.id),
|
|
);
|
|
final displayed = await container.read(preview.future);
|
|
expect(await store.read(store.capture(_scope, _args.savedPage)), [
|
|
retained,
|
|
]);
|
|
expect(displayed, [retained]);
|
|
expect(container.read(otherPreview), same(unaffected));
|
|
});
|
|
}
|