status-desktop/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml

208 lines
7.8 KiB
QML
Raw Normal View History

2020-06-17 19:18:31 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
2020-05-28 11:10:12 +00:00
import "../../../../shared"
import "../../../../shared/status"
2020-05-28 11:10:12 +00:00
import "../../../../imports"
import "../components"
2020-05-28 11:10:12 +00:00
Item {
property string chatId: ""
property string name: "channelName"
property string lastMessage: "My latest message\n with a return"
2020-12-11 20:29:46 +00:00
property string timestamp: "1605212622434"
property string unviewedMessagesCount: "2"
2020-12-11 20:38:10 +00:00
property string identicon
property bool hasMentions: false
property int chatType: Constants.chatTypePublic
property int realChatType: {
if (chatType === Constants.chatTypeCommunity) {
// TODO add a check for private community chats once it is created
return Constants.chatTypePublic
}
return chatType
}
property string searchStr: ""
2021-02-10 20:41:00 +00:00
property bool isCompact: appSettings.useCompactMode
property int contentType: 1
property bool muted: false
property bool hovered: false
2020-12-15 16:04:19 +00:00
property bool enableMouseArea: true
property color color: {
if (ListView.isCurrentItem) {
return Style.current.menuBackgroundActive
}
if (wrapper.hovered) {
return Style.current.menuBackgroundHover
}
return Style.current.transparent
}
property string profileImage: realChatType === Constants.chatTypeOneToOne ? appMain.getProfileImage(chatId) || "" : ""
2020-11-30 17:03:52 +00:00
// Hide the box if it is filtered out
property bool isVisible: searchStr === "" || name.includes(searchStr)
2020-11-30 17:03:52 +00:00
2020-05-28 11:10:12 +00:00
id: wrapper
anchors.right: parent.right
anchors.top: applicationWindow.top
anchors.left: parent.left
visible: isVisible ? true : false
height: isVisible ? rectangle.height + (isCompact ? 4 : Style.current.halfPadding) : 0
2020-05-28 11:10:12 +00:00
Rectangle {
Connections {
enabled: realChatType === Constants.chatTypeOneToOne
target: profileModel.contacts.list
onContactChanged: {
if (pubkey === wrapper.chatId) {
wrapper.profileImage = appMain.getProfileImage(wrapper.chatId)
}
}
}
id: rectangle
color: wrapper.color
radius: 8
height: !isCompact ? 64 : 40
width: parent.width
StatusIdenticon {
id: contactImage
height: !isCompact ? 40 : 28
width: !isCompact ? 40 : 28
chatId: wrapper.chatId
chatName: wrapper.name
chatType: wrapper.realChatType
identicon: wrapper.profileImage || wrapper.identicon
anchors.left: parent.left
anchors.leftMargin: !isCompact ? Style.current.padding : Style.current.smallPadding
anchors.verticalCenter: parent.verticalCenter
}
SVGImage {
id: channelIcon
width: 16
height: 16
fillMode: Image.PreserveAspectFit
source: "../../../img/channel-icon-" + (wrapper.realChatType === Constants.chatTypePublic ? "public-chat.svg" : "group.svg")
anchors.left: contactImage.right
anchors.leftMargin: !isCompact ? Style.current.padding : Style.current.smallPadding
anchors.top: !isCompact ? parent.top : undefined
anchors.topMargin: !isCompact ? Style.current.smallPadding : 0
anchors.verticalCenter: !isCompact ? undefined : parent.verticalCenter
visible: wrapper.realChatType !== Constants.chatTypeOneToOne
}
StyledText {
id: contactInfo
text: wrapper.realChatType !== Constants.chatTypePublic ?
Emoji.parse(Utils.removeStatusEns(Utils.filterXSS(wrapper.name))) :
"#" + Utils.filterXSS(wrapper.name)
anchors.right: contactTime.left
anchors.rightMargin: Style.current.smallPadding
elide: Text.ElideRight
color: muted ? Style.current.secondaryText : Style.current.textColor
font.weight: Font.Medium
font.pixelSize: 15
anchors.left: channelIcon.visible ? channelIcon.right : contactImage.right
anchors.leftMargin: channelIcon.visible ? 2 :
(!isCompact ? Style.current.padding : Style.current.halfPadding)
anchors.top: !isCompact ? parent.top : undefined
anchors.topMargin: !isCompact ? Style.current.smallPadding : 0
anchors.verticalCenter: !isCompact ? undefined : parent.verticalCenter
}
StyledText {
id: lastChatMessage
visible: !isCompact
text: {
switch(contentType){
//% "Image"
2020-08-26 15:52:26 +00:00
case Constants.imageType: return qsTrId("image");
//% "Sticker"
2020-08-26 15:52:26 +00:00
case Constants.stickerType: return qsTrId("sticker");
//% "No messages"
default: return lastMessage ? Emoji.parse(Utils.filterXSS(lastMessage)).replace(/\n|\r/g, ' ') : qsTrId("no-messages")
}
}
textFormat: Text.RichText
clip: true // This is needed because emojis don't ellide correctly
anchors.right: contactNumberChatsCircle.left
anchors.rightMargin: Style.current.smallPadding
elide: Text.ElideRight
anchors.bottom: parent.bottom
anchors.bottomMargin: Style.current.smallPadding
font.pixelSize: 15
anchors.left: contactImage.right
anchors.leftMargin: Style.current.padding
color: Style.current.secondaryText
}
StyledText {
id: contactTime
visible: !isCompact
text: Utils.formatDateTime(wrapper.timestamp, globalSettings.locale)
anchors.right: parent.right
anchors.rightMargin: Style.current.padding
anchors.top: parent.top
anchors.topMargin: Style.current.smallPadding
font.pixelSize: 11
color: Style.current.secondaryText
2020-05-28 11:10:12 +00:00
}
Rectangle {
id: contactNumberChatsCircle
width: 22
height: 22
radius: 50
anchors.right: parent.right
anchors.rightMargin: !isCompact ? Style.current.padding : Style.current.smallPadding
anchors.bottom: !isCompact ? parent.bottom : undefined
anchors.bottomMargin: !isCompact ? Style.current.smallPadding : 0
anchors.verticalCenter: !isCompact ? undefined : parent.verticalCenter
color: Style.current.blue
visible: (unviewedMessagesCount > 0) || wrapper.hasMentions
StyledText {
id: contactNumberChats
text: wrapper.hasMentions ? '@' : (wrapper.unviewedMessagesCount < 100 ? wrapper.unviewedMessagesCount : "99+")
font.pixelSize: 12
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
color: Style.current.white
}
}
MouseArea {
enabled: enableMouseArea
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton
anchors.fill: parent
hoverEnabled: true
onEntered: {
wrapper.hovered = true
}
onExited: {
wrapper.hovered = false
}
onClicked: {
if (mouse.button & Qt.RightButton) {
chatsModel.setContextChannel(chatId)
channelContextMenu.openMenu(chatsModel.contextChannel, index)
return;
}
chatGroupsListView.currentIndex = index
chatsModel.setActiveChannelByIndex(index)
}
}
}
2020-05-28 11:10:12 +00:00
}
2020-06-17 19:18:31 +00:00
2020-06-17 19:18:31 +00:00
/*##^##
Designer {
D{i:0;formeditorColor:"#ffffff";height:64;width:640}
2020-06-17 19:18:31 +00:00
}
##^##*/