Skip to content

Commit 8b8a168

Browse files
browclaude
andcommitted
mobile: share and test the page typing selector
Channel and thread pages now watch one visibleTypingProvider, and a test checks that the user's own echoed indicator does not notify it while another user's typing does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent 5ff7541 commit 8b8a168

4 files changed

Lines changed: 63 additions & 12 deletions

File tree

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,10 @@ class _ResolvedChannelDetailPage extends HookConsumerWidget {
366366
// Ordinary channels keep thread activity inside the thread view.
367367
final typingEntries = ref
368368
.watch(
369-
channelTypingProvider(channel.id).select(
370-
(all) => VisibleTyping(
371-
all,
372-
selfPubkey: currentPubkey,
373-
include: (e) => personalChat || e.threadHeadId == null,
374-
),
369+
visibleTypingProvider(
370+
channel.id,
371+
selfPubkey: currentPubkey,
372+
include: (e) => personalChat || e.threadHeadId == null,
375373
),
376374
)
377375
.entries;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:flutter/foundation.dart';
44
import 'package:hooks_riverpod/hooks_riverpod.dart';
5+
import 'package:hooks_riverpod/misc.dart' show ProviderListenable;
56

67
import '../../shared/relay/relay.dart';
78

@@ -56,6 +57,17 @@ class VisibleTyping {
5657
int get hashCode => Object.hashAll(entries);
5758
}
5859

60+
/// What a page watches to show typing in [channelId]: everyone but
61+
/// [selfPubkey], filtered by [include]. The user's own echoed indicator
62+
/// refreshes its expiry every few seconds, and this skips those updates.
63+
ProviderListenable<VisibleTyping> visibleTypingProvider(
64+
String channelId, {
65+
required String? selfPubkey,
66+
required bool Function(TypingEntry entry) include,
67+
}) => channelTypingProvider(
68+
channelId,
69+
).select((all) => VisibleTyping(all, selfPubkey: selfPubkey, include: include));
70+
5971
/// Tracks who is currently typing in a specific channel.
6072
///
6173
/// Subscribes to typing and message events so a reply ends its typing signal.

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,10 @@ class ThreadDetailPage extends HookConsumerWidget {
786786
// Thread-scoped typing indicators (exclude self).
787787
final threadTyping = ref
788788
.watch(
789-
channelTypingProvider(channelId).select(
790-
(all) => VisibleTyping(
791-
all,
792-
selfPubkey: currentPubkey,
793-
include: (e) => e.threadHeadId == threadHead.id,
794-
),
789+
visibleTypingProvider(
790+
channelId,
791+
selfPubkey: currentPubkey,
792+
include: (e) => e.threadHeadId == threadHead.id,
795793
),
796794
)
797795
.entries;

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,47 @@ void main() {
247247
container.dispose();
248248
}),
249249
);
250+
test(
251+
'pages ignore the user\'s own typing echo but see others',
252+
() => fakeAsync((async) {
253+
final relay = _Relay();
254+
final container = ProviderContainer(
255+
overrides: [relaySessionProvider.overrideWith(() => relay)],
256+
);
257+
final seen = <List<String>>[];
258+
container.listen(
259+
visibleTypingProvider(
260+
'chat',
261+
selfPubkey: 'ME',
262+
include: (e) => e.threadHeadId == null,
263+
),
264+
(_, next) => seen.add([for (final e in next.entries) e.pubkey]),
265+
);
266+
_settle(container, async);
267+
void typing(String id, String pubkey) => relay.receive(
268+
NostrEvent(
269+
id: id,
270+
pubkey: pubkey,
271+
kind: 20002,
272+
createdAt: DateTime.now().millisecondsSinceEpoch ~/ 1000,
273+
content: '',
274+
sig: '',
275+
tags: [
276+
['h', 'chat'],
277+
],
278+
),
279+
);
280+
for (var i = 0; i < 3; i++) {
281+
typing('self-$i', 'me');
282+
async.elapse(const Duration(seconds: 3));
283+
}
284+
expect(container.read(channelTypingProvider('chat')), hasLength(1));
285+
expect(seen, isEmpty);
286+
typing('other', 'agent');
287+
expect(seen, [
288+
['agent'],
289+
]);
290+
container.dispose();
291+
}),
292+
);
250293
}

0 commit comments

Comments
 (0)