Skip to content

Commit 4b6a10d

Browse files
committed
api [nfc]: Remove DmMessage.allRecipientIds, use DmMessage.destination
While this new form ends up a bit longer, it will make the later transition to MessageBase smoother.
1 parent f8ecf14 commit 4b6a10d

File tree

7 files changed

+26
-33
lines changed

7 files changed

+26
-33
lines changed

lib/api/model/model.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -857,17 +857,10 @@ class DmMessage extends Message<DmDestination> {
857857
@DmRecipientListConverter()
858858
final List<DmRecipient> displayRecipient;
859859

860-
/// The user IDs of all users in the thread, sorted numerically.
861-
///
862-
/// This lists the sender as well as all (other) recipients, and it
863-
/// lists each user just once. In particular the self-user is always
864-
/// included.
865-
///
866-
/// This is a result of [List.map], so it has an efficient `length`.
867-
Iterable<int> get allRecipientIds => displayRecipient.map((e) => e.id);
868-
869860
@override
870-
DmDestination get destination => DmDestination(userIds: allRecipientIds);
861+
DmDestination get destination => DmDestination(
862+
// This is a result of [List.map], so it has an efficient `length`.
863+
userIds: displayRecipient.map((e) => e.id));
871864

872865
DmMessage({
873866
required super.client,

lib/model/message_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ bool haveSameRecipient(Message prevMessage, Message message) {
354354
if (prevMessage.streamId != message.streamId) return false;
355355
if (prevMessage.topic.canonicalize() != message.topic.canonicalize()) return false;
356356
} else if (prevMessage is DmMessage && message is DmMessage) {
357-
if (!_equalIdSequences(prevMessage.allRecipientIds, message.allRecipientIds)) {
357+
if (!_equalIdSequences(prevMessage.destination.userIds, message.destination.userIds)) {
358358
return false;
359359
}
360360
} else {

lib/model/narrow.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class DmNarrow extends Narrow implements SendableNarrow {
196196

197197
factory DmNarrow.ofMessage(DmMessage message, {required int selfUserId}) {
198198
return DmNarrow(
199-
allRecipientIds: List.unmodifiable(message.allRecipientIds),
199+
allRecipientIds: List.unmodifiable(message.destination.userIds),
200200
selfUserId: selfUserId,
201201
);
202202
}
@@ -262,9 +262,9 @@ class DmNarrow extends Narrow implements SendableNarrow {
262262
@override
263263
bool containsMessage(Message message) {
264264
if (message is! DmMessage) return false;
265-
if (message.allRecipientIds.length != allRecipientIds.length) return false;
265+
if (message.destination.userIds.length != allRecipientIds.length) return false;
266266
int i = 0;
267-
for (final userId in message.allRecipientIds) {
267+
for (final userId in message.destination.userIds) {
268268
if (userId != allRecipientIds[i]) return false;
269269
i++;
270270
}

lib/widgets/message_list.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,8 +1176,8 @@ class DmRecipientHeader extends StatelessWidget {
11761176
final zulipLocalizations = ZulipLocalizations.of(context);
11771177
final store = PerAccountStoreWidget.of(context);
11781178
final String title;
1179-
if (message.allRecipientIds.length > 1) {
1180-
title = zulipLocalizations.messageListGroupYouAndOthers(message.allRecipientIds
1179+
if (message.destination.userIds.length > 1) {
1180+
title = zulipLocalizations.messageListGroupYouAndOthers(message.destination.userIds
11811181
.where((id) => id != store.selfUserId)
11821182
.map(store.userDisplayName)
11831183
.sorted()

test/api/model/model_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,19 @@ void main() {
209209
});
210210

211211
test('allRecipientIds', () {
212-
check(parse(withRecipients([user2])).allRecipientIds)
212+
check(parse(withRecipients([user2])).destination.userIds)
213213
.deepEquals([2]);
214214

215-
check(parse(withRecipients([user2, user3])).allRecipientIds)
215+
check(parse(withRecipients([user2, user3])).destination.userIds)
216216
.deepEquals([2, 3]);
217-
check(parse(withRecipients([user3, user2])).allRecipientIds)
217+
check(parse(withRecipients([user3, user2])).destination.userIds)
218218
.deepEquals([2, 3]);
219219

220-
check(parse(withRecipients([user2, user3, user11])).allRecipientIds)
220+
check(parse(withRecipients([user2, user3, user11])).destination.userIds)
221221
.deepEquals([2, 3, 11]);
222-
check(parse(withRecipients([user3, user11, user2])).allRecipientIds)
222+
check(parse(withRecipients([user3, user11, user2])).destination.userIds)
223223
.deepEquals([2, 3, 11]);
224-
check(parse(withRecipients([user11, user2, user3])).allRecipientIds)
224+
check(parse(withRecipients([user11, user2, user3])).destination.userIds)
225225
.deepEquals([2, 3, 11]);
226226
});
227227
});

test/model/message_list_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ void main() {
18381838
final message0 = groups[i0][j0];
18391839
final message1 = groups[i1][j1];
18401840
check(
1841-
because: 'recipients ${message0.allRecipientIds} vs ${message1.allRecipientIds}',
1841+
because: 'recipients ${message0.destination.userIds} vs ${message1.destination.userIds}',
18421842
haveSameRecipient(message0, message1),
18431843
).equals(i0 == i1);
18441844
}

test/notifications/display_test.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ MessageFcmMessage messageFcmMessage(
6969
},
7070
DmNarrow(allRecipientIds: [_, _, _, ...]) => {
7171
"recipient_type": "private",
72-
"pm_users": narrow.allRecipientIds.join(","),
72+
"pm_users": narrow.destination.userIds.join(","),
7373
},
7474
DmNarrow() => {
7575
"recipient_type": "private",
@@ -625,7 +625,7 @@ void main() {
625625
await checkNotifications(async, messageFcmMessage(message),
626626
expectedIsGroupConversation: true,
627627
expectedTitle: "${eg.thirdUser.fullName} to you and 1 other",
628-
expectedTagComponent: 'dm:${message.allRecipientIds.join(",")}');
628+
expectedTagComponent: 'dm:${message.destination.userIds.join(",")}');
629629
})));
630630

631631
test('group DM: more than 3 users', () => runWithHttpClient(() => awaitFakeAsync((async) async {
@@ -635,7 +635,7 @@ void main() {
635635
await checkNotifications(async, messageFcmMessage(message),
636636
expectedIsGroupConversation: true,
637637
expectedTitle: "${eg.thirdUser.fullName} to you and 2 others",
638-
expectedTagComponent: 'dm:${message.allRecipientIds.join(",")}');
638+
expectedTagComponent: 'dm:${message.destination.userIds.join(",")}');
639639
})));
640640

641641
test('group DM: title updates with latest sender', () => runWithHttpClient(() => awaitFakeAsync((async) async {
@@ -645,7 +645,7 @@ void main() {
645645
final message2 = eg.dmMessage(from: eg.thirdUser, to: [eg.selfUser, eg.otherUser]);
646646
final data2 = messageFcmMessage(message2);
647647

648-
final expectedTagComponent = 'dm:${message1.allRecipientIds.join(",")}';
648+
final expectedTagComponent = 'dm:${message1.destination.userIds.join(",")}';
649649

650650
receiveFcmMessage(async, data1);
651651
checkNotification(data1,
@@ -668,7 +668,7 @@ void main() {
668668
await checkNotifications(async, messageFcmMessage(message),
669669
expectedIsGroupConversation: false,
670670
expectedTitle: eg.otherUser.fullName,
671-
expectedTagComponent: 'dm:${message.allRecipientIds.join(",")}');
671+
expectedTagComponent: 'dm:${message.destination.userIds.join(",")}');
672672
})));
673673

674674
test('1:1 DM: title updates when sender name changes', () => runWithHttpClient(() => awaitFakeAsync((async) async {
@@ -677,7 +677,7 @@ void main() {
677677
final message1 = eg.dmMessage(from: otherUser, to: [eg.selfUser]);
678678
final data1 = messageFcmMessage(message1);
679679

680-
final expectedTagComponent = 'dm:${message1.allRecipientIds.join(",")}';
680+
final expectedTagComponent = 'dm:${message1.destination.userIds.join(",")}';
681681

682682
receiveFcmMessage(async, data1);
683683
checkNotification(data1,
@@ -704,7 +704,7 @@ void main() {
704704
final message1 = eg.dmMessage(from: otherUser, to: [eg.selfUser]);
705705
final data1 = messageFcmMessage(message1);
706706

707-
final expectedTagComponent = 'dm:${message1.allRecipientIds.join(",")}';
707+
final expectedTagComponent = 'dm:${message1.destination.userIds.join(",")}';
708708

709709
receiveFcmMessage(async, data1);
710710
checkNotification(data1,
@@ -735,7 +735,7 @@ void main() {
735735
messageStyleMessages: [data],
736736
expectedIsGroupConversation: false,
737737
expectedTitle: eg.otherUser.fullName,
738-
expectedTagComponent: 'dm:${message.allRecipientIds.join(",")}',
738+
expectedTagComponent: 'dm:${message.destination.userIds.join(",")}',
739739
expectedIconBitmap: null); // Failed to fetch avatar photo
740740
}),
741741
httpClientFactory: () => makeFakeHttpClient(
@@ -751,7 +751,7 @@ void main() {
751751
messageStyleMessages: [data],
752752
expectedIsGroupConversation: false,
753753
expectedTitle: eg.otherUser.fullName,
754-
expectedTagComponent: 'dm:${message.allRecipientIds.join(",")}',
754+
expectedTagComponent: 'dm:${message.destination.userIds.join(",")}',
755755
expectedIconBitmap: null); // Failed to fetch avatar photo
756756
}),
757757
httpClientFactory: () => makeFakeHttpClient(
@@ -763,7 +763,7 @@ void main() {
763763
await checkNotifications(async, messageFcmMessage(message),
764764
expectedIsGroupConversation: false,
765765
expectedTitle: eg.selfUser.fullName,
766-
expectedTagComponent: 'dm:${message.allRecipientIds.join(",")}');
766+
expectedTagComponent: 'dm:${message.destination.userIds.join(",")}');
767767
})));
768768

769769
test('remove: smoke', () => runWithHttpClient(() => awaitFakeAsync((async) async {

0 commit comments

Comments
 (0)