2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-05-28 11:06:17 +00:00
|
|
|
import "../../../../shared"
|
|
|
|
import "../../../../imports"
|
|
|
|
import "../components"
|
2020-09-23 19:03:55 +00:00
|
|
|
import "./"
|
2020-05-28 11:06:17 +00:00
|
|
|
|
2020-07-22 16:24:07 +00:00
|
|
|
ScrollView {
|
2020-05-28 11:06:17 +00:00
|
|
|
property alias channelListCount: chatGroupsListView.count
|
2020-06-18 18:06:02 +00:00
|
|
|
property string searchStr: ""
|
2020-05-28 11:06:17 +00:00
|
|
|
id: chatGroupsContainer
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
2020-07-31 15:25:45 +00:00
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
2020-09-23 19:36:36 +00:00
|
|
|
contentHeight: channelListContent.height
|
2020-09-23 19:03:55 +00:00
|
|
|
clip: true
|
|
|
|
|
2020-09-23 19:11:27 +00:00
|
|
|
Item {
|
2020-09-23 19:36:36 +00:00
|
|
|
id: channelListContent
|
2020-09-23 19:11:27 +00:00
|
|
|
Layout.fillHeight: true
|
2020-09-23 19:03:55 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
height: childrenRect.height
|
2020-05-28 11:06:17 +00:00
|
|
|
|
2020-09-23 19:11:27 +00:00
|
|
|
ListView {
|
|
|
|
id: chatGroupsListView
|
|
|
|
anchors.top: parent.top
|
|
|
|
height: childrenRect.height
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
interactive: false
|
|
|
|
model: chatsModel.chats
|
|
|
|
delegate: Channel {
|
|
|
|
name: model.name
|
|
|
|
muted: model.muted
|
|
|
|
lastMessage: model.lastMessage
|
|
|
|
timestamp: model.timestamp
|
|
|
|
chatType: model.chatType
|
|
|
|
identicon: model.identicon
|
|
|
|
unviewedMessagesCount: model.unviewedMessagesCount
|
|
|
|
hasMentions: model.hasMentions
|
|
|
|
contentType: model.contentType
|
|
|
|
searchStr: chatGroupsContainer.searchStr
|
|
|
|
chatId: model.id
|
|
|
|
}
|
|
|
|
onCountChanged: {
|
|
|
|
if (count > 0 && chatsModel.activeChannelIndex > -1) {
|
|
|
|
// If a chat is added or removed, we set the current index to the first value
|
|
|
|
chatsModel.activeChannelIndex = 0;
|
|
|
|
currentIndex = 0;
|
2020-06-05 14:50:39 +00:00
|
|
|
} else {
|
2020-09-23 19:11:27 +00:00
|
|
|
if(chatsModel.activeChannelIndex > -1){
|
|
|
|
chatGroupsListView.currentIndex = 0;
|
|
|
|
} else {
|
|
|
|
// Initial state. No chat has been selected yet
|
|
|
|
chatGroupsListView.currentIndex = -1;
|
|
|
|
}
|
2020-06-05 14:50:39 +00:00
|
|
|
}
|
2020-05-29 18:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 19:11:27 +00:00
|
|
|
EmptyView {
|
|
|
|
width: parent.width
|
|
|
|
anchors.top: chatGroupsListView.bottom
|
2020-09-23 19:36:36 +00:00
|
|
|
anchors.topMargin: Style.current.smallPadding
|
2020-09-23 19:11:27 +00:00
|
|
|
}
|
2020-09-23 19:03:55 +00:00
|
|
|
|
2020-09-23 19:11:27 +00:00
|
|
|
}
|
2020-09-23 19:03:55 +00:00
|
|
|
|
2020-09-07 16:41:09 +00:00
|
|
|
ProfilePopup {
|
|
|
|
id: profilePopup
|
|
|
|
height: 330
|
|
|
|
noFooter: true
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupInfoPopup {
|
|
|
|
id: groupInfoPopup
|
|
|
|
profileClick: {
|
|
|
|
profilePopup.openPopup.bind(profilePopup)
|
|
|
|
}
|
|
|
|
onClosed: {
|
|
|
|
mouseArea.menuOpened = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 19:05:49 +00:00
|
|
|
PopupMenu {
|
|
|
|
property int channelIndex
|
2020-08-18 15:31:54 +00:00
|
|
|
property bool channelMuted
|
2020-09-07 15:18:42 +00:00
|
|
|
property int chatType
|
2020-09-07 16:41:09 +00:00
|
|
|
property string chatName
|
|
|
|
property string chatId
|
|
|
|
property string chatIdenticon
|
2020-08-03 19:05:49 +00:00
|
|
|
|
|
|
|
id: channelContextMenu
|
|
|
|
width: 175
|
2020-08-04 21:09:24 +00:00
|
|
|
subMenuIcons: [
|
2020-08-18 15:31:54 +00:00
|
|
|
/* { */
|
|
|
|
/* source: Qt.resolvedUrl("../../../img/bell.svg"), */
|
|
|
|
/* width: 16, */
|
|
|
|
/* height: 16 */
|
|
|
|
/* }, */
|
2020-08-04 21:09:24 +00:00
|
|
|
{
|
|
|
|
source: Qt.resolvedUrl("../../../img/fetch.svg"),
|
2020-08-14 12:08:09 +00:00
|
|
|
width: 16,
|
|
|
|
height: 16
|
2020-08-04 21:09:24 +00:00
|
|
|
}
|
|
|
|
]
|
2020-08-03 19:05:49 +00:00
|
|
|
|
2020-09-07 16:41:09 +00:00
|
|
|
function openMenu(channelIndex, muted, chatType, chatName, chatId, chatIdenticon) {
|
2020-08-03 19:05:49 +00:00
|
|
|
channelContextMenu.channelIndex = channelIndex
|
2020-08-18 15:31:54 +00:00
|
|
|
channelContextMenu.channelMuted = muted
|
2020-09-07 15:18:42 +00:00
|
|
|
channelContextMenu.chatType = chatType
|
2020-09-07 16:41:09 +00:00
|
|
|
channelContextMenu.chatName = chatName
|
|
|
|
channelContextMenu.chatId = chatId
|
|
|
|
channelContextMenu.chatIdenticon = chatIdenticon
|
2020-08-03 19:05:49 +00:00
|
|
|
channelContextMenu.popup()
|
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
2020-09-07 16:41:09 +00:00
|
|
|
enabled: channelContextMenu.chatType !== Constants.chatTypePublic
|
|
|
|
text: {
|
|
|
|
if (channelContextMenu.chatType === Constants.chatTypeOneToOne) {
|
2020-09-08 18:22:16 +00:00
|
|
|
//% "View Profile"
|
2020-09-07 16:41:09 +00:00
|
|
|
return qsTrId("view-profile")
|
|
|
|
}
|
|
|
|
if (channelContextMenu.chatType === Constants.chatTypePrivateGroupChat) {
|
2020-09-08 18:22:16 +00:00
|
|
|
//% "View Group"
|
2020-09-07 16:41:09 +00:00
|
|
|
return qsTrId("view-group")
|
|
|
|
}
|
2020-09-08 18:22:16 +00:00
|
|
|
//% "Share Chat"
|
2020-09-07 16:41:09 +00:00
|
|
|
return qsTrId("share-chat")
|
|
|
|
}
|
2020-08-03 19:05:49 +00:00
|
|
|
icon.source: "../../../img/group.svg"
|
2020-08-14 12:08:09 +00:00
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
2020-09-07 16:41:09 +00:00
|
|
|
onTriggered: {
|
|
|
|
chatsModel.setActiveChannelByIndex(channelContextMenu.channelIndex)
|
|
|
|
chatGroupsListView.currentIndex = channelContextMenu.channelIndex
|
|
|
|
if (channelContextMenu.chatType === Constants.chatTypeOneToOne) {
|
|
|
|
return profilePopup.openPopup(channelContextMenu.chatName, channelContextMenu.chatId, channelContextMenu.chatIdenticon)
|
|
|
|
}
|
|
|
|
if (channelContextMenu.chatType === Constants.chatTypePrivateGroupChat) {
|
|
|
|
return groupInfoPopup.open()
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 19:05:49 +00:00
|
|
|
}
|
2020-08-04 21:09:24 +00:00
|
|
|
|
|
|
|
Separator {}
|
|
|
|
|
2020-08-18 15:31:54 +00:00
|
|
|
Action {
|
2020-09-23 19:11:27 +00:00
|
|
|
text: channelContextMenu.channelMuted ?
|
|
|
|
//% "Unmute chat"
|
|
|
|
qsTrId("unmute-chat") :
|
|
|
|
//% "Mute chat"
|
|
|
|
qsTrId("mute-chat")
|
2020-08-18 15:31:54 +00:00
|
|
|
icon.source: "../../../img/bell.svg"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
onTriggered: {
|
2020-09-23 19:11:27 +00:00
|
|
|
if (chatsModel.channelIsMuted(channelContextMenu.channelIndex)) {
|
|
|
|
chatsModel.unmuteChannel(channelContextMenu.channelIndex)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
chatsModel.muteChannel(channelContextMenu.channelIndex)
|
2020-08-18 15:31:54 +00:00
|
|
|
}
|
2020-08-03 19:05:49 +00:00
|
|
|
}
|
2020-08-18 15:31:54 +00:00
|
|
|
|
2020-08-03 19:05:49 +00:00
|
|
|
Action {
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Mark as Read"
|
|
|
|
text: qsTrId("mark-as-read")
|
2020-08-03 19:05:49 +00:00
|
|
|
icon.source: "../../../img/check-circle.svg"
|
2020-08-14 12:08:09 +00:00
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
2020-08-03 19:05:49 +00:00
|
|
|
onTriggered: {
|
|
|
|
chatsModel.markAllChannelMessagesReadByIndex(channelContextMenu.channelIndex)
|
|
|
|
}
|
|
|
|
}
|
2020-08-04 21:09:24 +00:00
|
|
|
PopupMenu {
|
|
|
|
hasArrow: false
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Fetch Messages"
|
|
|
|
title: qsTrId("fetch-messages")
|
2020-08-04 21:09:24 +00:00
|
|
|
|
|
|
|
// TODO call fetch for the wanted duration
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Last 24 hours"
|
|
|
|
Action { text: qsTrId("last-24-hours"); icon.width: 0; }
|
|
|
|
//% "Last 2 days"
|
|
|
|
Action { text: qsTrId("last-2-days"); icon.width: 0; }
|
|
|
|
//% "Last 3 days"
|
|
|
|
Action { text: qsTrId("last-3-days"); icon.width: 0; }
|
|
|
|
//% "Last 7 days"
|
|
|
|
Action { text: qsTrId("last-7-days"); icon.width: 0; }
|
2020-08-03 19:05:49 +00:00
|
|
|
}
|
|
|
|
Action {
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Clear History"
|
|
|
|
text: qsTrId("clear-history")
|
2020-08-03 19:05:49 +00:00
|
|
|
icon.source: "../../../img/close.svg"
|
2020-08-14 12:08:09 +00:00
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
2020-08-03 19:05:49 +00:00
|
|
|
onTriggered: chatsModel.clearChatHistoryByIndex(channelContextMenu.channelIndex)
|
|
|
|
}
|
2020-08-04 21:09:24 +00:00
|
|
|
|
|
|
|
Separator {}
|
|
|
|
|
2020-08-03 19:05:49 +00:00
|
|
|
Action {
|
2020-09-07 15:18:42 +00:00
|
|
|
text: {
|
|
|
|
if (channelContextMenu.chatType === Constants.chatTypeOneToOne) {
|
2020-09-08 18:22:16 +00:00
|
|
|
//% "Delete chat"
|
2020-09-07 15:18:42 +00:00
|
|
|
return qsTrId("delete-chat")
|
|
|
|
}
|
|
|
|
if (channelContextMenu.chatType === Constants.chatTypePrivateGroupChat) {
|
2020-09-08 18:22:16 +00:00
|
|
|
//% "Leave group"
|
2020-09-07 15:18:42 +00:00
|
|
|
return qsTrId("leave-group")
|
|
|
|
}
|
2020-09-08 18:22:16 +00:00
|
|
|
//% "Leave chat"
|
2020-09-07 15:18:42 +00:00
|
|
|
return qsTrId("leave-chat")
|
|
|
|
}
|
|
|
|
icon.source: {
|
|
|
|
if (channelContextMenu.chatType === Constants.chatTypeOneToOne) {
|
|
|
|
return "../../../img/delete.svg"
|
|
|
|
}
|
|
|
|
return "../../../img/leave_chat.svg"
|
|
|
|
}
|
2020-08-14 12:08:09 +00:00
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
2020-08-03 19:05:49 +00:00
|
|
|
onTriggered: chatsModel.leaveChatByIndex(channelContextMenu.channelIndex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 18:24:48 +00:00
|
|
|
Connections {
|
|
|
|
target: chatsModel.chats
|
|
|
|
onDataChanged: {
|
|
|
|
// If the current active channel receives messages and changes its position,
|
|
|
|
// refresh the currentIndex accordingly
|
2020-06-02 20:10:48 +00:00
|
|
|
if(chatsModel.activeChannelIndex !== chatGroupsListView.currentIndex){
|
2020-05-29 18:24:48 +00:00
|
|
|
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
|
2020-05-28 14:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-28 11:06:17 +00:00
|
|
|
}
|
2020-06-22 17:24:01 +00:00
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: chatsModel
|
|
|
|
onActiveChannelChanged: {
|
2020-09-07 11:47:00 +00:00
|
|
|
chatsModel.hideLoadingIndicator()
|
2020-06-22 17:24:01 +00:00
|
|
|
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
|
2020-07-10 22:22:39 +00:00
|
|
|
SelectedMessage.reset();
|
|
|
|
chatColumn.isReply = false;
|
2020-06-22 17:24:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-17 19:18:31 +00:00
|
|
|
}
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;autoSize:true;height:480;width:640}
|
|
|
|
}
|
|
|
|
##^##*/
|