Skip to content

Commit 99b0370

Browse files
sm-sayedichrisbobbe
authored andcommitted
api: In sendMessage, use "channel" when supported
The modern type "channel" was added in server-9 (FL-248).
1 parent e5f429f commit 99b0370

5 files changed

Lines changed: 22 additions & 6 deletions

File tree

lib/api/route/messages.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,13 @@ Future<SendMessageResult> sendMessage(
134134
String? localId,
135135
bool? readBySender,
136136
}) {
137+
final supportsTypeChannel = connection.zulipFeatureLevel! >= 248; // TODO(server-9)
137138
final supportsTypeDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7)
138139
final supportsReadBySender = connection.zulipFeatureLevel! >= 236; // TODO(server-8)
139140
return connection.post('sendMessage', SendMessageResult.fromJson, 'messages', {
140141
...(switch (destination) {
141142
StreamDestination() => {
142-
'type': RawParameter('stream'),
143+
'type': supportsTypeChannel ? RawParameter('channel') : RawParameter('stream'),
143144
'to': destination.streamId,
144145
'topic': RawParameter(destination.topic.apiName),
145146
},

test/api/route/messages_test.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void main() {
286286
localId: '456',
287287
readBySender: true,
288288
expectedBodyFields: {
289-
'type': 'stream',
289+
'type': 'channel',
290290
'to': streamId.toString(),
291291
'topic': topic,
292292
'content': content,
@@ -299,6 +299,21 @@ void main() {
299299

300300
test('to stream', () {
301301
return FakeApiConnection.with_((connection) async {
302+
await checkSendMessage(connection,
303+
destination: StreamDestination(streamId, eg.t(topic)), content: content,
304+
readBySender: true,
305+
expectedBodyFields: {
306+
'type': 'channel',
307+
'to': streamId.toString(),
308+
'topic': topic,
309+
'content': content,
310+
'read_by_sender': 'true',
311+
});
312+
});
313+
});
314+
315+
test('to stream, with legacy type "stream"', () {
316+
return FakeApiConnection.with_(zulipFeatureLevel: 247, (connection) async {
302317
await checkSendMessage(connection,
303318
destination: StreamDestination(streamId, eg.t(topic)), content: content,
304319
readBySender: true,
@@ -347,7 +362,7 @@ void main() {
347362
destination: StreamDestination(streamId, eg.t(topic)), content: content,
348363
readBySender: null,
349364
expectedBodyFields: {
350-
'type': 'stream',
365+
'type': 'channel',
351366
'to': streamId.toString(),
352367
'topic': topic,
353368
'content': content,

test/model/message_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void main() {
159159
..method.equals('POST')
160160
..url.path.equals('/api/v1/messages')
161161
..bodyFields.deepEquals({
162-
'type': 'stream',
162+
'type': 'channel',
163163
'to': stream.streamId.toString(),
164164
'topic': 'world',
165165
'content': 'hello',

test/widgets/compose_box_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ void main() {
11161116
..method.equals('POST')
11171117
..url.path.equals('/api/v1/messages')
11181118
..bodyFields.deepEquals({
1119-
'type': 'stream',
1119+
'type': 'channel',
11201120
'to': '123',
11211121
'topic': 'some topic',
11221122
'content': 'hello world',

test/widgets/message_list_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ void main() {
17871787
..method.equals('POST')
17881788
..url.path.equals('/api/v1/messages')
17891789
..bodyFields.deepEquals({
1790-
'type': 'stream',
1790+
'type': 'channel',
17911791
'to': '${otherChannel.streamId}',
17921792
'topic': 'new topic',
17931793
'content': 'Some text',

0 commit comments

Comments
 (0)