Skip to content

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

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions lib/api/route/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Member

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".

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`
Copy link
Member

Choose a reason for hiding this comment

The 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 lib/credential_fixture.dart as described in the README.)

Looking at connection.auth.realmUrl would be a good way to check that.

'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);
}
12 changes: 12 additions & 0 deletions lib/api/route/messages.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '../api/model/events.dart';
import '../api/model/initial_snapshot.dart';
import '../api/model/model.dart';
import '../api/route/events.dart';
import '../api/route/messages.dart';
import '../credential_fixture.dart' as credentials;
import 'message_list.dart';

Expand Down Expand Up @@ -106,6 +107,11 @@ class PerAccountStore extends ChangeNotifier {
}
}

Future<void> sendStreamMessage({required String topic, required String content}) {
// TODO implement outbox; see design at
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M3881.20Sending.20outbox.20messages.20is.20fraught.20with.20issues/near/1405739
return sendMessage(connection, topic: topic, content: content);
}
}

/// A scaffolding hack for while prototyping.
Expand Down
6 changes: 2 additions & 4 deletions lib/widgets/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';

import 'compose_box.dart';
import 'message_list.dart';
import '../model/store.dart';

Expand Down Expand Up @@ -163,9 +164,6 @@ class MessageListPage extends StatelessWidget {

child: const Expanded(
child: MessageList())),
const SizedBox(
height: 80,
child: Center(
child: Text("(Compose box goes here.)")))]))));
const StreamComposeBox()]))));
}
}
Loading