Skip to content

Commit d76183c

Browse files
committed
api [nfc]: Support const constructor for MessageDestination.
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 4f678b0 commit d76183c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/api/route/messages.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,16 @@ Future<SendMessageResult> sendMessage(
219219
/// Which conversation to send a message to, in [sendMessage].
220220
///
221221
/// This is either a [StreamDestination] or a [DmDestination].
222-
sealed class MessageDestination {}
222+
sealed class MessageDestination {
223+
const MessageDestination();
224+
}
223225

224226
/// A conversation in a stream, for specifying to [sendMessage].
225227
///
226228
/// The server accepts a stream name as an alternative to a stream ID,
227229
/// but this binding currently doesn't.
228230
class StreamDestination extends MessageDestination {
229-
StreamDestination(this.streamId, this.topic);
231+
const StreamDestination(this.streamId, this.topic);
230232

231233
final int streamId;
232234
final String topic;
@@ -237,7 +239,7 @@ class StreamDestination extends MessageDestination {
237239
/// The server accepts a list of Zulip API emails as an alternative to
238240
/// a list of user IDs, but this binding currently doesn't.
239241
class DmDestination extends MessageDestination {
240-
DmDestination({required this.userIds});
242+
const DmDestination({required this.userIds});
241243

242244
final List<int> userIds;
243245
}

test/api/route/messages_test.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void main() {
325325
test('smoke', () {
326326
return FakeApiConnection.with_((connection) async {
327327
await checkSendMessage(connection,
328-
destination: StreamDestination(streamId, topic), content: content,
328+
destination: const StreamDestination(streamId, topic), content: content,
329329
queueId: 'abc:123',
330330
localId: '456',
331331
readBySender: true,
@@ -344,7 +344,7 @@ void main() {
344344
test('to stream', () {
345345
return FakeApiConnection.with_((connection) async {
346346
await checkSendMessage(connection,
347-
destination: StreamDestination(streamId, topic), content: content,
347+
destination: const StreamDestination(streamId, topic), content: content,
348348
readBySender: true,
349349
expectedBodyFields: {
350350
'type': 'stream',
@@ -359,7 +359,7 @@ void main() {
359359
test('to DM conversation', () {
360360
return FakeApiConnection.with_((connection) async {
361361
await checkSendMessage(connection,
362-
destination: DmDestination(userIds: userIds), content: content,
362+
destination: const DmDestination(userIds: userIds), content: content,
363363
readBySender: true,
364364
expectedBodyFields: {
365365
'type': 'direct',
@@ -373,7 +373,7 @@ void main() {
373373
test('to DM conversation, with legacy type "private"', () {
374374
return FakeApiConnection.with_(zulipFeatureLevel: 173, (connection) async {
375375
await checkSendMessage(connection,
376-
destination: DmDestination(userIds: userIds), content: content,
376+
destination: const DmDestination(userIds: userIds), content: content,
377377
readBySender: true,
378378
expectedBodyFields: {
379379
'type': 'private',
@@ -388,7 +388,7 @@ void main() {
388388
test('when readBySender is null, sends a User-Agent we know the server will recognize', () {
389389
return FakeApiConnection.with_((connection) async {
390390
await checkSendMessage(connection,
391-
destination: StreamDestination(streamId, topic), content: content,
391+
destination: const StreamDestination(streamId, topic), content: content,
392392
readBySender: null,
393393
expectedBodyFields: {
394394
'type': 'stream',
@@ -403,7 +403,7 @@ void main() {
403403
test('legacy: when server does not support readBySender, sends a User-Agent the server will recognize', () {
404404
return FakeApiConnection.with_(zulipFeatureLevel: 235, (connection) async {
405405
await checkSendMessage(connection,
406-
destination: StreamDestination(streamId, topic), content: content,
406+
destination: const StreamDestination(streamId, topic), content: content,
407407
readBySender: true,
408408
expectedBodyFields: {
409409
'type': 'stream',

0 commit comments

Comments
 (0)