Skip to content

Commit fd54070

Browse files
committed
api: In sendMessage, use "direct" where possible
Part of #146.
1 parent e3a3496 commit fd54070

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/api/route/messages.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ Future<SendMessageResult> sendMessage(
9999
String? queueId,
100100
String? localId,
101101
}) {
102+
final supportsTypeDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7)
102103
return connection.post('sendMessage', SendMessageResult.fromJson, 'messages', {
103104
if (destination is StreamDestination) ...{
104105
'type': RawParameter('stream'),
105106
'to': destination.streamId,
106107
'topic': RawParameter(destination.topic),
107108
} else if (destination is DmDestination) ...{
108-
'type': RawParameter('private'), // TODO(#146): use 'direct' where possible
109+
'type': supportsTypeDirect ? RawParameter('direct') : RawParameter('private'),
109110
'to': destination.userIds,
110111
} else ...(
111112
throw Exception('impossible destination') // TODO(dart-3) show this statically

test/api/route/messages_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ void main() {
147147

148148
test('to DM conversation', () {
149149
return FakeApiConnection.with_((connection) async {
150+
await checkSendMessage(connection,
151+
destination: DmDestination(userIds: userIds), content: content,
152+
expectedBodyFields: {
153+
'type': 'direct',
154+
'to': jsonEncode(userIds),
155+
'content': content,
156+
});
157+
});
158+
});
159+
160+
test('to DM conversation, with legacy type "private"', () {
161+
return FakeApiConnection.with_(zulipFeatureLevel: 173, (connection) async {
150162
await checkSendMessage(connection,
151163
destination: DmDestination(userIds: userIds), content: content,
152164
expectedBodyFields: {

0 commit comments

Comments
 (0)