2024-08-27 14:35:52 +00:00
import QtQuick 2.15
import QtQuick . Controls 2.15
import QtQuick . Layouts 1.15
2021-09-15 10:59:01 +00:00
import Qt . labs . platform 1.1
2021-09-28 15:04:06 +00:00
2024-08-27 14:35:52 +00:00
import StatusQ 0.1
2021-07-06 09:42:51 +00:00
import StatusQ . Popups 0.1
2023-06-23 06:17:04 +00:00
import AppLayouts . Communities . popups 1.0
2024-08-27 14:35:52 +00:00
import shared . controls . chat . menuItems 1.0
import shared . popups 1.0
import utils 1.0
2021-10-25 09:57:09 +00:00
2022-12-01 16:58:37 +00:00
StatusMenu {
2021-10-21 22:39:53 +00:00
id: root
2021-12-09 12:53:40 +00:00
property string currentFleet: ""
property bool isCommunityChat: false
2022-01-05 15:50:03 +00:00
property bool amIChatAdmin: false
2021-12-09 12:53:40 +00:00
property string chatId: ""
property string chatName: ""
2021-12-21 09:26:13 +00:00
property string chatDescription: ""
2022-03-07 14:56:05 +00:00
property string chatEmoji: ""
2022-03-10 19:28:37 +00:00
property string chatColor: ""
2021-12-09 12:53:40 +00:00
property string chatIcon: ""
property int chatType: - 1
property bool chatMuted: false
2022-01-31 18:57:05 +00:00
property int channelPosition: - 1
property string chatCategoryId: ""
2024-03-13 19:13:41 +00:00
property bool viewersCanPostReactions: true
2024-02-07 12:38:46 +00:00
property bool showDebugOptions: false
2024-02-06 09:31:36 +00:00
property alias deleteChatConfirmationDialog: deleteChatConfirmationDialogComponent
2024-03-18 17:33:07 +00:00
property bool hideIfPermissionsNotMet: false
2021-12-09 12:53:40 +00:00
2022-01-05 15:50:03 +00:00
signal displayProfilePopup ( string publicKey )
2024-02-06 09:31:36 +00:00
signal displayEditChannelPopup ( string chatId )
2021-12-21 09:26:13 +00:00
signal requestAllHistoricMessages ( string chatId )
signal unmuteChat ( string chatId )
2023-05-26 12:54:10 +00:00
signal muteChat ( string chatId , int interval )
2021-12-21 09:26:13 +00:00
signal markAllMessagesRead ( string chatId )
signal clearChatHistory ( string chatId )
2021-12-09 12:53:40 +00:00
signal downloadMessages ( string file )
2022-01-25 12:09:27 +00:00
signal deleteCommunityChat ( string chatId )
2021-12-21 09:26:13 +00:00
signal leaveChat ( string chatId )
2022-07-12 08:27:35 +00:00
signal updateGroupChatDetails ( string chatId , string groupName , string groupColor , string groupImage )
2021-12-21 09:26:13 +00:00
2023-11-29 09:55:03 +00:00
signal requestMoreMessages ( string chatId )
2022-02-15 21:00:05 +00:00
signal addRemoveGroupMember ( )
2021-07-06 09:42:51 +00:00
2022-05-13 17:11:02 +00:00
width: root . amIChatAdmin && ( root . chatType === Constants . chatType . privateGroupChat ) ? 207 : implicitWidth
2022-06-10 11:12:03 +00:00
ViewProfileMenuItem {
enabled: root . chatType === Constants . chatType . oneToOne
onTriggered: root . displayProfilePopup ( root . chatId )
}
2022-12-01 16:58:37 +00:00
StatusAction {
2024-09-16 10:10:33 +00:00
objectName: "addRemoveFromGroupStatusAction"
2022-08-29 14:33:14 +00:00
text: root . amIChatAdmin ? qsTr ( "Add / remove from group" ) : qsTr ( "Add to group" )
2022-05-13 17:11:02 +00:00
icon.name: "add-to-dm"
2022-08-29 14:33:14 +00:00
enabled: ( root . chatType === Constants . chatType . privateGroupChat )
2022-05-13 17:11:02 +00:00
onTriggered: { root . addRemoveGroupMember ( ) }
}
2022-02-15 21:00:05 +00:00
2023-10-24 15:13:25 +00:00
StatusAction {
2024-09-16 12:58:16 +00:00
objectName: "copyChannelLinkStatusAction"
2023-10-24 15:13:25 +00:00
text: qsTr ( "Copy channel link" )
icon.name: "copy"
enabled: root . isCommunityChat
onTriggered: {
const link = Utils . getCommunityChannelShareLinkWithChatId ( root . chatId )
2024-08-27 14:35:52 +00:00
ClipboardUtils . setText ( link )
2023-10-24 15:13:25 +00:00
}
}
2021-07-06 09:42:51 +00:00
StatusMenuSeparator {
2023-10-24 15:13:25 +00:00
visible: root . chatType === Constants . chatType . oneToOne || root . chatType === Constants . chatType . privateGroupChat || root . isCommunityChat
2021-07-06 09:42:51 +00:00
}
2022-12-01 16:58:37 +00:00
StatusAction {
2022-09-01 07:53:22 +00:00
objectName: "editNameAndImageMenuItem"
2022-07-12 08:27:35 +00:00
text: qsTr ( "Edit name and image" )
icon.name: "edit_pencil"
2022-03-21 20:51:54 +00:00
enabled: root . chatType === Constants . chatType . privateGroupChat
2022-02-15 21:00:05 +00:00
onTriggered: {
2022-04-12 18:54:01 +00:00
Global . openPopup ( renameGroupPopupComponent , {
2022-07-12 08:27:35 +00:00
activeGroupName: root . chatName ,
2022-08-11 10:58:09 +00:00
activeGroupColor: root . chatColor ,
activeGroupImageData: root . chatIcon
2022-02-15 21:00:05 +00:00
} ) ;
}
}
2022-04-12 18:54:01 +00:00
Component {
id: renameGroupPopupComponent
RenameGroupPopup {
2024-03-22 13:05:19 +00:00
destroyOnClose: true
2022-07-12 08:27:35 +00:00
onUpdateGroupChatDetails: {
root . updateGroupChatDetails ( root . chatId , groupName , groupColor , groupImage )
2022-04-12 18:54:01 +00:00
close ( )
}
}
}
2022-06-10 11:12:03 +00:00
MuteChatMenuItem {
2023-05-26 12:54:10 +00:00
enabled: ! root . chatMuted
isCommunityChat: root . isCommunityChat
onMuteTriggered: {
root . muteChat ( root . chatId , interval )
}
}
StatusAction {
2024-09-16 12:58:16 +00:00
objectName: "muteChatStatusAction"
2023-05-26 12:54:10 +00:00
enabled: root . chatMuted
text: root . isCommunityChat ? qsTr ( "Unmute Channel" ) : qsTr ( "Unmute Chat" )
icon.name: "notification"
2021-07-06 09:42:51 +00:00
onTriggered: {
2023-05-26 12:54:10 +00:00
root . unmuteChat ( root . chatId )
2021-07-06 09:42:51 +00:00
}
}
2022-12-01 16:58:37 +00:00
StatusAction {
2022-07-28 20:14:29 +00:00
objectName: "chatMarkAsReadMenuItem"
2022-04-04 11:26:30 +00:00
text: qsTr ( "Mark as Read" )
2021-07-06 09:42:51 +00:00
icon.name: "checkmark-circle"
2021-12-09 12:53:40 +00:00
onTriggered: {
2021-12-08 11:10:34 +00:00
root . markAllMessagesRead ( root . chatId )
2021-12-09 12:53:40 +00:00
}
2021-07-06 09:42:51 +00:00
}
2024-03-22 13:05:19 +00:00
StatusAction {
objectName: "editChannelMenuItem"
text: qsTr ( "Edit Channel" )
icon.name: "edit"
enabled: root . isCommunityChat && root . amIChatAdmin
onTriggered: {
root . displayEditChannelPopup ( root . chatId ) ;
}
}
2024-03-12 14:24:55 +00:00
StatusMenu {
title: qsTr ( "Debug actions" )
2024-02-07 12:38:46 +00:00
enabled: root . showDebugOptions
2024-03-12 14:24:55 +00:00
StatusAction {
text: root . isCommunityChat ? qsTr ( "Copy channel ID" ) : qsTr ( "Copy chat ID" )
icon.name: "copy"
2024-08-27 14:35:52 +00:00
onTriggered: ClipboardUtils . setText ( root . chatId )
2024-03-12 14:24:55 +00:00
}
StatusAction {
objectName: "chatFetchMessagesMenuItem"
text: qsTr ( "Fetch messages" )
icon.name: "download"
onTriggered: {
root . requestMoreMessages ( root . chatId )
}
2023-11-29 09:55:03 +00:00
}
}
2022-02-15 21:00:05 +00:00
2022-12-01 16:58:37 +00:00
StatusAction {
2021-09-15 10:59:01 +00:00
text: qsTr ( "Download" )
2021-10-20 09:50:50 +00:00
enabled: localAccountSensitiveSettings . downloadChannelMessagesEnabled
2021-09-15 10:59:01 +00:00
icon.name: "download"
2022-08-01 18:34:31 +00:00
onTriggered: downloadDialog . open ( )
2021-09-15 10:59:01 +00:00
}
2021-07-06 09:42:51 +00:00
StatusMenuSeparator {
2024-03-22 13:05:19 +00:00
visible: clearHistoryGroupMenuItem . enabled || deleteOrLeaveMenuItem . enabled
2023-08-22 18:24:06 +00:00
}
StatusAction {
2024-03-22 13:05:19 +00:00
id: clearHistoryGroupMenuItem
objectName: "clearHistoryGroupMenuItem"
enabled: ( root . chatType !== Constants . chatType . oneToOne )
2023-08-22 18:24:06 +00:00
text: qsTr ( "Clear History" )
2024-03-22 13:05:19 +00:00
icon.name: "delete"
type: StatusAction . Type . Danger
2023-08-22 18:24:06 +00:00
onTriggered: {
Global . openPopup ( clearChatConfirmationDialogComponent ) ;
}
2021-07-06 09:42:51 +00:00
}
2022-12-01 16:58:37 +00:00
StatusAction {
2021-07-06 09:42:51 +00:00
id: deleteOrLeaveMenuItem
2023-08-31 12:16:29 +00:00
objectName: "deleteOrLeaveMenuItem"
2021-07-30 16:14:10 +00:00
text: {
2021-12-21 09:26:13 +00:00
if ( root . isCommunityChat ) {
2021-07-30 16:14:10 +00:00
return qsTr ( "Delete Channel" )
}
2022-02-15 21:00:05 +00:00
if ( root . chatType === Constants . chatType . privateGroupChat ) {
return qsTr ( "Leave group" )
}
2021-12-09 12:53:40 +00:00
return root . chatType === Constants . chatType . oneToOne ?
2023-11-16 18:45:01 +00:00
qsTr ( "Close Chat" ) :
2022-09-22 22:01:29 +00:00
qsTr ( "Leave Chat" )
2021-07-30 16:14:10 +00:00
}
2024-03-22 13:05:19 +00:00
icon.name: root . chatType === Constants . chatType . oneToOne || root . isCommunityChat ? "close-circle" : "arrow-left"
2021-12-21 09:26:13 +00:00
icon.width: root . chatType === Constants . chatType . oneToOne || root . isCommunityChat ? 18 : 14
2021-07-06 09:42:51 +00:00
2022-12-01 16:58:37 +00:00
type: StatusAction . Type . Danger
2021-07-06 09:42:51 +00:00
onTriggered: {
2022-02-15 21:00:05 +00:00
if ( root . chatType === Constants . chatType . privateGroupChat ) {
2023-08-31 13:42:51 +00:00
Global . openPopup ( leaveGroupConfirmationDialogComponent ) ;
2022-02-15 21:00:05 +00:00
} else {
Global . openPopup ( deleteChatConfirmationDialogComponent ) ;
}
2021-07-06 09:42:51 +00:00
}
2022-01-05 15:50:03 +00:00
enabled: ! root . isCommunityChat || root . amIChatAdmin
2021-07-06 09:42:51 +00:00
}
2024-03-22 13:05:19 +00:00
StatusAction {
id: clearHistoryMenuItem
objectName: "clearHistoryMenuItem"
enabled: ( root . chatType === Constants . chatType . oneToOne )
text: qsTr ( "Clear History" )
icon.name: "delete"
type: StatusAction . Type . Danger
onTriggered: {
Global . openPopup ( clearChatConfirmationDialogComponent ) ;
}
}
2021-09-15 10:59:01 +00:00
FileDialog {
2022-08-01 18:34:31 +00:00
id: downloadDialog
2021-09-15 10:59:01 +00:00
acceptLabel: qsTr ( "Save" )
fileMode: FileDialog . SaveFile
title: qsTr ( "Download messages" )
currentFile: StandardPaths . writableLocation ( StandardPaths . DocumentsLocation ) + "/messages.json"
defaultSuffix: "json"
2021-12-09 12:53:40 +00:00
2021-09-15 10:59:01 +00:00
onAccepted: {
2022-08-01 18:34:31 +00:00
root . downloadMessages ( downloadDialog . currentFile )
2021-09-15 10:59:01 +00:00
}
}
2023-08-22 18:24:06 +00:00
Component {
id: clearChatConfirmationDialogComponent
ConfirmationDialog {
confirmButtonObjectName: "clearChatConfirmationDialogClearButton"
headerSettings.title: qsTr ( "Clear chat history" )
2024-03-22 13:05:19 +00:00
confirmationText: qsTr ( "Are you sure you want to clear your chat history with <b>%1</b>? All messages will be deleted on your side and will be unrecoverable." ) . arg ( root . chatName )
confirmButtonLabel: qsTr ( "Clear chat history" )
2023-08-22 18:24:06 +00:00
showCancelButton: true
cancelBtnType: "normal"
onClosed: {
destroy ( )
}
onCancelButtonClicked: {
close ( )
}
onConfirmButtonClicked: {
root . clearChatHistory ( root . chatId )
close ( )
}
}
}
2023-08-31 13:42:51 +00:00
Component {
id: leaveGroupConfirmationDialogComponent
ConfirmationDialog {
confirmButtonObjectName: "leaveGroupConfirmationDialogLeaveButton"
headerSettings.title: qsTr ( "Leave group" )
confirmationText: qsTr ( "Are you sure you want to leave group chat <b>%1</b>?" ) . arg ( root . chatName )
confirmButtonLabel: qsTr ( "Leave" )
showCancelButton: true
cancelBtnType: "normal"
onClosed: {
destroy ( )
}
onCancelButtonClicked: {
close ( )
}
onConfirmButtonClicked: {
root . leaveChat ( root . chatId )
close ( )
}
}
}
2021-07-06 09:42:51 +00:00
Component {
id: deleteChatConfirmationDialogComponent
ConfirmationDialog {
2022-08-01 18:34:31 +00:00
confirmButtonObjectName: "deleteChatConfirmationDialogDeleteButton"
2023-05-23 12:46:16 +00:00
headerSettings.title: root . isCommunityChat ? qsTr ( "Delete #%1" ) . arg ( root . chatName ) :
2021-12-09 12:53:40 +00:00
root . chatType === Constants . chatType . oneToOne ?
2023-11-16 18:45:01 +00:00
qsTr ( "Close chat" ) :
2022-04-04 11:26:30 +00:00
qsTr ( "Leave chat" )
2023-07-13 13:24:01 +00:00
confirmButtonLabel: root . isCommunityChat ? qsTr ( "Delete" ) : headerSettings . title
2021-12-21 09:26:13 +00:00
confirmationText: root . isCommunityChat ? qsTr ( "Are you sure you want to delete #%1 channel?" ) . arg ( root . chatName ) :
2021-12-09 12:53:40 +00:00
root . chatType === Constants . chatType . oneToOne ?
2024-03-22 13:05:19 +00:00
qsTr ( "Are you sure you want to close this chat? This will remove the chat from the list. Your chat history will be retained and shown the next time you message each other." ) :
2021-07-30 16:14:10 +00:00
qsTr ( "Are you sure you want to leave this chat?" )
2023-08-22 18:24:06 +00:00
showCancelButton: true
cancelBtnType: "normal"
2021-09-14 09:58:20 +00:00
2021-07-06 09:42:51 +00:00
onClosed: {
destroy ( )
}
2021-09-14 09:58:20 +00:00
onCancelButtonClicked: {
close ( )
}
2021-07-06 09:42:51 +00:00
onConfirmButtonClicked: {
2022-01-18 15:56:57 +00:00
if ( root . isCommunityChat )
2022-01-25 12:09:27 +00:00
root . deleteCommunityChat ( root . chatId )
2021-12-21 09:26:13 +00:00
else
root . leaveChat ( root . chatId )
2021-12-09 12:53:40 +00:00
2021-12-21 09:26:13 +00:00
close ( )
}
2021-07-06 09:42:51 +00:00
}
}
}