feat: introduce character limit of 2000 when sending messages

fix: refactor sticker query
This commit is contained in:
hydr063n 2020-09-28 15:24:03 +02:00 committed by Iuri Matias
parent 3229fc06e6
commit 5da0d47c5a
2 changed files with 49 additions and 7 deletions

View File

@ -170,7 +170,7 @@ StackLayout {
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
Layout.fillWidth: true
Layout.preferredWidth: parent.width
height: !isExtendedInput ? 70 : 140
height: (!isExtendedInput ? 70 : 140) * chatInput.extraHeightFactor
Layout.preferredHeight: height
SuggestionBox {

View File

@ -2,7 +2,7 @@ import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import QtMultimedia 5.13
import QtQuick.Dialogs 1.0
import QtQuick.Dialogs 1.3
import "../components"
import "../../../../shared"
import "../../../../imports"
@ -23,12 +23,21 @@ Rectangle {
property bool paste: false;
property bool isColonPressed: false;
property int extraHeightFactor: calculateExtraHeightFactor()
property int messageLimit: 2000
property int messageLimitVisible: 200
Audio {
id: sendMessageSound
source: "../../../../sounds/send_message.wav"
volume: appSettings.volume
}
function calculateExtraHeightFactor() {
const factor = (txtData.length / 500) + 1;
return (factor > 5) ? 5 : factor;
}
function insertInTextInput(start, text) {
// Repace new lines with entities because `insert` gets rid of them
txtData.insert(start, text.replace(/\n/g, "<br/>"));
@ -75,7 +84,12 @@ Rectangle {
event.accepted = true;
return
}
sendMsg(event);
if (txtData.length < messageLimit) {
sendMsg(event);
return;
}
if(event) event.accepted = true
messageTooLongDialog.open()
}
if ((event.key === Qt.Key_V) && (event.modifiers & Qt.ControlModifier)) {
@ -368,7 +382,7 @@ Rectangle {
anchors.rightMargin: 0
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
topPadding: Style.current.padding
StyledTArea {
textFormat: Text.RichText
id: txtData
@ -391,18 +405,46 @@ Rectangle {
}
}
StyledText {
id: messageLengthLimit
property int remainingChars: messageLimit - txtData.length
text: remainingChars.toString()
visible: remainingChars <= root.messageLimitVisible
color: (remainingChars <= 0) ? Style.current.danger : Style.current.textColor
anchors.right: parent.right
anchors.bottom: sendBtns.top
anchors.rightMargin: Style.current.padding
leftPadding: Style.current.halfPadding
rightPadding: Style.current.halfPadding
}
ChatButtons {
id: sendBtns
height: parent.height
anchors.verticalCenter: parent.verticalCenter
height: 36
anchors.right: parent.right
anchors.rightMargin: Style.current.padding
anchors.bottom: parent.bottom
addToChat: function (text, atCursor) {
insertInTextInput(atCursor ? txtData.cursorPosition :txtData.length, text)
}
onSend: function(){
sendMsg(false)
if (txtData.length < messageLimit) {
sendMsg(false);
return;
}
messageTooLongDialog.open()
}
}
MessageDialog {
id: messageTooLongDialog
//% "Your message is too long."
title: qsTrId("your-message-is-too-long.")
icon: StandardIcon.Critical
//% "Please make your message shorter. We have set the limit to 2000 characters to be courteous of others."
text: qsTrId("please-make-your-message-shorter.-we-have-set-the-limit-to-2000-characters-to-be-courteous-of-others.")
standardButtons: StandardButton.Ok
}
}
/*##^##
Designer {