Skip to content

Commit 621869d

Browse files
committed
api: Add DmMessage.allRecipientIds, to avoid displayRecipients
1 parent 4281e2a commit 621869d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/api/model/model.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,29 @@ class DmMessage extends Message {
393393
String get type => 'private';
394394

395395
/// The `display_recipient` from the server, sorted by user ID numerically.
396+
///
397+
/// This lists the sender as well as all (other) recipients, and it
398+
/// lists each user just once. In particular the self-user is always
399+
/// included.
400+
///
401+
/// Note the data here is not updated on changes to the users, so everything
402+
/// other than the user IDs may be stale.
403+
/// Consider using [allRecipientIds] instead, and getting user details
404+
/// from the store.
405+
// TODO(server): Document that it's all users. That statement is based on
406+
// reverse-engineering notes in zulip-mobile:src/api/modelTypes.js at PmMessage.
396407
@DmRecipientListConverter()
397408
final List<DmRecipient> displayRecipient;
398409

410+
/// The user IDs of all users in the thread, sorted numerically.
411+
///
412+
/// This lists the sender as well as all (other) recipients, and it
413+
/// lists each user just once. In particular the self-user is always
414+
/// included.
415+
///
416+
/// This is a result of [List.map], so it has an efficient `length`.
417+
Iterable<int> get allRecipientIds => displayRecipient.map((e) => e.id);
418+
399419
DmMessage({
400420
super.avatarUrl,
401421
required super.client,

test/api/model/model_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,22 @@ void main() {
9090
check(parse(withRecipients([user11, user2, user3])).displayRecipient)
9191
.deepEquals(asRecipients([user2, user3, user11]));
9292
});
93+
94+
test('allRecipientIds', () {
95+
check(parse(withRecipients([user2])).allRecipientIds)
96+
.deepEquals([2]);
97+
98+
check(parse(withRecipients([user2, user3])).allRecipientIds)
99+
.deepEquals([2, 3]);
100+
check(parse(withRecipients([user3, user2])).allRecipientIds)
101+
.deepEquals([2, 3]);
102+
103+
check(parse(withRecipients([user2, user3, user11])).allRecipientIds)
104+
.deepEquals([2, 3, 11]);
105+
check(parse(withRecipients([user3, user11, user2])).allRecipientIds)
106+
.deepEquals([2, 3, 11]);
107+
check(parse(withRecipients([user11, user2, user3])).allRecipientIds)
108+
.deepEquals([2, 3, 11]);
109+
});
93110
});
94111
}

0 commit comments

Comments
 (0)