Skip to content

Commit 4be6e68

Browse files
committed
api: Send local_(message)_id as a raw String; add it to MessageEvent
The server documents this to be an optional String (https://zulip.com/api/send-message#parameter-local_id), match that that in our bindings. We will determine how this is encoded, but not at the bindings level. This will be used for local echoing. local_message_id on message event is not yet fully documented; see CZO discussion: https://chat.zulip.org/#narrow/channel/412-api-documentation/topic/local_id.2C.20queue_id.2Fsender_queue_id/near/2135340
1 parent 02f7cb9 commit 4be6e68

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

lib/api/model/events.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,16 @@ class MessageEvent extends Event {
682682
@JsonKey(readValue: _readMessageValue, includeToJson: false)
683683
final Message message;
684684

685-
MessageEvent({required super.id, required this.message});
685+
// The format of this is documented to be chosen freely by the client.
686+
//
687+
// When present, this corresponds to the JSON-encoded int, "local_id",
688+
// from a previous [sendMessage] call by us.
689+
//
690+
// This is not yet fully documented. See CZO discussion for reference:
691+
// https://chat.zulip.org/#narrow/channel/412-api-documentation/topic/local_id.2C.20queue_id.2Fsender_queue_id/near/2135340
692+
final String? localMessageId;
693+
694+
MessageEvent({required super.id, required this.message, required this.localMessageId});
686695

687696
static Map<String, dynamic> _readMessageValue(Map<dynamic, dynamic> json, String key) =>
688697
{...json['message'] as Map<String, dynamic>, 'flags': json['flags']};

lib/api/model/events.g.dart

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api/route/messages.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Future<SendMessageResult> sendMessage(
194194
}}),
195195
'content': RawParameter(content),
196196
if (queueId != null) 'queue_id': RawParameter(queueId),
197-
if (localId != null) 'local_id': localId, // TODO should this use RawParameter?
197+
if (localId != null) 'local_id': RawParameter(localId),
198198
if (readBySender != null) 'read_by_sender': readBySender,
199199
},
200200
overrideUserAgent: switch ((supportsReadBySender, readBySender)) {

test/api/model/events_checks.dart

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extension SubscriptionUpdateEventChecks on Subject<SubscriptionUpdateEvent> {
3939

4040
extension MessageEventChecks on Subject<MessageEvent> {
4141
Subject<Message> get message => has((e) => e.message, 'message');
42+
Subject<String?> get localMessageId => has((e) => e.localMessageId, 'localMessageId');
4243
}
4344

4445
extension UpdateMessageEventChecks on Subject<UpdateMessageEvent> {

test/api/route/messages_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void main() {
363363
'topic': topic,
364364
'content': content,
365365
'queue_id': 'abc:123',
366-
'local_id': '"456"',
366+
'local_id': '456',
367367
'read_by_sender': 'true',
368368
});
369369
});

test/example_data.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ UserTopicEvent userTopicEvent(
621621
}
622622

623623
MessageEvent messageEvent(Message message) =>
624-
MessageEvent(id: 0, message: message);
624+
MessageEvent(id: 0, message: message, localMessageId: null);
625625

626626
DeleteMessageEvent deleteMessageEvent(List<StreamMessage> messages) {
627627
assert(messages.isNotEmpty);

0 commit comments

Comments
 (0)