Skip to content

Commit bcfa8cf

Browse files
committed
fix(mobile): reconcile retained targets in deletion proofs
Signed-off-by: Tom Brow <[email protected]>
1 parent c99809a commit bcfa8cf

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

‎mobile/lib/features/channels/channel_messages_provider.dart‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,16 @@ class ChannelMessagesNotifier extends Notifier<AsyncValue<List<NostrEvent>>> {
589589
event.kind != EventKind.nip29DeleteEvent)) {
590590
throw StateError('Expected a deletion in channel $channelId.');
591591
}
592+
_replyOwnership.record(events);
592593
final affectedTargets = scopedStandardDeletion
593-
? targets.intersection(scopedTargetIds)
594+
? targets
595+
.where(
596+
(id) =>
597+
scopedTargetIds.contains(id) ||
598+
_replyOwnership.rootFor(id) != null ||
599+
events.any((cached) => cached.id == id),
600+
)
601+
.toSet()
594602
: targets;
595603
final reconciled = affectedTargets.intersection(reconciledTargetIds);
596604
_retireDeferredDeletionTargets(reconciled);

‎mobile/test/features/channels/channel_messages_provider_test.dart‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,71 @@ void main() {
19321932
);
19331933
}
19341934

1935+
test('unscoped proof reconciles other retained channel targets', () async {
1936+
final session = _RecordingRelaySessionNotifier(
1937+
queryResults: [
1938+
[
1939+
_event(id: 'root', createdAt: 10),
1940+
_event(id: 'other-root', createdAt: 9),
1941+
_event(id: 'unrelated', createdAt: 8),
1942+
_summary(rootId: 'unrelated', replyCount: 2),
1943+
_bounds(),
1944+
],
1945+
<NostrEvent>[],
1946+
<NostrEvent>[],
1947+
],
1948+
);
1949+
final container = _buildContainer(session);
1950+
addTearDown(container.dispose);
1951+
container.listen(channelMessagesProvider(_channelId), (_, _) {});
1952+
await _pumpEventQueue();
1953+
final notifier = container.read(
1954+
channelMessagesProvider(_channelId).notifier,
1955+
);
1956+
for (final root in ['root', 'other-root']) {
1957+
notifier.cacheCompleteThreadQuery(root, {}, [
1958+
_event(
1959+
id: '$root-reply',
1960+
createdAt: 20,
1961+
extraTags: [
1962+
['e', root, '', 'reply'],
1963+
],
1964+
),
1965+
]);
1966+
}
1967+
final deletion = NostrEvent(
1968+
id: 'multi-target-proof',
1969+
pubkey: 'author',
1970+
createdAt: 30,
1971+
kind: EventKind.deletion,
1972+
tags: const [
1973+
['e', 'root-reply'],
1974+
['e', 'other-root-reply'],
1975+
['e', 'outside-channel'],
1976+
],
1977+
content: '',
1978+
sig: 'original-signature',
1979+
);
1980+
notifier.cacheThreadDeletions([deletion], scopedTargetIds: {'root-reply'});
1981+
expect(notifier.cachedThreadReplyIds('other-root'), isEmpty);
1982+
expect(notifier.threadSummaries['other-root']?.descendantCount, 0);
1983+
expect(notifier.threadSummaries['unrelated']!.isCountPending, isFalse);
1984+
await Future<void>.delayed(const Duration(milliseconds: 350));
1985+
expect(notifier.threadSummaries['other-root']?.descendantCount, 0);
1986+
expect(notifier.threadSummaries['other-root']?.isLowerBound, isFalse);
1987+
expect(
1988+
session.queryFilters.where(
1989+
(filter) => filter.extensions['resolve_thread_roots'] == true,
1990+
),
1991+
isEmpty,
1992+
);
1993+
final cached = container
1994+
.read(channelMessagesProvider(_channelId))
1995+
.value!
1996+
.singleWhere((event) => event.id == deletion.id);
1997+
expect(cached, same(deletion));
1998+
});
1999+
19352000
for (final multiTarget in [false, true]) {
19362001
test(
19372002
'unacknowledged reply needs deletion proof (multi-target: $multiTarget)',

0 commit comments

Comments
 (0)