Skip to content

Commit 3de7ff9

Browse files
committed
api: Add prevContentSha256 param to updateMessage route
1 parent 93e84ad commit 3de7ff9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/api/route/messages.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ class SendMessageResult {
267267
}
268268

269269
/// https://zulip.com/api/update-message
270+
///
271+
/// `prev_content_sha256` is sent if the feature level is >= 379,
272+
/// otherwise ignored.
270273
Future<UpdateMessageResult> updateMessage(
271274
ApiConnection connection, {
272275
required int messageId,
@@ -276,6 +279,7 @@ Future<UpdateMessageResult> updateMessage(
276279
bool? sendNotificationToNewThread,
277280
String? content,
278281
int? streamId,
282+
String? prevContentSha256,
279283
}) {
280284
return connection.patch('updateMessage', UpdateMessageResult.fromJson, 'messages/$messageId', {
281285
if (topic != null) 'topic': RawParameter(topic.apiName),
@@ -284,6 +288,8 @@ Future<UpdateMessageResult> updateMessage(
284288
if (sendNotificationToNewThread != null) 'send_notification_to_new_thread': sendNotificationToNewThread,
285289
if (content != null) 'content': RawParameter(content),
286290
if (streamId != null) 'stream_id': streamId,
291+
// TODO(server-11) remove FL condition and its mention in the dartdoc
292+
if (prevContentSha256 != null && connection.zulipFeatureLevel! >= 379) 'prev_content_sha256': RawParameter(prevContentSha256),
287293
});
288294
}
289295

test/api/route/messages_test.dart

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ void main() {
455455
bool? sendNotificationToNewThread,
456456
String? content,
457457
int? streamId,
458+
String? prevContentSha256,
458459
required Map<String, String> expected,
459460
}) async {
460461
final result = await updateMessage(connection,
@@ -465,14 +466,43 @@ void main() {
465466
sendNotificationToNewThread: sendNotificationToNewThread,
466467
content: content,
467468
streamId: streamId,
469+
prevContentSha256: prevContentSha256,
468470
);
469471
check(connection.lastRequest).isA<http.Request>()
470472
..method.equals('PATCH')
471473
..url.path.equals('/api/v1/messages/$messageId')
472-
..bodyFields.deepEquals(expected);
474+
..bodyFields.deepEquals(expected)
475+
..bodyFields.length.equals(expected.length);
473476
return result;
474477
}
475478

479+
test('pure content change', () {
480+
return FakeApiConnection.with_((connection) async {
481+
connection.prepare(json: UpdateMessageResult().toJson());
482+
await checkUpdateMessage(connection,
483+
messageId: eg.streamMessage().id,
484+
content: 'asdf',
485+
prevContentSha256: '34a780ad578b997db55b260beb60b501f3e04d30ba1a51fcf43cd8dd1241780d',
486+
expected: {
487+
'content': 'asdf',
488+
'prev_content_sha256': '34a780ad578b997db55b260beb60b501f3e04d30ba1a51fcf43cd8dd1241780d',
489+
});
490+
});
491+
});
492+
493+
test('pure content change (legacy, before prev_content_sha256)', () {
494+
return FakeApiConnection.with_(zulipFeatureLevel: 378, (connection) async {
495+
connection.prepare(json: UpdateMessageResult().toJson());
496+
await checkUpdateMessage(connection,
497+
messageId: eg.streamMessage().id,
498+
content: 'asdf',
499+
prevContentSha256: '34a780ad578b997db55b260beb60b501f3e04d30ba1a51fcf43cd8dd1241780d',
500+
expected: {
501+
'content': 'asdf',
502+
});
503+
});
504+
});
505+
476506
test('topic/content change', () {
477507
// A separate test exercises `streamId`;
478508
// the API doesn't allow changing channel and content at the same time.

0 commit comments

Comments
 (0)