Skip to content

Max message limit changed from static value to server value #1267

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

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class InitialSnapshot {
final int maxFileUploadSizeMib;

final Uri? serverEmojiDataUrl; // TODO(server-6)
final int maxMessageLength;

@JsonKey(readValue: _readUsersIsActiveFallbackTrue)
final List<User> realmUsers;
Expand Down Expand Up @@ -132,6 +133,7 @@ class InitialSnapshot {
required this.realmUsers,
required this.realmNonActiveUsers,
required this.crossRealmBots,
required this.maxMessageLength,
});

factory InitialSnapshot.fromJson(Map<String, dynamic> json) =>
Expand Down
2 changes: 2 additions & 0 deletions lib/api/model/initial_snapshot.g.dart

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

6 changes: 5 additions & 1 deletion lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
connection: connection,
realmUrl: realmUrl,
realmWaitingPeriodThreshold: initialSnapshot.realmWaitingPeriodThreshold,
maxMessageLength : initialSnapshot.maxMessageLength,
maxFileUploadSizeMib: initialSnapshot.maxFileUploadSizeMib,
realmDefaultExternalAccounts: initialSnapshot.realmDefaultExternalAccounts,
customProfileFields: _sortCustomProfileFields(initialSnapshot.customProfileFields),
Expand Down Expand Up @@ -327,7 +328,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
required MessageStoreImpl messages,
required this.unreads,
required this.recentDmConversationsView,
required this.recentSenders,
required this.recentSenders, required this.maxMessageLength,
}) : assert(selfUserId == globalStore.getAccount(accountId)!.userId),
assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
assert(realmUrl == connection.realmUrl),
Expand All @@ -348,6 +349,8 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess

UpdateMachine? get updateMachine => _updateMachine;
UpdateMachine? _updateMachine;


set updateMachine(UpdateMachine? value) {
assert(_updateMachine == null);
assert(value != null);
Expand Down Expand Up @@ -378,6 +381,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
/// For docs, please see [InitialSnapshot.realmWaitingPeriodThreshold].
final int realmWaitingPeriodThreshold; // TODO(#668): update this realm setting
final int maxFileUploadSizeMib; // No event for this.
final int maxMessageLength;
final Map<String, RealmDefaultExternalAccount> realmDefaultExternalAccounts;
List<CustomProfileField> customProfileFields;
/// For docs, please see [InitialSnapshot.emailAddressVisibility].
Expand Down
16 changes: 14 additions & 2 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ class ComposeContentController extends ComposeController<ContentValidationError>

int _nextQuoteAndReplyTag = 0;
int _nextUploadTag = 0;
num _maxMessageLimit = 0;

num get maxMessageLimit => _maxMessageLimit;

// Setter for maxMessageLimit
set maxMessageLimit(num value) {
if (value < 0) {
throw ArgumentError("maxMessageLimit cannot be negative.");
}
_maxMessageLimit = value;
}

final Map<int, ({int messageId, String placeholder})> _quoteAndReplies = {};
final Map<int, ({String filename, String placeholder})> _uploads = {};
Expand Down Expand Up @@ -260,7 +271,7 @@ class ComposeContentController extends ComposeController<ContentValidationError>
// normalized.length is the number of UTF-16 code units, while the server
// API expresses the max in Unicode code points. So this comparison will
// be conservative and may cut the user off shorter than necessary.
if (textNormalized.length > kMaxMessageLengthCodePoints)
if (textNormalized.length > _maxMessageLimit)
ContentValidationError.tooLong,

if (_quoteAndReplies.isNotEmpty)
Expand Down Expand Up @@ -1322,7 +1333,8 @@ class _ComposeBoxState extends State<ComposeBox> implements ComposeBoxState {
@override
Widget build(BuildContext context) {
final Widget? body;

final perAccountStore = PerAccountStoreWidget.of(context);
_controller.content.maxMessageLimit = perAccountStore.maxMessageLength;
final errorBanner = _errorBanner(context);
if (errorBanner != null) {
return _ComposeBoxContainer(body: null, errorBanner: errorBanner);
Expand Down
2 changes: 2 additions & 0 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ InitialSnapshot initialSnapshot({
int? realmWaitingPeriodThreshold,
Map<String, RealmDefaultExternalAccount>? realmDefaultExternalAccounts,
int? maxFileUploadSizeMib,
int? maxMessageLength,
Uri? serverEmojiDataUrl,
List<User>? realmUsers,
List<User>? realmNonActiveUsers,
Expand Down Expand Up @@ -865,6 +866,7 @@ InitialSnapshot initialSnapshot({
realmWaitingPeriodThreshold: realmWaitingPeriodThreshold ?? 0,
realmDefaultExternalAccounts: realmDefaultExternalAccounts ?? {},
maxFileUploadSizeMib: maxFileUploadSizeMib ?? 25,
maxMessageLength: maxMessageLength ?? 10000,
serverEmojiDataUrl: serverEmojiDataUrl
?? realmUrl.replace(path: '/static/emoji.json'),
realmUsers: realmUsers ?? [],
Expand Down