2020-12-04 10:38:22 +00:00
|
|
|
import QtQuick 2.13
|
2020-07-15 21:04:14 +00:00
|
|
|
import "../../../../../shared"
|
|
|
|
import "../../../../../imports"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
property var clickMessage: function () {}
|
2020-12-07 23:38:53 +00:00
|
|
|
property string linkUrls: ""
|
|
|
|
property bool isCurrentUser: false
|
|
|
|
property int contentType: 2
|
2020-12-16 20:50:54 +00:00
|
|
|
property var container
|
2021-02-09 14:53:54 +00:00
|
|
|
property bool headerRepeatCondition: (authorCurrentMsg != authorPrevMsg || shouldRepeatHeader || dateGroupLbl.visible)
|
2020-07-15 21:04:14 +00:00
|
|
|
|
2020-12-07 23:38:53 +00:00
|
|
|
id: root
|
2020-07-15 21:04:14 +00:00
|
|
|
anchors.top: parent.top
|
2020-11-18 18:55:57 +00:00
|
|
|
anchors.topMargin: authorCurrentMsg !== authorPrevMsg ? Style.current.smallPadding : 0
|
2020-07-23 16:11:48 +00:00
|
|
|
height: childrenRect.height + this.anchors.topMargin + (dateGroupLbl.visible ? dateGroupLbl.height : 0)
|
2020-07-15 21:04:14 +00:00
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
DateGroup {
|
|
|
|
id: dateGroupLbl
|
|
|
|
}
|
|
|
|
|
|
|
|
UserImage {
|
|
|
|
id: chatImage
|
2021-04-06 14:59:59 +00:00
|
|
|
active: chatsModel.activeChannel.chatType !== Constants.chatTypeOneToOne && isMessage && headerRepeatCondition && !root.isCurrentUser
|
2020-07-15 21:04:14 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top
|
|
|
|
anchors.topMargin: 20
|
|
|
|
}
|
|
|
|
|
|
|
|
UsernameLabel {
|
|
|
|
id: chatName
|
2021-02-09 14:53:54 +00:00
|
|
|
visible: chatsModel.activeChannel.chatType !== Constants.chatTypeOneToOne && isMessage && headerRepeatCondition && !root.isCurrentUser
|
2020-07-15 21:04:14 +00:00
|
|
|
anchors.leftMargin: 20
|
|
|
|
anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top
|
|
|
|
anchors.topMargin: 0
|
|
|
|
anchors.left: chatImage.right
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
2020-11-18 18:55:57 +00:00
|
|
|
readonly property int defaultMessageWidth: 400
|
|
|
|
readonly property int defaultMaxMessageChars: 54
|
2020-11-20 15:28:32 +00:00
|
|
|
readonly property int messageWidth: Math.max(defaultMessageWidth, parent.width / 1.4)
|
2020-11-18 18:55:57 +00:00
|
|
|
readonly property int maxMessageChars: (defaultMaxMessageChars * messageWidth) / defaultMessageWidth
|
2020-11-17 03:07:01 +00:00
|
|
|
property int chatVerticalPadding: isImage ? 4 : 6
|
2020-11-12 14:08:40 +00:00
|
|
|
property int chatHorizontalPadding: isImage ? 0 : 12
|
2021-02-08 18:46:20 +00:00
|
|
|
property bool longReply: chatReply.active && repliedMessageContent.length > maxMessageChars
|
2020-11-18 18:55:57 +00:00
|
|
|
property bool longChatText: chatsModel.plainText(message).split('\n').some(function (messagePart) {
|
|
|
|
return messagePart.length > maxMessageChars
|
|
|
|
})
|
2020-07-15 21:04:14 +00:00
|
|
|
|
|
|
|
id: chatBox
|
2020-11-12 14:08:40 +00:00
|
|
|
color: {
|
|
|
|
if (isSticker) {
|
|
|
|
return Style.current.background
|
|
|
|
}
|
|
|
|
if (isImage) {
|
|
|
|
return "transparent"
|
|
|
|
}
|
2020-12-07 23:38:53 +00:00
|
|
|
return root.isCurrentUser ? Style.current.primary : Style.current.secondaryBackground
|
2020-11-12 14:08:40 +00:00
|
|
|
}
|
2020-07-15 21:04:14 +00:00
|
|
|
border.color: isSticker ? Style.current.border : Style.current.transparent
|
|
|
|
border.width: 1
|
2020-07-17 19:44:25 +00:00
|
|
|
height: {
|
|
|
|
let h = (3 * chatVerticalPadding)
|
|
|
|
switch(contentType){
|
|
|
|
case Constants.stickerType:
|
|
|
|
h += stickerId.height;
|
|
|
|
break;
|
2020-07-30 16:07:41 +00:00
|
|
|
case Constants.audioType:
|
|
|
|
h += audioPlayerLoader.height;
|
|
|
|
break;
|
2020-07-17 19:44:25 +00:00
|
|
|
default:
|
2020-10-06 15:07:12 +00:00
|
|
|
if (!chatImageContent.active && !chatReply.active) {
|
|
|
|
h -= chatVerticalPadding
|
|
|
|
}
|
|
|
|
|
2020-07-17 19:44:25 +00:00
|
|
|
h += chatText.visible ? chatText.height : 0;
|
2020-10-06 15:07:12 +00:00
|
|
|
h += chatImageContent.active ? chatImageContent.height: 0;
|
|
|
|
h += chatReply.active ? chatReply.height : 0;
|
2020-07-17 19:44:25 +00:00
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
2020-07-15 21:04:14 +00:00
|
|
|
width: {
|
2020-09-30 20:40:54 +00:00
|
|
|
switch(contentType) {
|
2020-07-15 21:04:14 +00:00
|
|
|
case Constants.stickerType:
|
|
|
|
return stickerId.width + (2 * chatBox.chatHorizontalPadding);
|
2020-07-17 19:44:25 +00:00
|
|
|
case Constants.imageType:
|
|
|
|
return chatImageContent.width
|
2020-07-15 21:04:14 +00:00
|
|
|
default:
|
2020-07-20 21:26:29 +00:00
|
|
|
if (longChatText || longReply) {
|
2020-11-18 18:55:57 +00:00
|
|
|
return messageWidth;
|
2020-07-20 21:26:29 +00:00
|
|
|
}
|
|
|
|
let baseWidth = chatText.width;
|
2020-09-30 20:40:54 +00:00
|
|
|
if (chatReply.visible && chatText.width < chatReply.textFieldWidth) {
|
|
|
|
baseWidth = chatReply.textFieldWidth
|
2020-07-20 21:26:29 +00:00
|
|
|
}
|
2020-12-10 20:59:00 +00:00
|
|
|
|
|
|
|
if (chatReply.visible && chatText.width < chatReply.authorWidth) {
|
|
|
|
if(chatReply.authorWidth > baseWidth){
|
|
|
|
baseWidth = chatReply.authorWidth + 20
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-20 21:26:29 +00:00
|
|
|
return baseWidth + 2 * chatHorizontalPadding
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
radius: 16
|
2020-12-07 23:38:53 +00:00
|
|
|
anchors.left: !root.isCurrentUser ? chatImage.right : undefined
|
|
|
|
anchors.leftMargin: !root.isCurrentUser ? 8 : 0
|
|
|
|
anchors.right: !root.isCurrentUser ? undefined : parent.right
|
|
|
|
anchors.rightMargin: !root.isCurrentUser ? 0 : Style.current.padding
|
2021-02-09 14:53:54 +00:00
|
|
|
anchors.top: headerRepeatCondition && !root.isCurrentUser ? chatImage.top : (dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top)
|
2020-08-14 12:08:09 +00:00
|
|
|
anchors.topMargin: 0
|
2021-02-01 18:40:55 +00:00
|
|
|
visible: isMessage && contentType !== Constants.transactionType
|
2020-07-15 21:04:14 +00:00
|
|
|
|
|
|
|
ChatReply {
|
|
|
|
id: chatReply
|
2020-07-20 21:26:29 +00:00
|
|
|
longReply: chatBox.longReply
|
2020-07-15 21:04:14 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: chatReply.visible ? chatBox.chatVerticalPadding : 0
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: chatBox.chatHorizontalPadding
|
2020-12-16 20:50:54 +00:00
|
|
|
container: root.container
|
2021-02-08 18:46:20 +00:00
|
|
|
chatHorizontalPadding: chatBox.chatHorizontalPadding
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ChatText {
|
|
|
|
id: chatText
|
2020-09-25 19:44:40 +00:00
|
|
|
longChatText: chatBox.longChatText
|
2020-07-15 21:04:14 +00:00
|
|
|
anchors.top: chatReply.bottom
|
2020-10-06 15:07:12 +00:00
|
|
|
anchors.topMargin: chatReply.active ? chatBox.chatVerticalPadding : 0
|
2020-07-15 21:04:14 +00:00
|
|
|
anchors.left: parent.left
|
2020-07-20 21:26:29 +00:00
|
|
|
anchors.leftMargin: chatBox.chatHorizontalPadding
|
|
|
|
anchors.right: chatBox.longChatText ? parent.right : undefined
|
|
|
|
anchors.rightMargin: chatBox.longChatText ? chatBox.chatHorizontalPadding : 0
|
2020-12-07 23:38:53 +00:00
|
|
|
textField.color: !root.isCurrentUser ? Style.current.textColor : Style.current.currentUserTextColor
|
2020-12-04 10:38:22 +00:00
|
|
|
Connections {
|
2021-02-10 20:41:00 +00:00
|
|
|
target: appSettings.useCompactMode ? null : chatBox
|
2020-12-04 10:38:22 +00:00
|
|
|
onLongChatTextChanged: {
|
|
|
|
chatText.setWidths()
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 17:34:20 +00:00
|
|
|
Loader {
|
2020-07-17 19:44:25 +00:00
|
|
|
id: chatImageContent
|
2020-09-30 20:40:54 +00:00
|
|
|
active: isImage && !!image
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: Style.current.smallPadding
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: chatBox.chatHorizontalPadding
|
2020-11-27 15:38:58 +00:00
|
|
|
z: 51
|
2020-07-17 19:44:25 +00:00
|
|
|
|
2020-09-30 20:40:54 +00:00
|
|
|
sourceComponent: Component {
|
|
|
|
Item {
|
|
|
|
width: chatImageComponent.width + 2 * chatBox.chatHorizontalPadding
|
|
|
|
height: chatImageComponent.height
|
2020-11-27 15:38:58 +00:00
|
|
|
|
2020-09-30 20:40:54 +00:00
|
|
|
ChatImage {
|
|
|
|
id: chatImageComponent
|
|
|
|
imageSource: image
|
|
|
|
imageWidth: 250
|
2020-12-07 23:38:53 +00:00
|
|
|
isCurrentUser: root.isCurrentUser
|
|
|
|
onClicked: root.clickMessage(false, false, true, image)
|
2020-12-16 20:50:54 +00:00
|
|
|
container: root.container
|
2020-09-30 20:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-20 17:34:20 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-30 16:07:41 +00:00
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: audioPlayerLoader
|
|
|
|
active: isAudio
|
|
|
|
sourceComponent: audioPlayer
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: audioPlayer
|
|
|
|
AudioPlayer {
|
|
|
|
audioSource: audio
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 21:04:14 +00:00
|
|
|
Sticker {
|
|
|
|
id: stickerId
|
|
|
|
anchors.left: parent.left
|
2020-07-20 21:26:29 +00:00
|
|
|
anchors.leftMargin: chatBox.chatHorizontalPadding
|
2020-07-15 21:04:14 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: chatBox.chatVerticalPadding
|
2020-09-23 08:18:23 +00:00
|
|
|
color: Style.current.transparent
|
2020-12-16 20:50:54 +00:00
|
|
|
container: root.container
|
2020-12-07 23:38:53 +00:00
|
|
|
contentType: root.contentType
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageMouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
2020-07-16 14:51:12 +00:00
|
|
|
|
|
|
|
RectangleCorner {
|
|
|
|
// TODO find a way to show the corner for stickers since they have a border
|
2020-07-20 17:34:20 +00:00
|
|
|
visible: isMessage
|
2020-07-16 14:51:12 +00:00
|
|
|
}
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 18:40:55 +00:00
|
|
|
Loader {
|
|
|
|
id: transactionBubbleLoader
|
|
|
|
active: contentType === Constants.transactionType
|
|
|
|
anchors.left: !isCurrentUser ? chatImage.right : undefined
|
|
|
|
anchors.leftMargin: isCurrentUser ? 0 : Style.current.halfPadding
|
|
|
|
anchors.right: isCurrentUser ? parent.right : undefined
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
sourceComponent: Component {
|
|
|
|
TransactionBubble {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 18:51:27 +00:00
|
|
|
Rectangle {
|
|
|
|
id: dateTimeBackground
|
|
|
|
visible: isImage
|
|
|
|
height: visible ? chatTime.height + Style.current.halfPadding : 0
|
|
|
|
width: chatTime.width + 2 * chatTime.anchors.rightMargin +
|
|
|
|
(retry.visible ? retry.width + retry.anchors.rightMargin : sentMessage.width + sentMessage.anchors.rightMargin)
|
|
|
|
color: Utils.setColorAlpha(Style.current.black, 0.66)
|
|
|
|
radius: Style.current.radius
|
|
|
|
anchors.bottom: chatBox.bottom
|
|
|
|
anchors.bottomMargin: Style.current.halfPadding
|
|
|
|
anchors.right: chatBox.right
|
|
|
|
anchors.rightMargin: 6
|
|
|
|
}
|
|
|
|
|
2020-07-15 21:04:14 +00:00
|
|
|
ChatTime {
|
|
|
|
id: chatTime
|
2021-02-08 18:46:20 +00:00
|
|
|
visible: isMessage && !emojiReactionLoader.active
|
2021-01-14 18:51:27 +00:00
|
|
|
anchors.top: isImage ? undefined : (linksLoader.active ? linksLoader.bottom : chatBox.bottom)
|
|
|
|
anchors.topMargin: isImage ? 0 : 4
|
|
|
|
anchors.verticalCenter: isImage ? dateTimeBackground.verticalCenter : undefined
|
|
|
|
anchors.right: isImage ? dateTimeBackground.right : (linksLoader.active ? linksLoader.right : chatBox.right)
|
|
|
|
anchors.rightMargin: isImage ? 6 : (root.isCurrentUser ? 5 : Style.current.padding)
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SentMessage {
|
|
|
|
id: sentMessage
|
2021-01-14 18:51:27 +00:00
|
|
|
visible: root.isCurrentUser && !timeout && !isExpired && isMessage && outgoingStatus === "sent"
|
|
|
|
anchors.verticalCenter: chatTime.verticalCenter
|
2020-07-15 21:04:14 +00:00
|
|
|
anchors.right: chatTime.left
|
|
|
|
anchors.rightMargin: 5
|
|
|
|
}
|
2020-07-14 15:35:21 +00:00
|
|
|
|
|
|
|
Retry {
|
|
|
|
id: retry
|
2021-01-14 18:51:27 +00:00
|
|
|
anchors.verticalCenter: chatTime.verticalCenter
|
2020-07-14 15:35:21 +00:00
|
|
|
anchors.right: chatTime.left
|
|
|
|
anchors.rightMargin: 5
|
|
|
|
}
|
|
|
|
|
2020-10-23 19:46:44 +00:00
|
|
|
Loader {
|
|
|
|
id: linksLoader
|
2020-12-07 23:38:53 +00:00
|
|
|
active: !!root.linkUrls
|
|
|
|
anchors.left: !root.isCurrentUser ? chatImage.right : undefined
|
|
|
|
anchors.leftMargin: !root.isCurrentUser ? 8 : 0
|
|
|
|
anchors.right: !root.isCurrentUser ? undefined : parent.right
|
|
|
|
anchors.rightMargin: !root.isCurrentUser ? 0 : Style.current.padding
|
2020-10-23 19:46:44 +00:00
|
|
|
anchors.top: chatBox.bottom
|
feat: whitelist gifs (no url extension needed)
Fixes #1377.
Fixes #1479.
Two sites have been added to the whitelist: giphy.com and tenor.com.
`imageUrls` in its entirety has been removed and instead all links are being handle through the message `linkUrls`. This prevents double-handling of urls that may or may not be images.
The logic to automatically show links previews works like this:
1. If the setting "display chat images" is enabled, all links that *contain* ".png", ".jpg", ".jpeg", ".svg", ".gif" will be automatically shown. If the URL doesn't contain the extension, we are not downloading it. This was meant to be somewhat of a security compromise as we do not want to download each and every link posted in a message just to find out its true content type.
2. If the above setting is *disabled*, then we follow the whitelist settings for tenor and giphy. This allows us to preview gifs that do not have a file extension in their url.
feat: bump status-go to the commit that supports the new whitelist (https://github.com/status-im/status-go/pull/2094), and also lets us get link preview data from urls in the whitelist. NOTE: this commit was branched off status-go `develop`, so once it is merged, and we update this PR to the new commit, we will effectively be getting status-go develop changes. We *could* base that status-go PR off of master if it makes things easier.
fix: height on settings update issue
feat: move date/time of message below links
fix: layout issues when changing setting `neverAskAboutUnfurlingAgain`
feat: Add MessageBorder component to aid in showing rounded corners with different radius
2020-12-11 00:53:44 +00:00
|
|
|
anchors.topMargin: Style.current.halfPadding
|
|
|
|
anchors.bottomMargin: Style.current.halfPadding
|
2020-10-23 19:46:44 +00:00
|
|
|
|
|
|
|
sourceComponent: Component {
|
2020-12-07 23:38:53 +00:00
|
|
|
LinksMessage {
|
|
|
|
linkUrls: root.linkUrls
|
feat: whitelist gifs (no url extension needed)
Fixes #1377.
Fixes #1479.
Two sites have been added to the whitelist: giphy.com and tenor.com.
`imageUrls` in its entirety has been removed and instead all links are being handle through the message `linkUrls`. This prevents double-handling of urls that may or may not be images.
The logic to automatically show links previews works like this:
1. If the setting "display chat images" is enabled, all links that *contain* ".png", ".jpg", ".jpeg", ".svg", ".gif" will be automatically shown. If the URL doesn't contain the extension, we are not downloading it. This was meant to be somewhat of a security compromise as we do not want to download each and every link posted in a message just to find out its true content type.
2. If the above setting is *disabled*, then we follow the whitelist settings for tenor and giphy. This allows us to preview gifs that do not have a file extension in their url.
feat: bump status-go to the commit that supports the new whitelist (https://github.com/status-im/status-go/pull/2094), and also lets us get link preview data from urls in the whitelist. NOTE: this commit was branched off status-go `develop`, so once it is merged, and we update this PR to the new commit, we will effectively be getting status-go develop changes. We *could* base that status-go PR off of master if it makes things easier.
fix: height on settings update issue
feat: move date/time of message below links
fix: layout issues when changing setting `neverAskAboutUnfurlingAgain`
feat: Add MessageBorder component to aid in showing rounded corners with different radius
2020-12-11 00:53:44 +00:00
|
|
|
container: root.container
|
|
|
|
isCurrentUser: root.isCurrentUser
|
2020-12-07 23:38:53 +00:00
|
|
|
}
|
2020-10-23 19:46:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:01:03 +00:00
|
|
|
Loader {
|
|
|
|
id: emojiReactionLoader
|
|
|
|
active: emojiReactions !== ""
|
|
|
|
sourceComponent: emojiReactionsComponent
|
2021-02-08 18:46:20 +00:00
|
|
|
anchors.left: root.isCurrentUser ? undefined : chatBox.left
|
|
|
|
anchors.right: root.isCurrentUser ? chatBox.right : undefined
|
2021-02-01 18:40:55 +00:00
|
|
|
anchors.leftMargin: root.isCurrentUser ? Style.current.halfPadding : 1
|
2020-08-12 15:01:03 +00:00
|
|
|
anchors.top: chatBox.bottom
|
|
|
|
anchors.topMargin: 2
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: emojiReactionsComponent
|
|
|
|
EmojiReactions {}
|
|
|
|
}
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|