diff --git a/lib/model/narrow.dart b/lib/model/narrow.dart index c71cfe5407..9532b27eb4 100644 --- a/lib/model/narrow.dart +++ b/lib/model/narrow.dart @@ -155,15 +155,22 @@ class DmNarrow extends Narrow implements SendableNarrow { /// A [DmNarrow] from an item in [InitialSnapshot.recentPrivateConversations]. factory DmNarrow.ofRecentDmConversation(RecentDmConversation conversation, {required int selfUserId}) { - return DmNarrow( - allRecipientIds: [...conversation.userIds, selfUserId]..sort(), + return DmNarrow.withUsers( + conversation.userIds, selfUserId: selfUserId, ); } factory DmNarrow.withUser(int userId, {required int selfUserId}) { + return DmNarrow.withUsers( + [userId], + selfUserId: selfUserId, + ); + } + + factory DmNarrow.withUsers(List userIds, {required int selfUserId}) { return DmNarrow( - allRecipientIds: {userId, selfUserId}.toList()..sort(), + allRecipientIds: {...userIds, selfUserId}.toList()..sort(), selfUserId: selfUserId, ); } diff --git a/test/model/narrow_test.dart b/test/model/narrow_test.dart index c7825c6766..10fb8e8efa 100644 --- a/test/model/narrow_test.dart +++ b/test/model/narrow_test.dart @@ -90,6 +90,20 @@ void main() { selfUserId: 5)); }); + test('withUsers: without selfUserId', () { + final actual = DmNarrow.withUsers([1, 2], selfUserId: 3); + check(actual).equals(DmNarrow( + allRecipientIds: [1, 2, 3], + selfUserId: 3)); + }); + + test('withUsers: with selfUserId', () { + final actual = DmNarrow.withUsers([1, 2, 3], selfUserId: 3); + check(actual).equals(DmNarrow( + allRecipientIds: [1, 2, 3], + selfUserId: 3)); + }); + test('otherRecipientIds', () { check(DmNarrow(allRecipientIds: [1, 2, 3], selfUserId: 2)) .otherRecipientIds.deepEquals([1, 3]);