-
Notifications
You must be signed in to change notification settings - Fork 309
compose: Prototype compose box, using Material TextField
widget
#9
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
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 |
---|---|---|
|
@@ -46,3 +46,56 @@ class GetMessagesResult { | |
|
||
Map<String, dynamic> toJson() => _$GetMessagesResultToJson(this); | ||
} | ||
|
||
// https://zulip.com/api/send-message#parameter-topic | ||
const int kMaxTopicLength = 60; | ||
|
||
// https://zulip.com/api/send-message#parameter-content | ||
const int kMaxMessageLengthCodePoints = 10000; | ||
|
||
/// The topic servers understand to mean "there is no topic". | ||
/// | ||
/// This should match | ||
/// https://github.com/zulip/zulip/blob/6.0/zerver/actions/message_edit.py#L940 | ||
/// or similar logic at the latest `main`. | ||
// This is hardcoded in the server, and therefore untranslated; that's | ||
// zulip/zulip#3639. | ||
const String kNoTopicTopic = '(no topic)'; | ||
|
||
/// https://zulip.com/api/send-message | ||
// TODO currently only handles stream messages; fix | ||
Future<SendMessageResult> sendMessage( | ||
ApiConnection connection, { | ||
required String content, | ||
required String topic, | ||
}) async { | ||
// assert() is less verbose but would have no effect in production, I think: | ||
// https://dart.dev/guides/language/language-tour#assert | ||
if (Uri.parse(connection.auth.realmUrl).origin != 'https://chat.zulip.org') { | ||
throw Exception('This binding can currently only be used on https://chat.zulip.org.'); | ||
} | ||
|
||
final data = await connection.post('messages', { | ||
'type': RawParameter('stream'), // TODO parametrize | ||
'to': 7, // TODO parametrize; this is `#test here` | ||
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. This is OK for the prototype, but let's do have it check the assumption that this is chat.zulip.org, and throw if not. (Because it's otherwise configurable, in Looking at |
||
'topic': RawParameter(topic), | ||
'content': RawParameter(content), | ||
}); | ||
return SendMessageResult.fromJson(jsonDecode(data)); | ||
} | ||
|
||
@JsonSerializable() | ||
class SendMessageResult { | ||
final int id; | ||
final String? deliver_at; | ||
|
||
SendMessageResult({ | ||
required this.id, | ||
this.deliver_at, | ||
}); | ||
|
||
factory SendMessageResult.fromJson(Map<String, dynamic> json) => | ||
_$SendMessageResultFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$SendMessageResultToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Let's make the
lib/api/
changes as their own commit, like "api: Add send-message route".