Fixup Length Display so it counts Bytes not Chars
This commit is contained in:
parent
ef5e8c6fcd
commit
eddca2e974
|
@ -54,7 +54,7 @@ class WindowsNotificationManager implements NotificationsManager {
|
||||||
}
|
}
|
||||||
// clicked
|
// clicked
|
||||||
if (event is ToastActivated) {
|
if (event is ToastActivated) {
|
||||||
active = false;
|
active = false;
|
||||||
}
|
}
|
||||||
// if a supplied action was clicked
|
// if a supplied action was clicked
|
||||||
if (event is ToastInteracted) {
|
if (event is ToastInteracted) {
|
||||||
|
|
|
@ -179,13 +179,14 @@ class _MessageViewState extends State<MessageView> {
|
||||||
// size because of the additional wrapping end encoding
|
// size because of the additional wrapping end encoding
|
||||||
// hybrid groups should allow these numbers to be the same.
|
// hybrid groups should allow these numbers to be the same.
|
||||||
static const P2PMessageLengthMax = 7000;
|
static const P2PMessageLengthMax = 7000;
|
||||||
static const GroupMessageLengthMax = 1800;
|
static const GroupMessageLengthMax = 1600;
|
||||||
|
|
||||||
void _sendMessage([String? ignoredParam]) {
|
void _sendMessage([String? ignoredParam]) {
|
||||||
var isGroup = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(Provider.of<AppState>(context, listen: false).selectedConversation!)!.isGroup;
|
var isGroup = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(Provider.of<AppState>(context, listen: false).selectedConversation!)!.isGroup;
|
||||||
|
|
||||||
// peers and groups currently have different length constraints (servers can store less)...
|
// peers and groups currently have different length constraints (servers can store less)...
|
||||||
var lengthOk = (isGroup && ctrlrCompose.value.text.length < GroupMessageLengthMax) || ctrlrCompose.value.text.length <= P2PMessageLengthMax;
|
var actualMessageLength = ctrlrCompose.value.text.length;
|
||||||
|
var lengthOk = (isGroup && actualMessageLength < GroupMessageLengthMax) || actualMessageLength <= P2PMessageLengthMax;
|
||||||
|
|
||||||
if (ctrlrCompose.value.text.isNotEmpty && lengthOk) {
|
if (ctrlrCompose.value.text.isNotEmpty && lengthOk) {
|
||||||
if (Provider.of<AppState>(context, listen: false).selectedConversation != null && Provider.of<AppState>(context, listen: false).selectedIndex != null) {
|
if (Provider.of<AppState>(context, listen: false).selectedConversation != null && Provider.of<AppState>(context, listen: false).selectedIndex != null) {
|
||||||
|
@ -250,6 +251,10 @@ class _MessageViewState extends State<MessageView> {
|
||||||
bool isOffline = Provider.of<ContactInfoState>(context).isOnline() == false;
|
bool isOffline = Provider.of<ContactInfoState>(context).isOnline() == false;
|
||||||
bool isGroup = Provider.of<ContactInfoState>(context).isGroup;
|
bool isGroup = Provider.of<ContactInfoState>(context).isGroup;
|
||||||
|
|
||||||
|
var charLength = ctrlrCompose.value.text.characters.length;
|
||||||
|
var expectedLength = ctrlrCompose.value.text.length;
|
||||||
|
var numberOfBytesMoreThanChar = (expectedLength - charLength);
|
||||||
|
|
||||||
var composeBox = Container(
|
var composeBox = Container(
|
||||||
color: Provider.of<Settings>(context).theme.backgroundMainColor,
|
color: Provider.of<Settings>(context).theme.backgroundMainColor,
|
||||||
padding: EdgeInsets.all(2),
|
padding: EdgeInsets.all(2),
|
||||||
|
@ -274,11 +279,16 @@ class _MessageViewState extends State<MessageView> {
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
enableIMEPersonalizedLearning: false,
|
enableIMEPersonalizedLearning: false,
|
||||||
minLines: 1,
|
minLines: 1,
|
||||||
maxLength: isGroup ? GroupMessageLengthMax : P2PMessageLengthMax,
|
maxLength: (isGroup ? GroupMessageLengthMax : P2PMessageLengthMax) - numberOfBytesMoreThanChar,
|
||||||
maxLengthEnforcement: MaxLengthEnforcement.enforced,
|
maxLengthEnforcement: MaxLengthEnforcement.enforced,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
onFieldSubmitted: _sendMessage,
|
onFieldSubmitted: _sendMessage,
|
||||||
enabled: !isOffline,
|
enabled: !isOffline,
|
||||||
|
onChanged: (String x) {
|
||||||
|
setState(() {
|
||||||
|
// we need to force a rerender here to update the max length count
|
||||||
|
});
|
||||||
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: isOffline ? "" : AppLocalizations.of(context)!.placeholderEnterMessage,
|
hintText: isOffline ? "" : AppLocalizations.of(context)!.placeholderEnterMessage,
|
||||||
hintStyle: TextStyle(color: Provider.of<Settings>(context).theme.sendHintTextColor),
|
hintStyle: TextStyle(color: Provider.of<Settings>(context).theme.sendHintTextColor),
|
||||||
|
|
Loading…
Reference in New Issue