Skip to content

Commit 0ad6fb3

Browse files
committed
api: Add prevContentSha256 param to updateMessage route
1 parent f1c0e0f commit 0ad6fb3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/api/route/messages.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ Future<UpdateMessageResult> updateMessage(
275275
bool? sendNotificationToOldThread,
276276
bool? sendNotificationToNewThread,
277277
String? content,
278+
String? prevContentSha256,
278279
int? streamId,
279280
}) {
280281
return connection.patch('updateMessage', UpdateMessageResult.fromJson, 'messages/$messageId', {
@@ -283,6 +284,7 @@ Future<UpdateMessageResult> updateMessage(
283284
if (sendNotificationToOldThread != null) 'send_notification_to_old_thread': sendNotificationToOldThread,
284285
if (sendNotificationToNewThread != null) 'send_notification_to_new_thread': sendNotificationToNewThread,
285286
if (content != null) 'content': RawParameter(content),
287+
if (prevContentSha256 != null) 'prev_content_sha256': RawParameter(prevContentSha256),
286288
if (streamId != null) 'stream_id': streamId,
287289
});
288290
}

test/api/route/messages_test.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ void main() {
454454
bool? sendNotificationToOldThread,
455455
bool? sendNotificationToNewThread,
456456
String? content,
457+
String? prevContentSha256,
457458
int? streamId,
458459
required Map<String, String> expected,
459460
}) async {
@@ -464,15 +465,31 @@ void main() {
464465
sendNotificationToOldThread: sendNotificationToOldThread,
465466
sendNotificationToNewThread: sendNotificationToNewThread,
466467
content: content,
468+
prevContentSha256: prevContentSha256,
467469
streamId: streamId,
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+
476493
test('topic/content change', () {
477494
// A separate test exercises `streamId`;
478495
// the API doesn't allow changing channel and content at the same time.

0 commit comments

Comments
 (0)