Skip to content

Commit

Permalink
Add DmNarrow.withUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Sep 22, 2023
1 parent e8ac5e7 commit 3ce3ead
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/model/narrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ class DmNarrow extends Narrow implements SendableNarrow {
);
}

factory DmNarrow.withUsers(List<int> userIds, {required int selfUserId}) {
return DmNarrow(
allRecipientIds: {...userIds, selfUserId}.toList()..sort(),
selfUserId: selfUserId,
);
}

/// The user IDs of everyone in the conversation, sorted.
///
/// Each message in the conversation is sent by one of these users
Expand Down
14 changes: 14 additions & 0 deletions test/model/narrow_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 3ce3ead

Please sign in to comment.