2020-09-22 14:50:14 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
2021-01-15 18:36:42 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
2020-09-22 14:50:14 +00:00
|
|
|
import "../../imports"
|
|
|
|
import "../../shared"
|
|
|
|
import "../../shared/status"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
2020-10-02 19:25:33 +00:00
|
|
|
property string chatId
|
2020-09-22 14:50:14 +00:00
|
|
|
property string chatName
|
|
|
|
property int chatType
|
2021-03-03 17:36:18 +00:00
|
|
|
property int realChatType: {
|
|
|
|
if (chatType === Constants.chatTypeCommunity) {
|
|
|
|
// TODO add a check for private community chats once it is created
|
|
|
|
return Constants.chatTypePublic
|
|
|
|
}
|
|
|
|
return chatType
|
|
|
|
}
|
2020-09-22 14:50:14 +00:00
|
|
|
property string identicon
|
|
|
|
property int identiconSize: 40
|
|
|
|
property bool isCompact: false
|
2021-01-15 18:36:42 +00:00
|
|
|
property bool muted: false
|
2020-09-22 14:50:14 +00:00
|
|
|
|
2021-03-03 17:36:18 +00:00
|
|
|
property string profileImage: realChatType === Constants.chatTypeOneToOne ? appMain.getProfileImage(chatId) || "" : ""
|
2020-11-30 17:03:52 +00:00
|
|
|
|
2020-09-22 14:50:14 +00:00
|
|
|
height: 48
|
|
|
|
width: nameAndInfo.width + chatIdenticon.width + Style.current.smallPadding
|
|
|
|
|
2020-11-30 17:03:52 +00:00
|
|
|
Connections {
|
2021-03-03 17:36:18 +00:00
|
|
|
enabled: realChatType === Constants.chatTypeOneToOne
|
2020-11-30 17:03:52 +00:00
|
|
|
target: profileModel.contacts.list
|
|
|
|
onContactChanged: {
|
|
|
|
if (pubkey === root.chatId) {
|
2020-12-21 12:08:44 +00:00
|
|
|
root.profileImage = appMain.getProfileImage(root.chatId)
|
2020-11-30 17:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 14:50:14 +00:00
|
|
|
StatusIdenticon {
|
|
|
|
id: chatIdenticon
|
2021-03-03 17:36:18 +00:00
|
|
|
chatType: root.realChatType
|
2021-03-02 20:43:32 +00:00
|
|
|
chatId: root.chatId
|
2020-09-22 14:50:14 +00:00
|
|
|
chatName: root.chatName
|
2020-11-30 17:03:52 +00:00
|
|
|
identicon: root.profileImage || root.identicon
|
2020-09-22 14:50:14 +00:00
|
|
|
width: root.isCompact ? 20 : root.identiconSize
|
|
|
|
height: root.isCompact ? 20 : root.identiconSize
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: nameAndInfo
|
|
|
|
height: chatName.height + chatInfo.height
|
2021-01-21 12:20:34 +00:00
|
|
|
width: childrenRect.width
|
2020-09-22 14:50:14 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: chatIdenticon.right
|
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: chatName
|
|
|
|
text: {
|
2021-03-03 17:36:18 +00:00
|
|
|
switch(root.realChatType) {
|
2020-09-22 14:50:14 +00:00
|
|
|
case Constants.chatTypePublic: return "#" + root.chatName;
|
|
|
|
case Constants.chatTypeOneToOne: return Utils.removeStatusEns(root.chatName)
|
|
|
|
default: return root.chatName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
|
2021-01-15 18:36:42 +00:00
|
|
|
SVGImage {
|
|
|
|
property bool hovered: false
|
|
|
|
|
|
|
|
id: bellImg
|
|
|
|
visible: root.muted
|
|
|
|
source: "../../app/img/bell-disabled.svg"
|
|
|
|
anchors.verticalCenter: chatName.verticalCenter
|
|
|
|
anchors.left: chatName.right
|
|
|
|
anchors.leftMargin: 4
|
|
|
|
width: 12.5
|
|
|
|
height: 12.5
|
|
|
|
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: parent
|
|
|
|
source: parent
|
|
|
|
color: bellImg.hovered ? Style.current.textColor : Style.current.darkGrey
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: bellImg.hovered = true
|
|
|
|
onExited: bellImg.hovered = false
|
|
|
|
onClicked: {
|
|
|
|
chatsModel.unmuteCurrentChannel()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 19:25:33 +00:00
|
|
|
|
|
|
|
Connections {
|
2020-12-06 22:15:51 +00:00
|
|
|
target: profileModel.contacts
|
2020-10-02 19:25:33 +00:00
|
|
|
onContactChanged: {
|
|
|
|
if(root.chatId === publicKey){
|
|
|
|
// Hack warning: Triggering reload to avoid changing the current text binding
|
|
|
|
var tmp = chatId;
|
|
|
|
chatId = "";
|
|
|
|
chatId = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 14:50:14 +00:00
|
|
|
StyledText {
|
|
|
|
id: chatInfo
|
2021-02-18 19:07:23 +00:00
|
|
|
color: Style.current.secondaryText
|
2020-09-22 14:50:14 +00:00
|
|
|
text: {
|
2021-03-03 17:36:18 +00:00
|
|
|
switch(root.realChatType){
|
2020-09-22 14:50:14 +00:00
|
|
|
//% "Public chat"
|
|
|
|
case Constants.chatTypePublic: return qsTrId("public-chat")
|
2020-12-06 22:15:51 +00:00
|
|
|
case Constants.chatTypeOneToOne: return (profileModel.contacts.isAdded(root.chatId) ?
|
2020-09-22 14:50:14 +00:00
|
|
|
//% "Contact"
|
|
|
|
qsTrId("chat-is-a-contact") :
|
|
|
|
//% "Not a contact"
|
|
|
|
qsTrId("chat-is-not-a-contact"))
|
|
|
|
case Constants.chatTypePrivateGroupChat:
|
|
|
|
let cnt = chatsModel.activeChannel.members.rowCount();
|
|
|
|
//% "%1 members"
|
|
|
|
if(cnt > 1) return qsTrId("%1-members").arg(cnt);
|
|
|
|
//% "1 member"
|
|
|
|
return qsTrId("1-member");
|
|
|
|
default: return "...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
font.pixelSize: 12
|
|
|
|
anchors.top: chatName.bottom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|