Skip to content

Commit 15f57e1

Browse files
committed
narrow: Add DmNarrow.withUsers
1 parent 21e5082 commit 15f57e1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/model/narrow.dart

+7
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ class DmNarrow extends Narrow implements SendableNarrow {
168168
);
169169
}
170170

171+
factory DmNarrow.withUsers(List<int> userIds, {required int selfUserId}) {
172+
return DmNarrow(
173+
allRecipientIds: {...userIds, selfUserId}.toList()..sort(),
174+
selfUserId: selfUserId,
175+
);
176+
}
177+
171178
/// The user IDs of everyone in the conversation, sorted.
172179
///
173180
/// Each message in the conversation is sent by one of these users

test/model/narrow_test.dart

+14
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ void main() {
9090
selfUserId: 5));
9191
});
9292

93+
test('withUsers: without selfUserId', () {
94+
final actual = DmNarrow.withUsers([1, 2], selfUserId: 3);
95+
check(actual).equals(DmNarrow(
96+
allRecipientIds: [1, 2, 3],
97+
selfUserId: 3));
98+
});
99+
100+
test('withUsers: with selfUserId', () {
101+
final actual = DmNarrow.withUsers([1, 2, 3], selfUserId: 3);
102+
check(actual).equals(DmNarrow(
103+
allRecipientIds: [1, 2, 3],
104+
selfUserId: 3));
105+
});
106+
93107
test('otherRecipientIds', () {
94108
check(DmNarrow(allRecipientIds: [1, 2, 3], selfUserId: 2))
95109
.otherRecipientIds.deepEquals([1, 3]);

0 commit comments

Comments
 (0)