2020-11-18 18:55:57 +00:00
|
|
|
import QtQuick 2.13
|
2020-11-18 20:07:23 +00:00
|
|
|
import QtGraphicalEffects 1.0
|
2020-07-15 21:04:14 +00:00
|
|
|
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.controls 1.0
|
|
|
|
import utils 1.0
|
|
|
|
|
2020-09-25 19:44:40 +00:00
|
|
|
Item {
|
2021-09-27 12:08:55 +00:00
|
|
|
id: root
|
|
|
|
|
2021-10-01 15:58:36 +00:00
|
|
|
property var store
|
|
|
|
property var messageStore
|
2020-09-25 19:44:40 +00:00
|
|
|
property bool longChatText: true
|
2021-10-21 22:39:53 +00:00
|
|
|
property bool veryLongChatText: !!root.store ? root.store.chatsModelInst.plainText(message).length >
|
2021-10-20 09:50:50 +00:00
|
|
|
(localAccountSensitiveSettings.useCompactMode ? Constants.limitLongChatTextCompactMode : Constants.limitLongChatText) : false
|
2020-09-25 19:44:40 +00:00
|
|
|
property bool readMore: false
|
|
|
|
property alias textField: chatText
|
|
|
|
|
2021-09-27 12:08:55 +00:00
|
|
|
signal linkActivated(url link)
|
2021-10-01 15:58:36 +00:00
|
|
|
property alias hoveredLink: chatText.hoveredLink
|
2021-09-27 12:08:55 +00:00
|
|
|
property bool linkHovered: chatText.hoveredLink !== ""
|
|
|
|
|
2020-12-15 18:56:02 +00:00
|
|
|
z: 51
|
2020-11-18 20:07:23 +00:00
|
|
|
|
2021-02-01 18:40:55 +00:00
|
|
|
implicitHeight: visible ? (showMoreLoader.active ? childrenRect.height - 10 : chatText.height) : 0
|
2020-11-18 18:55:57 +00: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 19:44:40 +00:00
|
|
|
StyledTextEdit {
|
|
|
|
id: chatText
|
2021-01-05 19:35:31 +00:00
|
|
|
visible: !showMoreLoader.active || root.readMore
|
2020-09-25 19:44:40 +00:00
|
|
|
textFormat: Text.RichText
|
|
|
|
wrapMode: Text.Wrap
|
2020-11-25 10:46:18 +00:00
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
2020-09-25 19:44:40 +00:00
|
|
|
readOnly: true
|
|
|
|
selectByMouse: true
|
|
|
|
color: Style.current.textColor
|
2021-01-05 19:35:31 +00:00
|
|
|
height: root.veryLongChatText && !root.readMore ? Math.min(implicitHeight, 200) : implicitHeight
|
2021-06-14 15:40:05 +00:00
|
|
|
clip: height < implicitHeight
|
2021-07-07 15:08:05 +00:00
|
|
|
onLinkActivated: {
|
2021-09-27 12:08:55 +00:00
|
|
|
|
|
|
|
root.linkActivated(link)
|
2020-09-25 19:44:40 +00:00
|
|
|
if(link.startsWith("#")) {
|
2021-05-10 15:30:36 +00:00
|
|
|
const channelName = link.substring(1);
|
2021-10-21 22:39:53 +00:00
|
|
|
const foundChannelObj = root.store.chatsModelInst.getChannel(channelName);
|
2021-05-10 15:30:36 +00:00
|
|
|
|
2021-09-20 13:49:51 +00:00
|
|
|
if (!foundChannelObj)
|
|
|
|
{
|
2021-12-01 16:47:57 +00:00
|
|
|
// Not Refactored Yet
|
|
|
|
// root.store.chatsModelInst.channelView.joinPublicChat(channelName)
|
|
|
|
// if(root.store.chatsModelInst.communities.activeCommunity.active)
|
|
|
|
// {
|
|
|
|
// root.store.chatsModelInst.channelView.joinPublicChat(channelName)
|
2021-12-06 21:10:54 +00:00
|
|
|
// Global.changeAppSectionBySectionType(Constants.appSection.chat)
|
2021-12-01 16:47:57 +00:00
|
|
|
// }
|
2021-09-20 13:49:51 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let obj = JSON.parse(foundChannelObj)
|
|
|
|
|
|
|
|
if(obj.chatType === -1 || obj.chatType === Constants.chatTypePublic)
|
|
|
|
{
|
2021-12-01 16:47:57 +00:00
|
|
|
// Not Refactored Yet
|
|
|
|
// if(root.store.chatsModelInst.communities.activeCommunity.active) {
|
|
|
|
// root.store.chatsModelInst.channelView.joinPublicChat(channelName)
|
2021-12-06 21:10:54 +00:00
|
|
|
// Global.changeAppSectionBySectionType(Constants.appSection.chat)
|
2021-12-01 16:47:57 +00:00
|
|
|
// }
|
|
|
|
// root.store.chatsModelInst.channelView.setActiveChannel(channelName);
|
2021-09-20 13:49:51 +00:00
|
|
|
}
|
2021-10-21 22:39:53 +00:00
|
|
|
else if(obj.communityId === root.store.chatsModelInst.communities.activeCommunity.id &&
|
2021-09-20 13:49:51 +00:00
|
|
|
obj.chatType === Constants.chatTypeCommunity &&
|
2021-10-21 22:39:53 +00:00
|
|
|
root.store.chatsModelInst.channelView.activeChannel.id !== obj.id
|
2021-09-20 13:49:51 +00:00
|
|
|
)
|
|
|
|
{
|
2021-10-21 22:39:53 +00:00
|
|
|
root.store.chatsModelInst.channelView.setActiveChannel(channelName);
|
2021-04-26 06:18:28 +00:00
|
|
|
}
|
2021-05-10 15:30:36 +00:00
|
|
|
|
2021-09-20 13:49:51 +00:00
|
|
|
return
|
2020-09-25 19:44:40 +00:00
|
|
|
}
|
2020-07-20 21:59:01 +00:00
|
|
|
|
2020-09-25 19:44:40 +00:00
|
|
|
if (link.startsWith('//')) {
|
|
|
|
let pk = link.replace("//", "");
|
2020-12-21 12:08:44 +00:00
|
|
|
const userProfileImage = appMain.getProfileImage(pk)
|
2021-10-28 20:23:30 +00:00
|
|
|
openProfilePopup(root.store.userNameOrAlias(pk), pk, userProfileImage || root.store.generateIdenticon(pk))
|
2020-09-25 19:44:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-25 19:41:40 +00:00
|
|
|
const data = Utils.getLinkDataForStatusLinks(link)
|
|
|
|
if (data && data.callback) {
|
|
|
|
return data.callback()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-06 21:10:54 +00:00
|
|
|
Global.openLink(link)
|
2020-09-25 19:44:40 +00:00
|
|
|
}
|
2020-12-06 02:29:23 +00:00
|
|
|
|
|
|
|
onLinkHovered: {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
}
|
|
|
|
|
2020-09-25 19:44:40 +00:00
|
|
|
text: {
|
|
|
|
if(contentType === Constants.stickerType) return "";
|
|
|
|
let msg = Utils.linkifyAndXSS(message);
|
|
|
|
if(isEmoji) {
|
2021-01-14 08:46:05 +00:00
|
|
|
return Emoji.parse(msg, Emoji.size.middle);
|
2020-09-25 19:44:40 +00:00
|
|
|
} else {
|
2021-06-29 14:49:32 +00:00
|
|
|
if(isEdited){
|
2021-08-24 14:14:19 +00:00
|
|
|
let index = msg.endsWith("code>") ? msg.length : msg.length - 4
|
2021-10-20 09:50:50 +00:00
|
|
|
return Utils.getMessageWithStyle(Emoji.parse(msg.slice(0, index) + Constants.editLabel + msg.slice(index)), localAccountSensitiveSettings.useCompactMode, isCurrentUser, hoveredLink)
|
2021-06-29 14:49:32 +00:00
|
|
|
}
|
2021-10-20 09:50:50 +00:00
|
|
|
return Utils.getMessageWithStyle(Emoji.parse(msg), localAccountSensitiveSettings.useCompactMode, isCurrentUser, hoveredLink)
|
2020-09-25 19:44:40 +00:00
|
|
|
}
|
2020-07-20 21:59:01 +00:00
|
|
|
}
|
2020-09-25 19:44:40 +00:00
|
|
|
}
|
2020-07-20 21:59:01 +00:00
|
|
|
|
2020-11-18 20:07:23 +00:00
|
|
|
Loader {
|
|
|
|
id: mask
|
|
|
|
anchors.fill: chatText
|
2021-01-05 19:35:31 +00:00
|
|
|
active: showMoreLoader.active
|
2020-11-18 20:07:23 +00: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 19:35:31 +00:00
|
|
|
active: showMoreLoader.active && !root.readMore
|
2020-11-18 20:07:23 +00:00
|
|
|
anchors.fill: chatText
|
|
|
|
sourceComponent: OpacityMask {
|
|
|
|
source: chatText
|
|
|
|
maskSource: mask
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 19:44:40 +00:00
|
|
|
Loader {
|
2020-09-30 18:45:45 +00:00
|
|
|
id: showMoreLoader
|
2020-09-25 19:44:40 +00:00
|
|
|
active: root.veryLongChatText
|
|
|
|
anchors.top: chatText.bottom
|
2020-11-18 20:07:23 +00:00
|
|
|
anchors.topMargin: - Style.current.padding
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2020-09-30 18:45:45 +00:00
|
|
|
sourceComponent: Component {
|
2020-11-18 20:07:23 +00:00
|
|
|
SVGImage {
|
|
|
|
id: emojiImage
|
|
|
|
width: 256
|
|
|
|
height: 44
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2021-09-28 15:04:06 +00:00
|
|
|
source: Style.svg("read-more")
|
2020-09-30 18:45:45 +00:00
|
|
|
z: 100
|
2020-11-19 16:08:08 +00:00
|
|
|
rotation: root.readMore ? 180 : 0
|
2020-09-30 18:45:45 +00:00
|
|
|
MouseArea {
|
|
|
|
z: 101
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: {
|
|
|
|
root.readMore = !root.readMore
|
|
|
|
}
|
2020-09-25 19:44:40 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|