fix(mobile): skip the Huddle record read when one person remains (#9547)

This commit is contained in:
Tom Brow
2026-11-15 15:17:02 -08:00
committed by GitHub
parent 54fb76debe
commit 706a6052f1
2 changed files with 19 additions and 0 deletions

View File

@@ -67,6 +67,12 @@ final huddleHumanCountProvider = Provider<HuddleHumanCountLoader>((ref) {
}
if (events.isEmpty) return 0;
final members = membersFromEvent(events.first);
final nonBotCount = members.where((member) => member.role != 'bot').length;
// A managed-agent record can only lower this count. With at most one
// non-bot member the answer is final, so skip the record read: a slow or
// failed read must not keep a bot-only Huddle open after its last person
// leaves, as it did before records were consulted.
if (nonBotCount <= 1) return nonBotCount;
// An agent without NIP-OA has role `member`. A failed record read throws,
// so leave keeps the Huddle open rather than count an agent as a person.
final recordAgents = await fetchTrustedManagedAgentPubkeys(

View File

@@ -173,6 +173,19 @@ void main() {
expect(await container.read(huddleHumanCountProvider)(_channelId), 3);
});
test('last-human count skips the record read for a lone person', () async {
final relay = _HuddleRelaySession(
members: {_owner.public: 'owner', _botAgent: 'bot'},
recordError: Exception('relay timeout'),
);
final container = _container(relay);
// Records can only lower the count, so a failed read must not keep a
// bot-only Huddle open after its last person leaves.
expect(await container.read(huddleHumanCountProvider)(_channelId), 1);
expect(relay.recordFilters, isEmpty);
});
test('last-human count fails when the records cannot be read', () async {
final relay = _HuddleRelaySession(
members: {_owner.public: 'owner', _ownerAgent: 'member'},