Skip to content

Commit 0354b8a

Browse files
committed
model: Add DmNarrow.withUser helper
1 parent 2d02299 commit 0354b8a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/model/narrow.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ class DmNarrow extends Narrow implements SendableNarrow {
161161
);
162162
}
163163

164+
factory DmNarrow.withUser(int userId, {required int selfUserId}) {
165+
return DmNarrow(
166+
allRecipientIds: {userId, selfUserId}.toList()..sort(),
167+
selfUserId: selfUserId,
168+
);
169+
}
170+
164171
/// The user IDs of everyone in the conversation, sorted.
165172
///
166173
/// Each message in the conversation is sent by one of these users

test/model/narrow_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ void main() {
6969
selfUserId: eg.selfUser.userId));
7070
});
7171

72+
test('ofUser: same user', () {
73+
final actual = DmNarrow.withUser(5, selfUserId: 5);
74+
check(actual).equals(DmNarrow(
75+
allRecipientIds: [5],
76+
selfUserId: 5));
77+
});
78+
79+
test('ofUser: user less than selfUserId', () {
80+
final actual = DmNarrow.withUser(3, selfUserId: 5);
81+
check(actual).equals(DmNarrow(
82+
allRecipientIds: [3, 5],
83+
selfUserId: 5));
84+
});
85+
86+
test('ofUser: user greater than selfUserId', () {
87+
final actual = DmNarrow.withUser(7, selfUserId: 5);
88+
check(actual).equals(DmNarrow(
89+
allRecipientIds: [5, 7],
90+
selfUserId: 5));
91+
});
92+
7293
test('otherRecipientIds', () {
7394
check(DmNarrow(allRecipientIds: [1, 2, 3], selfUserId: 2))
7495
.otherRecipientIds.deepEquals([1, 3]);

0 commit comments

Comments
 (0)