diff --git a/ui/app/AppLayouts/Chat/ChatColumn.qml b/ui/app/AppLayouts/Chat/ChatColumn.qml index a4e758118d..7024a835ac 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn.qml @@ -28,6 +28,8 @@ StackLayout { chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason) } + property bool isBlocked: Utils.isContactBlocked(chatsModel.activeChannel.id, profileModel.getBlockedContacts()) + Component.onCompleted: { chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason) } @@ -236,6 +238,8 @@ StackLayout { if (chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat) return true; return chatsModel.activeChannel.isMember } + enabled: !isBlocked + chatInputPlaceholder: isBlocked ? qsTr("This user has been blocked.") : qsTr("Type a message.") anchors.bottom: parent.bottom recentStickers: chatsModel.recentStickers stickerPackList: chatsModel.stickerPacks diff --git a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml index f3a8d153db..dbf0afd73e 100644 --- a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml +++ b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml @@ -22,10 +22,13 @@ ModalPopup { property bool showQR: false property bool isEnsVerified: false property bool noFooter: false + property bool isBlocked: false signal blockButtonClicked(name: string, address: string) + signal unblockButtonClicked(name: string, address: string) signal removeButtonClicked(address: string) + signal contactUnblocked(publicKey: string) signal contactBlocked(publicKey: string) signal contactAdded(publicKey: string) signal contactRemoved(publicKey: string) @@ -37,6 +40,7 @@ ModalPopup { identicon = identiconParam || "" text = textParam || "" isEnsVerified = chatsModel.isEnsVerified(this.fromAuthor) + isBlocked = Utils.isContactBlocked(this.fromAuthor, profileModel.getBlockedContacts()); alias = chatsModel.alias(this.fromAuthor) || "" showQR = false @@ -136,6 +140,17 @@ ModalPopup { } } + UnblockContactConfirmationDialog { + id: unblockContactConfirmationDialog + onUnblockButtonClicked: { + profileModel.unblockContact(fromAuthor) + unblockContactConfirmationDialog.close(); + popup.close() + + contactUnblocked(fromAuthor) + } + } + ConfirmationDialog { id: removeContactConfirmationDialog // % "Remove contact" @@ -361,6 +376,7 @@ ModalPopup { //% "Send Message" label: qsTrId("send-message") anchors.bottom: parent.bottom + visible: !isBlocked onClicked: { if (tabBar.currentIndex !== 0) tabBar.currentIndex = 0 @@ -371,15 +387,20 @@ ModalPopup { StyledButton { anchors.right: parent.right - anchors.rightMargin: addToContactsButton.width + 32 + anchors.rightMargin: isBlocked ? 0 : addToContactsButton.width + 32 btnColor: Style.current.lightRed btnBorderWidth: 1 btnBorderColor: Style.current.grey textColor: Style.current.red - //% "Block User" - label: qsTrId("block-user") + label: isBlocked ? qsTr("Unblock User") : qsTr("Block User") anchors.bottom: parent.bottom onClicked: { + if (isBlocked) { + unblockContactConfirmationDialog.contactName = userName; + unblockContactConfirmationDialog.contactAddress = fromAuthor; + unblockContactConfirmationDialog.open(); + return; + } blockContactConfirmationDialog.contactName = userName; blockContactConfirmationDialog.contactAddress = fromAuthor; blockContactConfirmationDialog.open(); @@ -396,6 +417,7 @@ ModalPopup { //% "Add to contacts" qsTrId("add-to-contacts") anchors.bottom: parent.bottom + visible: !isBlocked onClicked: { if (profileModel.isAdded(fromAuthor)) { removeContactConfirmationDialog.parentPopup = profilePopup; diff --git a/ui/imports/Utils.qml b/ui/imports/Utils.qml index 87549cc3cd..da0a7f3532 100644 --- a/ui/imports/Utils.qml +++ b/ui/imports/Utils.qml @@ -197,4 +197,13 @@ QtObject { default: return network } } + + function isContactBlocked(fromAuthor, blockedList) { + for (let i = 0; i < blockedList.rowCount(); i++) { + if (blockedList.rowData(i, 'pubKey') === fromAuthor) { + return true; + } + } + return false; + } } diff --git a/ui/shared/status/StatusChatInput.qml b/ui/shared/status/StatusChatInput.qml index ba4d66d0e6..32eadd692e 100644 --- a/ui/shared/status/StatusChatInput.qml +++ b/ui/shared/status/StatusChatInput.qml @@ -32,6 +32,8 @@ Rectangle { property int chatType + property string chatInputPlaceholder: qsTr("Type a message") + property alias textInput: messageInputField height: { @@ -626,7 +628,7 @@ Rectangle { wrapMode: TextArea.Wrap anchors.bottom: parent.bottom anchors.top: parent.top - placeholderText: qsTr("Type a message") + placeholderText: chatInputPlaceholder placeholderTextColor: Style.current.secondaryText selectByMouse: true color: Style.current.textColor