Skip to content

Commit 180868e

Browse files
chrisbobbegithub-actions[bot]
authored andcommitted
compose [nfc]: Comment on max-topic-length check about cutting off short
We have the same comment where we check the content length: if (textNormalized.length > kMaxMessageLengthCodePoints) and it applies here, too; the API doc on max_topic_length in /register also says it's in Unicode code points: https://zulip.com/api/register-queue And give our max-topic-length variable a more descriptive name, again like we do with kMaxMessageLengthCodePoints.
1 parent cda0925 commit 180868e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/api/route/messages.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class GetMessagesResult {
156156
}
157157

158158
// https://zulip.com/api/send-message#parameter-topic
159-
const int kMaxTopicLength = 60;
159+
const int kMaxTopicLengthCodePoints = 60;
160160

161161
// https://zulip.com/api/send-message#parameter-content
162162
const int kMaxMessageLengthCodePoints = 10000;

lib/widgets/compose_box.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ class ComposeTopicController extends ComposeController<TopicValidationError> {
8585
return [
8686
if (mandatory && textNormalized == kNoTopicTopic)
8787
TopicValidationError.mandatoryButEmpty,
88-
if (textNormalized.length > kMaxTopicLength)
88+
89+
// textNormalized.length is the number of UTF-16 code units, while the server
90+
// API expresses the max in Unicode code points. So this comparison will
91+
// be conservative and may cut the user off shorter than necessary.
92+
// TODO(#1238) stop cutting off shorter than necessary
93+
if (textNormalized.length > kMaxTopicLengthCodePoints)
8994
TopicValidationError.tooLong,
9095
];
9196
}

0 commit comments

Comments
 (0)