2021-10-28 20:23:30 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
|
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.controls 1.0
|
|
|
|
import utils 1.0
|
|
|
|
|
2022-03-07 14:56:05 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
|
|
|
|
2021-10-28 20:23:30 +00:00
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
2022-06-07 14:47:45 +00:00
|
|
|
property string message: ""
|
2021-10-28 20:23:30 +00:00
|
|
|
property var store
|
|
|
|
property bool longChatText: true
|
2022-02-08 12:08:02 +00:00
|
|
|
property bool veryLongChatText: globalUtils.plainText(message).length > Constants.limitLongChatTextCompactMode
|
2021-10-28 20:23:30 +00:00
|
|
|
property bool readMore: false
|
|
|
|
property alias textField: chatText
|
|
|
|
|
|
|
|
signal linkActivated(url link)
|
|
|
|
property alias hoveredLink: chatText.hoveredLink
|
|
|
|
property bool linkHovered: chatText.hoveredLink !== ""
|
|
|
|
|
|
|
|
z: 51
|
|
|
|
|
2022-08-10 11:05:19 +00:00
|
|
|
implicitHeight: {
|
|
|
|
if (!visible)
|
|
|
|
return 0;
|
|
|
|
if (!chatText.visible && showMoreLoader.active)
|
|
|
|
return childrenRect.height - 10;
|
|
|
|
if (root.veryLongChatText && !root.readMore)
|
|
|
|
return Math.min(chatText.contentHeight, 200);
|
|
|
|
if (chatText.getText(0, chatText.text.length) !== "")
|
|
|
|
return chatText.contentHeight;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-10-28 20:23:30 +00:00
|
|
|
|
|
|
|
// This function is to avoid the binding loop warning
|
|
|
|
function setWidths() {
|
|
|
|
if (longChatText) {
|
|
|
|
root.width = 0;
|
|
|
|
chatText.width = Qt.binding(function () {return root.width})
|
|
|
|
} else {
|
|
|
|
chatText.width = Qt.binding(function () {return chatText.implicitWidth})
|
|
|
|
root.width = Qt.binding(function () {return chatText.width})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
root.setWidths()
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledTextEdit {
|
|
|
|
id: chatText
|
2022-07-20 12:14:50 +00:00
|
|
|
objectName: "chatText"
|
2021-10-28 20:23:30 +00:00
|
|
|
textFormat: Text.RichText
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
|
|
|
readOnly: true
|
|
|
|
selectByMouse: true
|
|
|
|
color: Style.current.textColor
|
|
|
|
clip: height < implicitHeight
|
|
|
|
onLinkActivated: {
|
2022-01-13 14:45:34 +00:00
|
|
|
root.linkActivated(link)
|
|
|
|
|
2021-12-10 16:11:18 +00:00
|
|
|
// Not Refactored Yet
|
|
|
|
// if(link.startsWith("#")) {
|
|
|
|
// const channelName = link.substring(1);
|
|
|
|
// const foundChannelObj = root.store.chatsModelInst.getChannel(channelName);
|
|
|
|
|
|
|
|
// if (!foundChannelObj)
|
|
|
|
// {
|
|
|
|
// root.store.chatsModelInst.channelView.joinPublicChat(channelName)
|
|
|
|
// if(root.store.chatsModelInst.communities.activeCommunity.active)
|
|
|
|
// {
|
|
|
|
// root.store.chatsModelInst.channelView.joinPublicChat(channelName)
|
|
|
|
// Global.changeAppSectionBySectionType(Constants.appSection.chat)
|
|
|
|
// }
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let obj = JSON.parse(foundChannelObj)
|
|
|
|
|
|
|
|
// if(obj.chatType === -1 || obj.chatType === Constants.chatTypePublic)
|
|
|
|
// {
|
|
|
|
// if(root.store.chatsModelInst.communities.activeCommunity.active) {
|
|
|
|
// root.store.chatsModelInst.channelView.joinPublicChat(channelName)
|
|
|
|
// Global.changeAppSectionBySectionType(Constants.appSection.chat)
|
|
|
|
// }
|
|
|
|
// root.store.chatsModelInst.channelView.setActiveChannel(channelName);
|
|
|
|
// }
|
|
|
|
// else if(obj.communityId === root.store.chatsModelInst.communities.activeCommunity.id &&
|
|
|
|
// obj.chatType === Constants.chatTypeCommunity &&
|
|
|
|
// root.store.chatsModelInst.channelView.activeChannel.id !== obj.id
|
|
|
|
// )
|
|
|
|
// {
|
|
|
|
// root.store.chatsModelInst.channelView.setActiveChannel(channelName);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
|
2022-01-13 14:45:34 +00:00
|
|
|
if (link.startsWith('//')) {
|
|
|
|
let pk = link.replace("//", "");
|
|
|
|
Global.openProfilePopup(pk)
|
|
|
|
return;
|
|
|
|
}
|
2021-12-10 16:11:18 +00:00
|
|
|
|
2022-01-13 14:45:34 +00:00
|
|
|
// Not Refactored Yet
|
2021-12-10 16:11:18 +00:00
|
|
|
// const data = Utils.getLinkDataForStatusLinks(link)
|
|
|
|
// if (data && data.callback) {
|
|
|
|
// return data.callback()
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
2022-01-13 14:45:34 +00:00
|
|
|
Global.openLink(link)
|
2021-10-28 20:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onLinkHovered: {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
}
|
|
|
|
|
|
|
|
text: {
|
2022-07-05 10:12:27 +00:00
|
|
|
if (contentType === Constants.messageContentType.stickerType)
|
|
|
|
return "";
|
|
|
|
let msg = StatusQUtils.Utils.linkifyAndXSS(message);
|
2022-05-13 15:55:42 +00:00
|
|
|
if (isEmoji)
|
|
|
|
return StatusQUtils.Emoji.parse(msg, StatusQUtils.Emoji.size.middle, StatusQUtils.Emoji.format.png);
|
|
|
|
if (isEdited) {
|
|
|
|
let index = msg.endsWith("code>") ? msg.length : msg.length - 4
|
2022-07-05 10:12:27 +00:00
|
|
|
return StatusQUtils.Utils.getMessageWithStyle(StatusQUtils.Emoji.parse(msg.slice(0, index) + Constants.editLabel + msg.slice(index)), isCurrentUser, hoveredLink)
|
2021-10-28 20:23:30 +00:00
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
return StatusQUtils.Utils.getMessageWithStyle(StatusQUtils.Emoji.parse(msg), isCurrentUser, hoveredLink)
|
2021-10-28 20:23:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: mask
|
|
|
|
anchors.fill: chatText
|
|
|
|
active: showMoreLoader.active
|
|
|
|
visible: false
|
|
|
|
sourceComponent: LinearGradient {
|
|
|
|
start: Qt.point(0, 0)
|
|
|
|
end: Qt.point(0, chatText.height)
|
|
|
|
gradient: Gradient {
|
|
|
|
GradientStop { position: 0.0; color: "white" }
|
|
|
|
GradientStop { position: 0.85; color: "white" }
|
|
|
|
GradientStop { position: 1; color: "transparent" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: opMask
|
|
|
|
active: showMoreLoader.active && !root.readMore
|
|
|
|
anchors.fill: chatText
|
|
|
|
sourceComponent: OpacityMask {
|
|
|
|
source: chatText
|
|
|
|
maskSource: mask
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: showMoreLoader
|
|
|
|
active: root.veryLongChatText
|
|
|
|
anchors.top: chatText.bottom
|
|
|
|
anchors.topMargin: - Style.current.padding
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
sourceComponent: Component {
|
|
|
|
SVGImage {
|
|
|
|
id: emojiImage
|
|
|
|
width: 256
|
|
|
|
height: 44
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: Style.svg("read-more")
|
|
|
|
z: 100
|
|
|
|
rotation: root.readMore ? 180 : 0
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: {
|
|
|
|
root.readMore = !root.readMore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|