2020-05-27 22:59:17 +00:00
import QtQuick 2.3
import QtQuick . Controls 2.3
import QtQuick . Controls 2.12 as QQC2
import QtQuick . Layouts 1.3
import Qt . labs . platform 1.1
import "../../../../shared"
import "../../../../imports"
2020-06-04 10:30:49 +00:00
import "../components"
2020-05-27 22:59:17 +00:00
2020-05-28 19:32:14 +00:00
Item {
2020-05-28 15:55:52 +00:00
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
property int timestamp: 1234567
2020-05-28 21:34:04 +00:00
property string sticker: "Qme8vJtyrEHxABcSVGPF95PtozDgUyfr1xGjePmFdZgk9v"
property int contentType: 1 // constants don't work in default props
2020-06-08 17:29:28 +00:00
property string chatId: "chatId"
2020-05-28 15:55:52 +00:00
2020-06-05 22:20:45 +00:00
property string authorCurrentMsg: "authorCurrentMsg"
property string authorPrevMsg: "authorPrevMsg"
2020-05-27 22:59:17 +00:00
2020-06-10 15:14:12 +00:00
property bool isMessage: contentType == Constants . messageType || contentType == Constants . stickerType || contentType == Constants . emojiType
property bool isStatusMessage: contentType == Constants . systemMessagePrivateGroupType
2020-06-05 22:20:45 +00:00
width: parent . width
2020-06-08 17:29:28 +00:00
height: {
switch ( contentType ) {
case Constants.chatIdentifier:
2020-06-09 15:48:17 +00:00
return parent . parent . height - 100
2020-06-08 17:29:28 +00:00
case Constants.stickerType:
return stickerId . height + 50
default:
return ( isCurrentUser || ( ! isCurrentUser && authorCurrentMsg == authorPrevMsg ) ? chatBox.height : 24 + chatBox . height )
}
}
2020-06-04 10:30:49 +00:00
ProfilePopup {
id: profilePopup
}
2020-06-08 17:29:28 +00:00
Item {
id: channelIdentifier
visible: authorCurrentMsg == ""
anchors.horizontalCenter: parent . horizontalCenter
2020-06-08 22:34:41 +00:00
anchors.verticalCenter: parent . verticalCenter
2020-06-08 17:29:28 +00:00
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 ) {
2020-06-08 17:29:28 +00:00
return Theme . transparent
}
2020-06-09 21:20:42 +00:00
return chatsModel . activeChannel . color
2020-06-08 17:29:28 +00:00
}
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
}
Text {
visible: chatsModel . activeChannel . chatType != Constants . chatTypeOneToOne
2020-06-09 15:48:17 +00:00
text: ( chatsModel . activeChannel . name . charAt ( 0 ) == "#" ? chatsModel . activeChannel . name . charAt ( 1 ) : chatsModel . activeChannel . name . charAt ( 0 ) ) . toUpperCase ( )
2020-06-08 17:29:28 +00:00
opacity: 0.7
font.weight: Font . Bold
font.pixelSize: 51
color: "white"
anchors.horizontalCenter: parent . horizontalCenter
anchors.verticalCenter: parent . verticalCenter
}
}
Text {
2020-06-10 18:23:18 +00:00
id: channelName
2020-06-08 17:29:28 +00:00
wrapMode: Text . Wrap
text: {
2020-06-09 15:48:17 +00:00
if ( chatsModel . activeChannel . chatType != Constants . chatTypePublic ) {
2020-06-08 17:29:28 +00:00
return chatsModel . activeChannel . name ;
} else {
2020-06-09 15:48:17 +00:00
return "#" + chatsModel . activeChannel . name ;
2020-06-08 17:29:28 +00:00
}
}
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 // TODO: hide if the user is a member of the group (use chatsModel.activeChannel.isMember?)
anchors.top: channelName . bottom
anchors.topMargin: 16
id: joinOrDecline
Text {
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
}
Text {
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
}
}
2020-06-08 17:29:28 +00:00
}
2020-06-10 15:14:12 +00:00
// Private group Messages
Text {
wrapMode: Text . Wrap
text: message
visible: isStatusMessage
font.pixelSize: 16
color: Theme . darkGrey
width: parent . width - 120
horizontalAlignment: Text . AlignHCenter
anchors.horizontalCenter: parent . horizontalCenter
}
// Messages
2020-05-27 22:59:17 +00:00
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
2020-05-27 22:59:17 +00:00
anchors.top: parent . top
fillMode: Image . PreserveAspectFit
source: identicon
2020-06-10 15:14:12 +00:00
visible: isMessage && authorCurrentMsg != authorPrevMsg && ! isCurrentUser
2020-06-04 10:30:49 +00:00
MouseArea {
cursorShape: Qt . PointingHandCursor
anchors.fill: parent
onClicked: {
profilePopup . open ( )
}
}
2020-05-27 22:59:17 +00:00
}
TextEdit {
id: chatName
text: userName
2020-05-28 19:32:14 +00:00
anchors.leftMargin: 20
2020-05-27 22:59:17 +00:00
anchors.top: parent . top
2020-05-28 19:32:14 +00:00
anchors.topMargin: 0
anchors.left: chatImage . right
2020-05-27 22:59:17 +00:00
font.bold: true
font.pixelSize: 14
readOnly: true
wrapMode: Text . WordWrap
selectByMouse: true
2020-06-10 15:14:12 +00:00
visible: isMessage && authorCurrentMsg != authorPrevMsg && ! isCurrentUser
2020-06-10 18:23:18 +00:00
MouseArea {
cursorShape: Qt . PointingHandCursor
anchors.fill: parent
onClicked: {
profilePopup . open ( )
}
}
2020-05-27 22:59:17 +00:00
}
2020-05-28 19:32:14 +00:00
Rectangle {
property int chatVerticalPadding: 7
property int chatHorizontalPadding: 12
2020-05-27 22:59:17 +00:00
2020-05-28 19:32:14 +00:00
id: chatBox
2020-05-28 21:34:04 +00:00
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-05-28 21:34:04 +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
2020-06-05 22:20:45 +00:00
anchors.top: authorCurrentMsg != authorPrevMsg && ! isCurrentUser ? chatImage.top : parent . top
2020-05-28 19:32:14 +00:00
anchors.topMargin: 0
2020-06-10 15:14:12 +00:00
visible: isMessage
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
}
TextEdit {
id: chatText
text: message
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
font.family: "Inter"
wrapMode: Text . WordWrap
anchors.top: parent . top
anchors.topMargin: chatBox . chatVerticalPadding
font.pixelSize: 15
readOnly: true
selectByMouse: true
color: ! isCurrentUser ? Theme.black : Theme . white
2020-05-28 21:34:04 +00:00
visible: contentType == Constants . messageType
}
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
source: contentType == Constants . stickerType ? ( "https://ipfs.infura.io/ipfs/" + sticker ) : ""
visible: contentType == Constants . stickerType
2020-05-28 19:32:14 +00:00
}
TextEdit {
id: chatTime
color: Theme . darkGrey
font.family: "Inter"
text: timestamp
2020-05-28 21:34:04 +00:00
anchors.top: contentType == Constants . stickerType ? stickerId.bottom : chatText . bottom
2020-05-28 19:32:14 +00:00
anchors.bottomMargin: Theme . padding
anchors.right: ! isCurrentUser ? parent.right : undefined
anchors.rightMargin: ! isCurrentUser ? Theme.padding : 0
anchors.left: ! isCurrentUser ? undefined : parent . left
anchors.leftMargin: ! isCurrentUser ? 0 : Theme . padding
font.pixelSize: 10
readOnly: true
selectByMouse: true
// Probably only want to show this when clicking?
visible: false
}
2020-05-27 22:59:17 +00:00
}
}
2020-05-28 15:55:52 +00:00
/ * # # ^ # #
Designer {
2020-05-28 21:34:04 +00:00
D { i: 0 ; height: 80 ; width: 800 }
2020-05-28 15:55:52 +00:00
}
# # ^ # # * /
2020-05-28 19:32:14 +00:00