fix(StatusMessageReply): Fixed text formatting in replied message

This commit is contained in:
Igor Sirotin 2022-10-04 18:28:57 +03:00 committed by Igor Sirotin
parent 8f254279e1
commit 09d8a10b49
4 changed files with 49 additions and 22 deletions

View File

@ -221,6 +221,9 @@ Rectangle {
profileClickable: root.profileClickable
onReplyProfileClicked: root.replyProfileClicked(sender, mouse)
audioMessageInfoText: root.audioMessageInfoText
onLinkActivated: {
root.linkActivated(link);
}
}
}
@ -286,25 +289,8 @@ Rectangle {
visible: active
sourceComponent: StatusTextMessage {
objectName: "StatusMessage_textMessage"
textField.text: {
if (root.messageDetails.contentType === StatusMessage.ContentType.Sticker)
return "";
const formattedMessage = Utils.linkifyAndXSS(root.messageDetails.messageText);
if (root.messageDetails.contentType === StatusMessage.ContentType.Emoji)
return Emoji.parse(formattedMessage, Emoji.size.middle, Emoji.format.png);
if (root.isEdited) {
const index = formattedMessage.endsWith("code>") ? formattedMessage.length : formattedMessage.length - 4;
const editedMessage = formattedMessage.slice(0, index)
+ ` <span class="isEdited">` + qsTr("(edited)") + `</span>`
+ formattedMessage.slice(index);
return Utils.getMessageWithStyle(Emoji.parse(editedMessage), textField.hoveredLink)
}
return Utils.getMessageWithStyle(Emoji.parse(formattedMessage), textField.hoveredLink)
}
messageDetails: root.messageDetails
isEdited: root.isEdited
onLinkActivated: {
root.linkActivated(link);
}

View File

@ -15,6 +15,7 @@ Item {
property bool profileClickable: true
signal replyProfileClicked(var sender, var mouse)
signal linkActivated(string link)
implicitHeight: layout.implicitHeight
implicitWidth: layout.implicitWidth
@ -83,12 +84,16 @@ Item {
}
StatusTextMessage {
Layout.fillWidth: true
textField.text: replyDetails.messageText
textField.font.pixelSize: Theme.secondaryTextFontSize
textField.color: Theme.palette.baseColor1
convertToSingleLine: true
clip: true
visible: !!replyDetails.messageText && replyDetails.contentType !== StatusMessage.ContentType.Sticker
allowShowMore: false
messageDetails: root.replyDetails
onLinkActivated: {
root.linkActivated(link);
}
}
StatusImageMessage {
Layout.fillWidth: true

View File

@ -4,10 +4,15 @@ import QtGraphicalEffects 1.0
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Core.Utils 0.1
Item {
id: root
property StatusMessageDetails messageDetails: StatusMessageDetails {}
property bool isEdited: false
property bool convertToSingleLine: false
property alias textField: chatText
property bool allowShowMore: true
@ -21,19 +26,46 @@ Item {
property bool readMore: false
readonly property bool veryLongChatText: chatText.length > 1000
readonly property int showMoreHeight: showMoreLoader.visible ? showMoreLoader.height : 0
readonly property string text: {
if (root.messageDetails.contentType === StatusMessage.ContentType.Sticker)
return "";
const formattedMessage = Utils.linkifyAndXSS(root.messageDetails.messageText);
if (root.messageDetails.contentType === StatusMessage.ContentType.Emoji)
return Emoji.parse(formattedMessage, Emoji.size.middle, Emoji.format.png);
if (root.isEdited) {
const index = formattedMessage.endsWith("code>") ? formattedMessage.length : formattedMessage.length - 4;
const editedMessage = formattedMessage.slice(0, index)
+ ` <span class="isEdited">` + qsTr("(edited)") + `</span>`
+ formattedMessage.slice(index);
return Utils.getMessageWithStyle(Emoji.parse(editedMessage), chatText.hoveredLink)
}
if (root.convertToSingleLine) {
const singleLineMessage = Utils.convertToSingleLine(formattedMessage)
return Utils.getMessageWithStyle(Emoji.parse(singleLineMessage), chatText.hoveredLink)
}
return Utils.getMessageWithStyle(Emoji.parse(formattedMessage), chatText.hoveredLink)
}
}
TextEdit {
id: chatText
objectName: "StatusTextMessage_chatText"
readonly property int effectiveHeight: d.veryLongChatText && !d.readMore ? Math.min(chatText.implicitHeight, 200)
readonly property int effectiveHeight: d.veryLongChatText && !d.readMore
? Math.min(chatText.implicitHeight, 200)
: chatText.implicitHeight
width: parent.width
height: effectiveHeight + d.showMoreHeight / 2
visible: !opMask.active
clip: true
text: d.text
selectedTextColor: Theme.palette.directColor1
selectionColor: Theme.palette.primaryColor3
color: Theme.palette.directColor1

View File

@ -218,6 +218,10 @@ QtObject {
`${msg}`
}
function convertToSingleLine(text) {
return text.replace(/<br\s*\/>/gm, " ")
}
function delegateModelSort(srcGroup, dstGroup, lessThan) {
const insertPosition = (lessThan, item) => {
let lower = 0