mirror of
https://github.com/block/buzz.git
synced 2026-11-30 05:02:57 +00:00
fix(mobile): skip the Huddle record read when one person remains (#9547)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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'},
|
||||
|
||||
Reference in New Issue
Block a user