-
Notifications
You must be signed in to change notification settings - Fork 306
local echo (1/n): Add API support for local_id/local_message_id and queue_id #1454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
450d476
1c077cc
e9eabdc
c982795
d224a5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -665,8 +665,7 @@ class UserTopicEvent extends Event { | |
} | ||
|
||
/// A Zulip event of type `message`: https://zulip.com/api/get-events#message | ||
// TODO use [JsonSerializable] here too, using its customization features, | ||
// in order to skip the boilerplate in [fromJson] and [toJson]. | ||
@JsonSerializable(fieldRename: FieldRename.snake) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commit-message nits:
needs period (commit-message bodies use complete sentences); and s/ddd/dd/ |
||
class MessageEvent extends Event { | ||
@override | ||
@JsonKey(includeToJson: true) | ||
|
@@ -680,24 +679,30 @@ class MessageEvent extends Event { | |
// events and in the get-messages results is that `matchContent` and | ||
// `matchTopic` are absent here. Already [Message.matchContent] and | ||
// [Message.matchTopic] are optional, so no action is needed on that. | ||
@JsonKey(readValue: _readMessageValue, includeToJson: false) | ||
final Message message; | ||
|
||
MessageEvent({required super.id, required this.message}); | ||
// When present, this equals the "local_id" parameter | ||
// from a previous [sendMessage] call by us. | ||
// | ||
// This is not yet fully documented. See CZO discussion for reference: | ||
// https://chat.zulip.org/#narrow/channel/412-api-documentation/topic/local_id.2C.20queue_id.2Fsender_queue_id/near/2135340 | ||
final String? localMessageId; | ||
|
||
MessageEvent({required super.id, required this.message, required this.localMessageId}); | ||
|
||
static Map<String, dynamic> _readMessageValue(Map<dynamic, dynamic> json, String key) => | ||
{...json['message'] as Map<String, dynamic>, 'flags': json['flags']}; | ||
|
||
factory MessageEvent.fromJson(Map<String, dynamic> json) => MessageEvent( | ||
id: json['id'] as int, | ||
message: Message.fromJson({ | ||
...json['message'] as Map<String, dynamic>, | ||
'flags': (json['flags'] as List<dynamic>).map((e) => e as String).toList(), | ||
}), | ||
); | ||
factory MessageEvent.fromJson(Map<String, dynamic> json) => | ||
_$MessageEventFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
final messageJson = message.toJson(); | ||
final flags = messageJson['flags']; | ||
messageJson.remove('flags'); | ||
return {'id': id, 'type': type, 'message': messageJson, 'flags': flags}; | ||
return {..._$MessageEventToJson(this), 'message': messageJson, 'flags': flags}; | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,8 +193,8 @@ Future<SendMessageResult> sendMessage( | |
'to': destination.userIds, | ||
}}), | ||
'content': RawParameter(content), | ||
if (queueId != null) 'queue_id': queueId, // TODO should this use RawParameter? | ||
if (localId != null) 'local_id': localId, // TODO should this use RawParameter? | ||
if (queueId != null) 'queue_id': RawParameter(queueId), | ||
if (localId != null) 'local_id': RawParameter(localId), | ||
Comment on lines
-196
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change to Then the change adding |
||
if (readBySender != null) 'read_by_sender': readBySender, | ||
}, | ||
overrideUserAgent: switch ((supportsReadBySender, readBySender)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,8 +362,8 @@ void main() { | |
'to': streamId.toString(), | ||
'topic': topic, | ||
'content': content, | ||
'queue_id': '"abc:123"', | ||
'local_id': '"456"', | ||
'queue_id': 'abc:123', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, is this really NFC?
Seems like it changes what we'll actually send to the server. I guess it's NFC for the actual app, in that we don't currently pass this parameter in calls to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's true that a string as a top-level parameter to a Zulip API endpoint is typically sent as itself, not JSON-encoded. That isn't always true, though. Right in this same endpoint, when passing a channel name to (The server does currently accept a raw stream name there, apparently, but that isn't and fundamentally can't be reliable.) Moreover our docs don't really cover where this is the case or isn't, except via the So for this change, I think the key point is that you've tested and the raw string is what works. |
||
'local_id': '456', | ||
'read_by_sender': 'true', | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -622,6 +622,9 @@ UserTopicEvent userTopicEvent( | |
); | ||
} | ||
|
||
MessageEvent messageEvent(Message message) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commit-message nit:
Better:
For examples of previous summary lines, try this command:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I added a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah, thanks. I have this in my
That's equivalent to a |
||
MessageEvent(id: 0, message: message, localMessageId: null); | ||
|
||
DeleteMessageEvent deleteMessageEvent(List<StreamMessage> messages) { | ||
assert(messages.isNotEmpty); | ||
final streamId = messages.first.streamId; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, nice to have taken care of this.