Skip to content

Commit e60f65f

Browse files
committed
api [nfc]: Apply constraints from DmMessage.allRecipientIds on DmDestination
This does not change the runtime behavior of this class in production. Later we will replace DmMessage.allRecipientIds with DmMessage.destination.userIds.
1 parent 8a7b259 commit e60f65f

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

lib/api/route/messages.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:json_annotation/json_annotation.dart';
22

3+
import '../../model/algorithms.dart';
34
import '../core.dart';
45
import '../exception.dart';
56
import '../model/model.dart';
@@ -247,9 +248,17 @@ class StreamDestination extends MessageDestination {
247248
/// The server accepts a list of Zulip API emails as an alternative to
248249
/// a list of user IDs, but this binding currently doesn't.
249250
class DmDestination extends MessageDestination {
250-
const DmDestination({required this.userIds});
251-
252-
final List<int> userIds;
251+
DmDestination({required this.userIds})
252+
: assert(isSortedWithoutDuplicates(userIds.toList()));
253+
254+
/// The user IDs of all users in the thread, sorted numerically.
255+
///
256+
/// This lists the sender as well as all (other) recipients, and it
257+
/// lists each user just once. In particular the self-user is always
258+
/// included.
259+
///
260+
/// This is required to have an efficient `length`.
261+
final Iterable<int> userIds;
253262
}
254263

255264
@JsonSerializable(fieldRename: FieldRename.snake)

test/api/route/messages_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ void main() {
387387
test('to DM conversation', () {
388388
return FakeApiConnection.with_((connection) async {
389389
await checkSendMessage(connection,
390-
destination: const DmDestination(userIds: userIds), content: content,
390+
destination: DmDestination(userIds: userIds), content: content,
391391
readBySender: true,
392392
expectedBodyFields: {
393393
'type': 'direct',
@@ -401,7 +401,7 @@ void main() {
401401
test('to DM conversation, with legacy type "private"', () {
402402
return FakeApiConnection.with_(zulipFeatureLevel: 173, (connection) async {
403403
await checkSendMessage(connection,
404-
destination: const DmDestination(userIds: userIds), content: content,
404+
destination: DmDestination(userIds: userIds), content: content,
405405
readBySender: true,
406406
expectedBodyFields: {
407407
'type': 'private',

test/api/route/typing_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void main() {
5353
test('send typing status start for dm', () {
5454
return FakeApiConnection.with_((connection) {
5555
return checkSetTypingStatus(connection, TypingOp.start,
56-
destination: const DmDestination(userIds: userIds),
56+
destination: DmDestination(userIds: userIds),
5757
expectedBodyFields: {
5858
'op': 'start',
5959
'type': 'direct',
@@ -91,7 +91,7 @@ void main() {
9191
test('legacy: use "private" instead of "direct"', () {
9292
return FakeApiConnection.with_(zulipFeatureLevel: 173, (connection) {
9393
return checkSetTypingStatus(connection, TypingOp.start,
94-
destination: const DmDestination(userIds: userIds),
94+
destination: DmDestination(userIds: userIds),
9595
expectedBodyFields: {
9696
'op': 'start',
9797
'type': 'private',

0 commit comments

Comments
 (0)