2020-11-18 13:55:57 -05:00
|
|
|
import QtQuick 2.13
|
2020-07-15 17:04:14 -04:00
|
|
|
import "../../../../../shared"
|
|
|
|
import "../../../../../imports"
|
2020-11-18 16:07:23 -04:00
|
|
|
import QtGraphicalEffects 1.0
|
2020-07-15 17:04:14 -04:00
|
|
|
|
2020-09-25 15:44:40 -04:00
|
|
|
Item {
|
|
|
|
property bool longChatText: true
|
|
|
|
property bool veryLongChatText: chatsModel.plainText(message).length >
|
2021-02-10 15:41:00 -05:00
|
|
|
(appSettings.useCompactMode ? Constants.limitLongChatTextCompactMode : Constants.limitLongChatText)
|
2020-09-25 15:44:40 -04:00
|
|
|
property bool readMore: false
|
|
|
|
property alias textField: chatText
|
|
|
|
|
|
|
|
id: root
|
2021-06-11 15:50:52 -04:00
|
|
|
visible: contentType === Constants.messageType || isEmoji
|
2020-12-15 12:56:02 -06:00
|
|
|
z: 51
|
2020-11-18 16:07:23 -04:00
|
|
|
|
2021-02-01 13:40:55 -05:00
|
|
|
implicitHeight: visible ? (showMoreLoader.active ? childrenRect.height - 10 : chatText.height) : 0
|
2020-11-18 13:55:57 -05:00
|
|
|
|
|
|
|
// This function is to avoid the binding loop warning
|
|
|
|
function setWidths() {
|
|
|
|
if (longChatText) {
|
|
|
|
root.width = undefined
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:44:40 -04:00
|
|
|
StyledTextEdit {
|
|
|
|
id: chatText
|
2021-01-05 14:35:31 -05:00
|
|
|
visible: !showMoreLoader.active || root.readMore
|
2020-09-25 15:44:40 -04:00
|
|
|
textFormat: Text.RichText
|
|
|
|
wrapMode: Text.Wrap
|
2020-11-25 11:46:18 +01:00
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
2020-09-25 15:44:40 -04:00
|
|
|
readOnly: true
|
|
|
|
selectByMouse: true
|
|
|
|
color: Style.current.textColor
|
2021-01-05 14:35:31 -05:00
|
|
|
height: root.veryLongChatText && !root.readMore ? Math.min(implicitHeight, 200) : implicitHeight
|
2020-09-25 15:44:40 -04:00
|
|
|
clip: true
|
|
|
|
onLinkActivated: function (link) {
|
|
|
|
if(link.startsWith("#")) {
|
2021-05-10 11:30:36 -04:00
|
|
|
const channelName = link.substring(1);
|
2021-04-26 16:18:28 +10:00
|
|
|
const chatType = chatsModel.communities.activeCommunity.active ? Constants.chatTypeCommunity : Constants.chatTypePublic;
|
2021-05-10 11:30:36 -04:00
|
|
|
const foundChatType = chatsModel.getChatType(channelName);
|
|
|
|
|
2021-05-10 13:31:08 -04:00
|
|
|
if(foundChatType === -1 || foundChatType !== Constants.chatTypePublic){
|
2021-05-10 11:30:36 -04:00
|
|
|
chatsModel.joinPublicChat(channelName);
|
|
|
|
if(chatsModel.communities.activeCommunity.active) {
|
|
|
|
chatsModel.communities.activeCommunity.active = false
|
|
|
|
appMain.changeAppSection(Constants.chat)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chatsModel.setActiveChannel(channelName);
|
2021-04-26 16:18:28 +10:00
|
|
|
}
|
2021-05-10 11:30:36 -04:00
|
|
|
|
2020-09-25 15:44:40 -04:00
|
|
|
return;
|
|
|
|
}
|
2020-07-20 17:59:01 -04:00
|
|
|
|
2020-09-25 15:44:40 -04:00
|
|
|
if (link.startsWith('//')) {
|
|
|
|
let pk = link.replace("//", "");
|
2020-12-21 13:08:44 +01:00
|
|
|
const userProfileImage = appMain.getProfileImage(pk)
|
2020-11-30 12:03:52 -05:00
|
|
|
openProfilePopup(chatsModel.userNameOrAlias(pk), pk, userProfileImage || utilsModel.generateIdenticon(pk))
|
2020-09-25 15:44:40 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-25 14:41:40 -05:00
|
|
|
const data = Utils.getLinkDataForStatusLinks(link)
|
|
|
|
if (data && data.callback) {
|
|
|
|
return data.callback()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-29 15:33:54 -05:00
|
|
|
appMain.openLink(link)
|
2020-09-25 15:44:40 -04:00
|
|
|
}
|
2020-12-06 04:29:23 +02:00
|
|
|
|
|
|
|
onLinkHovered: {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:44:40 -04:00
|
|
|
text: {
|
|
|
|
if(contentType === Constants.stickerType) return "";
|
|
|
|
let msg = Utils.linkifyAndXSS(message);
|
|
|
|
if(isEmoji) {
|
2021-01-14 12:46:05 +04:00
|
|
|
return Emoji.parse(msg, Emoji.size.middle);
|
2020-09-25 15:44:40 -04:00
|
|
|
} else {
|
2021-05-07 09:40:23 +10:00
|
|
|
return Utils.getMessageWithStyle(Emoji.parse(msg), appSettings.useCompactMode, isCurrentUser, hoveredLink)
|
2020-09-25 15:44:40 -04:00
|
|
|
}
|
2020-07-20 17:59:01 -04:00
|
|
|
}
|
2020-09-25 15:44:40 -04:00
|
|
|
}
|
2020-07-20 17:59:01 -04:00
|
|
|
|
2020-11-18 16:07:23 -04:00
|
|
|
Loader {
|
|
|
|
id: mask
|
|
|
|
anchors.fill: chatText
|
2021-01-05 14:35:31 -05:00
|
|
|
active: showMoreLoader.active
|
2020-11-18 16:07:23 -04:00
|
|
|
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
|
2021-01-05 14:35:31 -05:00
|
|
|
active: showMoreLoader.active && !root.readMore
|
2020-11-18 16:07:23 -04:00
|
|
|
anchors.fill: chatText
|
|
|
|
sourceComponent: OpacityMask {
|
|
|
|
source: chatText
|
|
|
|
maskSource: mask
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:44:40 -04:00
|
|
|
Loader {
|
2020-09-30 14:45:45 -04:00
|
|
|
id: showMoreLoader
|
2020-09-25 15:44:40 -04:00
|
|
|
active: root.veryLongChatText
|
|
|
|
anchors.top: chatText.bottom
|
2020-11-18 16:07:23 -04:00
|
|
|
anchors.topMargin: - Style.current.padding
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2020-09-30 14:45:45 -04:00
|
|
|
sourceComponent: Component {
|
2020-11-18 16:07:23 -04:00
|
|
|
SVGImage {
|
|
|
|
id: emojiImage
|
|
|
|
width: 256
|
|
|
|
height: 44
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2020-11-19 12:08:08 -04:00
|
|
|
source: "../../../../img/read-more.svg"
|
2020-09-30 14:45:45 -04:00
|
|
|
z: 100
|
2020-11-19 12:08:08 -04:00
|
|
|
rotation: root.readMore ? 180 : 0
|
2020-09-30 14:45:45 -04:00
|
|
|
MouseArea {
|
|
|
|
z: 101
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: {
|
|
|
|
root.readMore = !root.readMore
|
|
|
|
}
|
2020-09-25 15:44:40 -04:00
|
|
|
}
|
|
|
|
}
|
2020-07-15 17:04:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|