Skip to content

Commit cca99eb

Browse files
committed
fix(mobile): tag kind:5 deletions with channel id
Mobile's deleteMessage emitted a kind:5 deletion with only an `e` tag, so other clients' h-scoped channel subscriptions never observed the delete until a non-channel-scoped fetch backfilled it. Mirror desktop's build_delete_compat: emit both `['h', channelId]` and `['e', eventId]`. Threads channelId through ChannelActions.deleteMessage and its callers. Tag construction is extracted to buildDeleteMessageTags for testing. Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
1 parent 61827c9 commit cca99eb

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

mobile/lib/features/channels/channel_management_provider.dart

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ final channelCanvasProvider = FutureProvider.family<ChannelCanvas, String>((
214214
);
215215
});
216216

217+
/// Channel-scoped kind:5 deletion tags. The `h` tag lets channel-scoped
218+
/// subscriptions observe the delete; the `e` tag points at the target event.
219+
@visibleForTesting
220+
List<List<String>> buildDeleteMessageTags({
221+
required String channelId,
222+
required String eventId,
223+
}) {
224+
return [
225+
['h', channelId],
226+
['e', eventId],
227+
];
228+
}
229+
217230
class ChannelActions {
218231
final Ref _ref;
219232
final RelaySessionNotifier _session;
@@ -438,13 +451,14 @@ class ChannelActions {
438451
);
439452
}
440453

441-
Future<void> deleteMessage(String eventId) async {
454+
Future<void> deleteMessage({
455+
required String channelId,
456+
required String eventId,
457+
}) async {
442458
await _signedEventRelay.submit(
443459
kind: EventKind.deletion,
444460
content: '',
445-
tags: [
446-
['e', eventId],
447-
],
461+
tags: buildDeleteMessageTags(channelId: channelId, eventId: eventId),
448462
);
449463
}
450464

mobile/lib/features/channels/message_actions.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void showMessageActions({
160160
_confirmDelete(
161161
context: context,
162162
ref: ref,
163+
channelId: channelId,
163164
messageId: message.id,
164165
);
165166
},
@@ -242,6 +243,7 @@ void _showEditSheet({
242243
void _confirmDelete({
243244
required BuildContext context,
244245
required WidgetRef ref,
246+
required String channelId,
245247
required String messageId,
246248
}) {
247249
showDialog<void>(
@@ -257,7 +259,10 @@ void _confirmDelete({
257259
FilledButton(
258260
onPressed: () {
259261
Navigator.of(dialogContext).pop();
260-
ref.read(channelActionsProvider).deleteMessage(messageId);
262+
ref.read(channelActionsProvider).deleteMessage(
263+
channelId: channelId,
264+
eventId: messageId,
265+
);
261266
},
262267
style: FilledButton.styleFrom(
263268
backgroundColor: Theme.of(dialogContext).colorScheme.error,

mobile/lib/features/forum/forum_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Future<void> deleteForumEvent(
132132
String? rootEventId,
133133
}) async {
134134
final actions = ref.read(channelActionsProvider);
135-
await actions.deleteMessage(eventId);
135+
await actions.deleteMessage(channelId: channelId, eventId: eventId);
136136
ref.invalidate(forumPostsProvider(channelId));
137137
if (rootEventId != null) {
138138
ref.invalidate(

mobile/test/features/channels/channel_management_provider_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,18 @@ void main() {
8484
expect(details.ttlDeadline, isNotNull);
8585
expect(details.ttlDeadline!.isUtc, isTrue);
8686
});
87+
88+
group('buildDeleteMessageTags', () {
89+
test('emits both channel h tag and target e tag', () {
90+
final tags = buildDeleteMessageTags(
91+
channelId: 'c8c629ae-d35c-44fa-bc39-f6c1816756cc',
92+
eventId: 'abc123',
93+
);
94+
95+
expect(tags, [
96+
['h', 'c8c629ae-d35c-44fa-bc39-f6c1816756cc'],
97+
['e', 'abc123'],
98+
]);
99+
});
100+
});
87101
}

0 commit comments

Comments
 (0)