2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-05-27 21:59:34 +00:00
|
|
|
import "../../../../shared"
|
2020-09-22 14:45:09 +00:00
|
|
|
import "../../../../shared/status"
|
2020-05-27 21:59:34 +00:00
|
|
|
import "../../../../imports"
|
2020-06-02 09:54:46 +00:00
|
|
|
import "../components"
|
2020-05-27 21:59:34 +00:00
|
|
|
|
|
|
|
Rectangle {
|
2020-08-14 12:08:09 +00:00
|
|
|
property int iconSize: 16
|
2020-05-27 21:59:34 +00:00
|
|
|
id: chatTopBarContent
|
2020-07-13 18:45:54 +00:00
|
|
|
color: Style.current.background
|
2020-05-27 21:59:34 +00:00
|
|
|
height: 56
|
|
|
|
Layout.fillWidth: true
|
2020-07-13 18:45:54 +00:00
|
|
|
border.color: Style.current.border
|
2020-05-27 21:59:34 +00:00
|
|
|
border.width: 1
|
|
|
|
|
2020-09-22 14:50:14 +00:00
|
|
|
Loader {
|
|
|
|
property bool isGroupChatOrOneToOne: (chatsModel.activeChannel.chatType === Constants.chatTypePrivateGroupChat ||
|
|
|
|
chatsModel.activeChannel.chatType === Constants.chatTypeOneToOne)
|
2020-07-15 16:09:20 +00:00
|
|
|
anchors.left: parent.left
|
2020-09-22 14:50:14 +00:00
|
|
|
anchors.leftMargin: this.isGroupChatOrOneToOne ? Style.current.padding : Style.current.padding + 4
|
2020-07-15 16:09:20 +00:00
|
|
|
anchors.top: parent.top
|
2020-09-22 14:50:14 +00:00
|
|
|
anchors.topMargin: 4
|
|
|
|
sourceComponent: this.isGroupChatOrOneToOne ? chatInfoButton : chatInfo
|
2020-05-27 21:59:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 14:50:14 +00:00
|
|
|
Component {
|
|
|
|
id: chatInfoButton
|
|
|
|
StatusChatInfoButton {
|
2020-10-02 19:25:33 +00:00
|
|
|
chatId: chatsModel.activeChannel.id
|
2020-09-22 14:50:14 +00:00
|
|
|
chatName: chatsModel.activeChannel.name
|
|
|
|
chatType: chatsModel.activeChannel.chatType
|
|
|
|
identicon: chatsModel.activeChannel.identicon
|
2021-01-15 18:36:42 +00:00
|
|
|
muted: chatsModel.activeChannel.muted
|
2020-09-22 14:50:14 +00:00
|
|
|
identiconSize: 36
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
switch (chatsModel.activeChannel.chatType) {
|
|
|
|
case Constants.chatTypePrivateGroupChat:
|
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
|
|
|
groupInfoPopup.openMenu(chatsModel.activeChannel, chatsModel.getActiveChannelIdx())
|
2020-09-22 14:50:14 +00:00
|
|
|
break;
|
|
|
|
case Constants.chatTypeOneToOne:
|
2020-12-21 12:08:44 +00:00
|
|
|
const profileImage = appMain.getProfileImage(chatsModel.activeChannel.id)
|
2020-11-30 17:03:52 +00:00
|
|
|
openProfilePopup(chatsModel.activeChannel.name, chatsModel.activeChannel.id, profileImage || chatsModel.activeChannel.identicon)
|
2020-09-22 14:50:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-08-07 19:26:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-27 21:59:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 14:50:14 +00:00
|
|
|
Component {
|
|
|
|
id: chatInfo
|
|
|
|
StatusChatInfo {
|
|
|
|
identiconSize: 36
|
|
|
|
chatName: chatsModel.activeChannel.name
|
|
|
|
chatType: chatsModel.activeChannel.chatType
|
|
|
|
identicon: chatsModel.activeChannel.identicon
|
2021-01-15 18:36:42 +00:00
|
|
|
muted: chatsModel.activeChannel.muted
|
2020-06-09 15:48:17 +00:00
|
|
|
}
|
2020-05-27 21:59:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 14:50:14 +00:00
|
|
|
|
2020-07-09 17:56:31 +00:00
|
|
|
Rectangle {
|
|
|
|
id: moreActionsBtnContainer
|
|
|
|
width: 40
|
|
|
|
height: 40
|
|
|
|
radius: Style.current.radius
|
|
|
|
color: Style.current.transparent
|
2020-05-27 21:59:34 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: parent.right
|
2020-07-09 17:56:31 +00:00
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: moreActionsBtn
|
|
|
|
text: "..."
|
|
|
|
font.letterSpacing: 0.5
|
|
|
|
font.bold: true
|
|
|
|
lineHeight: 1.4
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
font.pixelSize: 25
|
|
|
|
}
|
2020-05-27 21:59:34 +00:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
anchors.fill: parent
|
2020-07-09 17:56:31 +00:00
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: {
|
2020-07-13 18:45:54 +00:00
|
|
|
parent.color = Style.current.border
|
2020-07-09 17:56:31 +00:00
|
|
|
}
|
|
|
|
onExited: {
|
|
|
|
parent.color = Style.current.transparent
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:59:34 +00:00
|
|
|
onClicked: {
|
2020-06-10 19:41:03 +00:00
|
|
|
var menu = chatContextMenu;
|
2021-01-21 14:39:27 +00:00
|
|
|
var isPrivateGroupChat = chatsModel.activeChannel.chatType === Constants.chatTypePrivateGroupChat
|
|
|
|
if(isPrivateGroupChat){
|
2020-06-10 19:41:03 +00:00
|
|
|
menu = groupContextMenu
|
|
|
|
}
|
|
|
|
|
2021-01-11 20:08:35 +00:00
|
|
|
if (menu.opened) {
|
|
|
|
return menu.close()
|
|
|
|
}
|
|
|
|
|
2021-01-21 14:39:27 +00:00
|
|
|
if (isPrivateGroupChat) {
|
|
|
|
menu.popup(moreActionsBtn.x, moreActionsBtn.height)
|
|
|
|
} else {
|
|
|
|
menu.openMenu(chatsModel.activeChannel)
|
|
|
|
}
|
2020-05-27 21:59:34 +00:00
|
|
|
}
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
2021-01-21 14:39:27 +00:00
|
|
|
|
|
|
|
ChannelContextMenu {
|
2020-06-10 19:41:03 +00:00
|
|
|
id: chatContextMenu
|
2021-01-21 14:39:27 +00:00
|
|
|
groupInfoPopup: groupInfoPopup
|
2020-05-27 21:59:34 +00:00
|
|
|
}
|
2020-06-10 19:41:03 +00:00
|
|
|
|
|
|
|
PopupMenu {
|
|
|
|
id: groupContextMenu
|
2021-01-11 20:08:35 +00:00
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
|
2020-06-17 19:18:31 +00:00
|
|
|
Action {
|
2020-06-11 17:50:36 +00:00
|
|
|
icon.source: "../../../img/group_chat.svg"
|
2020-07-10 18:49:14 +00:00
|
|
|
icon.width: chatTopBarContent.iconSize
|
|
|
|
icon.height: chatTopBarContent.iconSize
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Group Information"
|
|
|
|
text: qsTrId("group-information")
|
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
|
|
|
onTriggered: groupInfoPopup.openMenu(chatsModel.activeChannel, chatsModel.getActiveChannelIdx())
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
2020-06-18 09:47:30 +00:00
|
|
|
Action {
|
|
|
|
icon.source: "../../../img/close.svg"
|
2020-07-10 18:49:14 +00:00
|
|
|
icon.width: chatTopBarContent.iconSize
|
|
|
|
icon.height: chatTopBarContent.iconSize
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Clear history"
|
|
|
|
text: qsTrId("clear-history")
|
2020-06-18 09:47:30 +00:00
|
|
|
onTriggered: chatsModel.clearChatHistory(chatsModel.activeChannel.id)
|
|
|
|
}
|
2020-06-17 19:18:31 +00:00
|
|
|
Action {
|
2020-06-10 19:41:03 +00:00
|
|
|
icon.source: "../../../img/leave_chat.svg"
|
2020-07-10 18:49:14 +00:00
|
|
|
icon.width: chatTopBarContent.iconSize
|
|
|
|
icon.height: chatTopBarContent.iconSize
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Leave Group"
|
|
|
|
text: qsTrId("leave-group")
|
2020-08-10 13:06:46 +00:00
|
|
|
onTriggered: {
|
|
|
|
//% "Leave group"
|
|
|
|
deleteChatConfirmationDialog.title = qsTrId("leave-group")
|
|
|
|
//% "Leave group"
|
|
|
|
deleteChatConfirmationDialog.confirmButtonLabel = qsTrId("leave-group")
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Are you sure you want to leave this chat?"
|
|
|
|
deleteChatConfirmationDialog.confirmationText = qsTrId("are-you-sure-you-want-to-leave-this-chat-")
|
2020-08-10 13:06:46 +00:00
|
|
|
deleteChatConfirmationDialog.open()
|
|
|
|
}
|
2020-06-10 19:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 17:50:36 +00:00
|
|
|
GroupInfoPopup {
|
|
|
|
id: groupInfoPopup
|
2020-08-06 13:37:09 +00:00
|
|
|
}
|
2020-05-27 21:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-10 13:06:46 +00:00
|
|
|
|
|
|
|
ConfirmationDialog {
|
|
|
|
id: deleteChatConfirmationDialog
|
2021-01-13 20:26:30 +00:00
|
|
|
btnType: "warn"
|
2020-08-10 13:06:46 +00:00
|
|
|
onConfirmButtonClicked: {
|
|
|
|
chatsModel.leaveActiveChat()
|
|
|
|
deleteChatConfirmationDialog.close()
|
|
|
|
}
|
|
|
|
}
|
2020-06-02 09:54:46 +00:00
|
|
|
}
|