status-desktop/ui/app/AppLayouts/Chat/ChatColumn/Message.qml

339 lines
12 KiB
QML
Raw Normal View History

import QtQuick 2.3
import QtQuick.Controls 2.3
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.3
import Qt.labs.platform 1.1
import "../../../../shared"
import "../../../../shared/xss.js" as XSS
import "../../../../imports"
import "../components"
2020-05-28 19:32:14 +00:00
Item {
property string fromAuthor: "0x0011223344556677889910"
property string userName: "Jotaro Kujo"
property string message: "That's right. We're friends... Of justice, that is."
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
property bool isCurrentUser: false
2020-06-11 17:50:36 +00:00
property string timestamp: "1234567"
property string sticker: "Qme8vJtyrEHxABcSVGPF95PtozDgUyfr1xGjePmFdZgk9v"
property int contentType: 1 // constants don't work in default props
property string chatId: "chatId"
property string authorCurrentMsg: "authorCurrentMsg"
property string authorPrevMsg: "authorPrevMsg"
2020-06-24 19:58:17 +00:00
property bool isEmoji: contentType === Constants.emojiType
property bool isMessage: contentType === Constants.messageType || contentType === Constants.stickerType
property bool isStatusMessage: contentType === Constants.systemMessagePrivateGroupType
2020-06-17 21:43:26 +00:00
property var profileClick: function () {}
width: parent.width
height: {
switch(contentType){
case Constants.chatIdentifier:
return parent.parent.height - 100
case Constants.stickerType:
return stickerId.height + 50
default:
return (isCurrentUser || (!isCurrentUser && authorCurrentMsg == authorPrevMsg) ? chatBox.height : 24 + chatBox.height) + 10
}
}
function linkify(inputText) {
//URLs starting with http://, https://, or ftp://
var replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
2020-06-30 16:30:04 +00:00
var replacedText = inputText.replace(replacePattern1, "<a href='$1'>$1</a>");
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
var replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, "$1<a href='http://$2'>$2</a>");
replacedText = XSS.filterXSS(replacedText)
return replacedText;
}
ProfilePopup {
id: profilePopup
}
Item {
id: channelIdentifier
visible: authorCurrentMsg == ""
anchors.horizontalCenter: parent.horizontalCenter
2020-06-08 22:34:41 +00:00
anchors.verticalCenter: parent.verticalCenter
Rectangle {
id: circleId
anchors.horizontalCenter: parent.horizontalCenter
width: 120
height: 120
radius: 120
border.width: chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne ? 2 : 0
border.color: Theme.grey
color: {
2020-06-09 21:20:42 +00:00
if (chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne) {
return Theme.transparent
}
2020-06-09 21:20:42 +00:00
return chatsModel.activeChannel.color
}
Image {
visible: chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: 120
height: 120
fillMode: Image.PreserveAspectFit
source: chatsModel.activeChannel.identicon
2020-06-23 17:54:16 +00:00
mipmap: true
smooth: false
antialiasing: true
}
StyledText {
visible: chatsModel.activeChannel.chatType != Constants.chatTypeOneToOne
text: (chatsModel.activeChannel.name.charAt(0) == "#" ? chatsModel.activeChannel.name.charAt(1) : chatsModel.activeChannel.name.charAt(0)).toUpperCase()
opacity: 0.7
font.weight: Font.Bold
font.pixelSize: 51
color: "white"
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
}
}
StyledText {
2020-06-10 18:23:18 +00:00
id: channelName
wrapMode: Text.Wrap
text: {
if (chatsModel.activeChannel.chatType != Constants.chatTypePublic) {
return chatsModel.activeChannel.name;
} else {
return "#" + chatsModel.activeChannel.name;
}
}
font.weight: Font.Bold
font.pixelSize: 22
color: Theme.black
anchors.top: circleId.bottom
anchors.topMargin: 16
anchors.horizontalCenter: parent.horizontalCenter
}
2020-06-10 18:23:18 +00:00
Item {
visible: chatsModel.activeChannel.chatType == Constants.chatTypePrivateGroupChat && !chatsModel.activeChannel.isMember(profileModel.profile.pubKey)
2020-06-10 18:23:18 +00:00
anchors.top: channelName.bottom
anchors.topMargin: 16
id: joinOrDecline
StyledText {
2020-06-10 19:41:03 +00:00
id: joinChat
2020-06-10 18:23:18 +00:00
text: qsTr("Join chat")
font.pixelSize: 20
color: Theme.blue
anchors.horizontalCenter: parent.horizontalCenter
MouseArea {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
chatsModel.joinGroup()
}
}
2020-06-10 19:41:03 +00:00
}
StyledText {
2020-06-10 19:41:03 +00:00
text: qsTr("Decline invitation")
font.pixelSize: 20
color: Theme.blue
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: joinChat.bottom
anchors.topMargin: Theme.padding
MouseArea {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
chatsModel.leaveActiveChat()
}
}
2020-06-10 18:23:18 +00:00
}
}
}
// Private group Messages
StyledText {
wrapMode: Text.Wrap
text: message
visible: isStatusMessage
font.pixelSize: 16
color: Theme.darkGrey
width: parent.width - 120
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
textFormat: Text.RichText
}
// Messages
Image {
id: chatImage
2020-05-28 19:32:14 +00:00
width: 36
height: 36
anchors.topMargin: 20
anchors.left: parent.left
anchors.leftMargin: Theme.padding
anchors.top: parent.top
fillMode: Image.PreserveAspectFit
source: identicon
2020-06-24 19:58:17 +00:00
visible: (isMessage || isEmoji) && authorCurrentMsg != authorPrevMsg && !isCurrentUser
2020-06-23 17:54:16 +00:00
mipmap: true
smooth: false
antialiasing: true
MouseArea {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
2020-06-17 21:43:26 +00:00
profileClick(userName, fromAuthor, identicon)
}
}
}
StyledTextEdit {
id: chatName
text: userName
2020-05-28 19:32:14 +00:00
anchors.leftMargin: 20
anchors.top: parent.top
2020-05-28 19:32:14 +00:00
anchors.topMargin: 0
anchors.left: chatImage.right
font.bold: true
font.pixelSize: 14
readOnly: true
wrapMode: Text.WordWrap
selectByMouse: true
2020-06-24 19:58:17 +00:00
visible: (isMessage || isEmoji) && authorCurrentMsg != authorPrevMsg && !isCurrentUser
2020-06-10 18:23:18 +00:00
MouseArea {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
2020-06-17 21:43:26 +00:00
profileClick(userName, fromAuthor, identicon)
2020-06-10 18:23:18 +00:00
}
}
}
2020-05-28 19:32:14 +00:00
Rectangle {
property int chatVerticalPadding: 7
property int chatHorizontalPadding: 12
2020-05-28 19:32:14 +00:00
id: chatBox
height: (2 * chatVerticalPadding) + (contentType == Constants.stickerType ? stickerId.height : chatText.height)
2020-05-28 19:32:14 +00:00
color: isCurrentUser ? Theme.blue : Theme.lightBlue
border.color: Theme.transparent
2020-06-24 19:58:17 +00:00
width: contentType === Constants.stickerType ? (stickerId.width + (2 * chatHorizontalPadding)) : (message.length > 52 ? 380 : chatText.width + 2 * chatHorizontalPadding)
2020-05-28 19:32:14 +00:00
radius: 16
anchors.left: !isCurrentUser ? chatImage.right : undefined
anchors.leftMargin: !isCurrentUser ? 8 : 0
anchors.right: !isCurrentUser ? undefined : parent.right
anchors.rightMargin: !isCurrentUser ? 0 : Theme.padding
anchors.top: authorCurrentMsg != authorPrevMsg && !isCurrentUser ? chatImage.top : parent.top
2020-05-28 19:32:14 +00:00
anchors.topMargin: 0
2020-06-24 19:58:17 +00:00
visible: isMessage || isEmoji
2020-05-28 19:32:14 +00:00
// Thi`s rectangle's only job is to mask the corner to make it less rounded... yep
Rectangle {
color: parent.color
width: 18
height: 18
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.left: !isCurrentUser ? parent.left : undefined
anchors.leftMargin: 0
anchors.right: !isCurrentUser ? undefined : parent.right
anchors.rightMargin: 0
radius: 4
z: -1
}
StyledTextEdit {
2020-05-28 19:32:14 +00:00
id: chatText
textFormat: TextEdit.RichText
2020-06-26 01:23:38 +00:00
text: {
if(contentType === Constants.stickerType) return "";
if (isMessage) return linkify(message);
if(isEmoji){
return Emoji.parse(message, "72x72");
} else {
return Emoji.parse(message, "26x26");
}
}
2020-05-28 19:32:14 +00:00
anchors.left: parent.left
anchors.leftMargin: parent.chatHorizontalPadding
anchors.right: message.length > 52 ? parent.right : undefined
anchors.rightMargin: message.length > 52 ? parent.chatHorizontalPadding : 0
horizontalAlignment: !isCurrentUser ? Text.AlignLeft : Text.AlignRight
2020-06-25 20:17:42 +00:00
wrapMode: Text.Wrap
2020-05-28 19:32:14 +00:00
anchors.top: parent.top
anchors.topMargin: chatBox.chatVerticalPadding
2020-06-26 01:23:38 +00:00
font.pixelSize: 15
2020-05-28 19:32:14 +00:00
readOnly: true
selectByMouse: true
color: !isCurrentUser ? Theme.black : Theme.white
2020-06-24 19:58:17 +00:00
visible: contentType == Constants.messageType || isEmoji
onLinkActivated: {
if(link.startsWith("#")){
chatsModel.joinChat(link.substring(1), Constants.chatTypePublic);
return;
}
Qt.openUrlExternally(link)
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton // we don't want to eat clicks on the Text
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
}
Image {
id: stickerId
horizontalAlignment: !isCurrentUser ? Text.AlignLeft : Text.AlignRight
anchors.left: parent.left
anchors.leftMargin: parent.chatHorizontalPadding
anchors.top: parent.top
anchors.topMargin: chatBox.chatVerticalPadding
width: 140
height: 140
2020-06-24 19:58:17 +00:00
source: contentType === Constants.stickerType ? ("https://ipfs.infura.io/ipfs/" + sticker) : ""
visible: contentType === Constants.stickerType
2020-05-28 19:32:14 +00:00
}
StyledTextEdit {
2020-05-28 19:32:14 +00:00
id: chatTime
color: Theme.darkGrey
text: {
let messageDate = new Date(Math.floor(timestamp))
let minutes = messageDate.getMinutes();
let hours = messageDate.getHours();
return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes)
}
2020-06-24 19:58:17 +00:00
anchors.top: contentType === Constants.stickerType ? stickerId.bottom : chatText.bottom
anchors.topMargin: 8
2020-05-28 19:32:14 +00:00
anchors.bottomMargin: Theme.padding
anchors.right: parent.right
anchors.rightMargin: isCurrentUser ? 5 : Theme.padding
2020-05-28 19:32:14 +00:00
font.pixelSize: 10
readOnly: true
selectByMouse: true
// Probably only want to show this when clicking?
visible: true
2020-05-28 19:32:14 +00:00
}
}
}
/*##^##
Designer {
D{i:0;height:80;width:800}
}
##^##*/