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"
|
2020-09-22 14:45:09 +00:00
|
|
|
import "../../../../shared/status"
|
2020-05-28 11:10:12 +00:00
|
|
|
import "../../../../imports"
|
2020-06-02 09:54:46 +00:00
|
|
|
import "../components"
|
2020-05-28 11:10:12 +00:00
|
|
|
|
|
|
|
Rectangle {
|
2020-09-07 16:41:09 +00:00
|
|
|
property string chatId: ""
|
2020-06-18 18:06:02 +00:00
|
|
|
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"
|
2020-06-19 19:03:43 +00:00
|
|
|
property string unviewedMessagesCount: "2"
|
2020-12-11 20:38:10 +00:00
|
|
|
property string identicon
|
2020-07-09 11:46:25 +00:00
|
|
|
property bool hasMentions: false
|
2020-06-19 19:03:43 +00:00
|
|
|
property int chatType: Constants.chatTypePublic
|
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-06-18 18:06:02 +00:00
|
|
|
property string searchStr: ""
|
2021-02-10 20:41:00 +00:00
|
|
|
property bool isCompact: appSettings.useCompactMode
|
2020-07-17 19:44:25 +00:00
|
|
|
property int contentType: 1
|
2020-08-18 15:31:54 +00:00
|
|
|
property bool muted: false
|
2020-10-14 08:00:29 +00:00
|
|
|
property bool hovered: false
|
2020-12-15 16:04:19 +00:00
|
|
|
property bool enableMouseArea: true
|
2020-06-18 18:06:02 +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
|
|
|
|
|
|
|
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 === wrapper.chatId) {
|
2020-12-21 12:08:44 +00:00
|
|
|
wrapper.profileImage = appMain.getProfileImage(wrapper.chatId)
|
2020-11-30 17:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:10:12 +00:00
|
|
|
id: wrapper
|
2020-10-14 08:00:29 +00:00
|
|
|
color: {
|
2021-01-22 10:21:24 +00:00
|
|
|
if (ListView.isCurrentItem) {
|
2020-10-14 08:00:29 +00:00
|
|
|
return Style.current.secondaryBackground
|
|
|
|
}
|
2021-01-22 10:21:24 +00:00
|
|
|
if (wrapper.hovered) {
|
|
|
|
return Style.current.backgroundHover
|
|
|
|
}
|
2020-10-14 08:00:29 +00:00
|
|
|
return Style.current.transparent
|
|
|
|
}
|
2020-05-28 11:10:12 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.top: applicationWindow.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
radius: 8
|
|
|
|
// Hide the box if it is filtered out
|
2020-12-28 20:03:57 +00:00
|
|
|
property bool isVisible: searchStr === "" || name.includes(searchStr)
|
2020-05-28 11:10:12 +00:00
|
|
|
visible: isVisible ? true : false
|
2021-02-01 18:40:55 +00:00
|
|
|
height: isVisible ? (!isCompact ? 64 : 40) : 0
|
2020-05-28 11:10:12 +00:00
|
|
|
|
2020-09-22 14:45:09 +00:00
|
|
|
StatusIdenticon {
|
|
|
|
id: contactImage
|
2021-02-01 18:40:55 +00:00
|
|
|
height: !isCompact ? 40 : 28
|
|
|
|
width: !isCompact ? 40 : 28
|
2021-03-02 20:43:32 +00:00
|
|
|
chatId: wrapper.chatId
|
2020-09-22 14:45:09 +00:00
|
|
|
chatName: wrapper.name
|
2021-03-03 17:36:18 +00:00
|
|
|
chatType: wrapper.realChatType
|
2020-11-30 17:03:52 +00:00
|
|
|
identicon: wrapper.profileImage || wrapper.identicon
|
2020-09-22 14:45:09 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: !isCompact ? Style.current.padding : Style.current.smallPadding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2020-05-28 11:10:12 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 13:23:17 +00:00
|
|
|
SVGImage {
|
2020-06-12 01:00:28 +00:00
|
|
|
id: channelIcon
|
|
|
|
width: 16
|
|
|
|
height: 16
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2021-03-03 17:36:18 +00:00
|
|
|
source: "../../../img/channel-icon-" + (wrapper.realChatType === Constants.chatTypePublic ? "public-chat.svg" : "group.svg")
|
2020-06-12 01:00:28 +00:00
|
|
|
anchors.left: contactImage.right
|
2021-02-01 18:40:55 +00:00
|
|
|
anchors.leftMargin: !isCompact ? Style.current.padding : Style.current.smallPadding
|
2020-07-15 16:09:20 +00:00
|
|
|
anchors.top: !isCompact ? parent.top : undefined
|
|
|
|
anchors.topMargin: !isCompact ? Style.current.smallPadding : 0
|
|
|
|
anchors.verticalCenter: !isCompact ? undefined : parent.verticalCenter
|
2021-03-03 17:36:18 +00:00
|
|
|
visible: wrapper.realChatType !== Constants.chatTypeOneToOne
|
2020-06-12 01:00:28 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-05-28 11:10:12 +00:00
|
|
|
id: contactInfo
|
2021-03-03 17:36:18 +00:00
|
|
|
text: wrapper.realChatType !== Constants.chatTypePublic ?
|
2020-11-17 03:07:01 +00:00
|
|
|
Emoji.parse(Utils.removeStatusEns(Utils.filterXSS(wrapper.name))) :
|
2020-11-05 20:11:59 +00:00
|
|
|
"#" + Utils.filterXSS(wrapper.name)
|
2020-05-28 11:10:12 +00:00
|
|
|
anchors.right: contactTime.left
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
2020-05-28 11:10:12 +00:00
|
|
|
elide: Text.ElideRight
|
2021-01-15 18:36:42 +00:00
|
|
|
color: muted ? Style.current.secondaryText : Style.current.textColor
|
2020-05-28 11:10:12 +00:00
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 15
|
2020-06-12 01:00:28 +00:00
|
|
|
anchors.left: channelIcon.visible ? channelIcon.right : contactImage.right
|
2021-02-01 18:40:55 +00:00
|
|
|
anchors.leftMargin: channelIcon.visible ? 2 :
|
|
|
|
(!isCompact ? Style.current.padding : Style.current.halfPadding)
|
2020-07-15 16:09:20 +00:00
|
|
|
anchors.top: !isCompact ? parent.top : undefined
|
|
|
|
anchors.topMargin: !isCompact ? Style.current.smallPadding : 0
|
|
|
|
anchors.verticalCenter: !isCompact ? undefined : parent.verticalCenter
|
2020-05-28 11:10:12 +00:00
|
|
|
}
|
2020-06-09 15:48:17 +00:00
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-05-28 11:10:12 +00:00
|
|
|
id: lastChatMessage
|
2020-07-15 16:09:20 +00:00
|
|
|
visible: !isCompact
|
2020-07-17 19:44:25 +00:00
|
|
|
text: {
|
2020-07-20 20:17:05 +00:00
|
|
|
switch(contentType){
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Image"
|
|
|
|
case Constants.imageType: return qsTrId("image");
|
|
|
|
//% "Sticker"
|
|
|
|
case Constants.stickerType: return qsTrId("sticker");
|
2020-09-22 07:53:03 +00:00
|
|
|
//% "No messages"
|
2020-11-17 03:07:01 +00:00
|
|
|
default: return lastMessage ? Emoji.parse(Utils.filterXSS(lastMessage)).replace(/\n|\r/g, ' ') : qsTrId("no-messages")
|
2020-07-17 19:44:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-05 23:22:52 +00:00
|
|
|
textFormat: Text.RichText
|
2020-07-06 15:03:41 +00:00
|
|
|
clip: true // This is needed because emojis don't ellide correctly
|
2020-05-28 11:10:12 +00:00
|
|
|
anchors.right: contactNumberChatsCircle.left
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
2020-05-28 11:10:12 +00:00
|
|
|
elide: Text.ElideRight
|
|
|
|
anchors.bottom: parent.bottom
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.bottomMargin: Style.current.smallPadding
|
2020-05-28 11:10:12 +00:00
|
|
|
font.pixelSize: 15
|
|
|
|
anchors.left: contactImage.right
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.leftMargin: Style.current.padding
|
2021-02-19 15:20:26 +00:00
|
|
|
color: Style.current.secondaryText
|
2020-05-28 11:10:12 +00:00
|
|
|
}
|
2020-07-15 16:09:20 +00:00
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-05-28 11:10:12 +00:00
|
|
|
id: contactTime
|
2021-02-01 18:40:55 +00:00
|
|
|
visible: !isCompact
|
2021-01-04 14:47:25 +00:00
|
|
|
text: Utils.formatDateTime(wrapper.timestamp, appSettings.locale)
|
2020-12-22 10:22:04 +00:00
|
|
|
anchors.right: parent.right
|
2021-02-01 18:40:55 +00:00
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: Style.current.smallPadding
|
2020-12-22 10:22:04 +00:00
|
|
|
font.pixelSize: 11
|
2021-02-19 15:20:26 +00:00
|
|
|
color: Style.current.secondaryText
|
2020-05-28 11:10:12 +00:00
|
|
|
}
|
|
|
|
Rectangle {
|
|
|
|
id: contactNumberChatsCircle
|
|
|
|
width: 22
|
|
|
|
height: 22
|
|
|
|
radius: 50
|
2021-02-01 18:40:55 +00:00
|
|
|
anchors.right: parent.right
|
2020-07-15 16:09:20 +00:00
|
|
|
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
|
2020-07-02 15:14:31 +00:00
|
|
|
color: Style.current.blue
|
2020-07-09 11:46:25 +00:00
|
|
|
visible: (unviewedMessagesCount > 0) || wrapper.hasMentions
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-05-28 11:10:12 +00:00
|
|
|
id: contactNumberChats
|
2020-12-02 19:28:13 +00:00
|
|
|
text: wrapper.hasMentions ? '@' : (wrapper.unviewedMessagesCount < 100 ? wrapper.unviewedMessagesCount : "99+")
|
2020-06-19 18:21:02 +00:00
|
|
|
font.pixelSize: 12
|
2020-05-28 11:10:12 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2020-07-15 16:09:20 +00:00
|
|
|
color: Style.current.white
|
2020-05-28 11:10:12 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-14 08:00:29 +00:00
|
|
|
|
|
|
|
MouseArea {
|
2020-12-15 16:04:19 +00:00
|
|
|
enabled: enableMouseArea
|
|
|
|
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
2020-10-14 08:00:29 +00:00
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: {
|
|
|
|
wrapper.hovered = true
|
|
|
|
}
|
|
|
|
onExited: {
|
|
|
|
wrapper.hovered = false
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
if (mouse.button & Qt.RightButton) {
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
chatsModel.setContextChannel(chatId)
|
|
|
|
channelContextMenu.openMenu(chatsModel.contextChannel, index)
|
2020-10-14 08:00:29 +00:00
|
|
|
return;
|
|
|
|
}
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
chatGroupsListView.currentIndex = index
|
2021-02-22 18:05:23 +00:00
|
|
|
chatsModel.setActiveChannelByIndex(index)
|
2020-10-14 08:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:10:12 +00:00
|
|
|
}
|
2020-06-17 19:18:31 +00:00
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
2020-06-18 18:06:02 +00:00
|
|
|
D{i:0;formeditorColor:"#ffffff";height:64;width:640}
|
2020-06-17 19:18:31 +00:00
|
|
|
}
|
|
|
|
##^##*/
|