fix: check if user is blocked on profile popup

This PR is a response to @emizzle's suggested change in PR #1431 . It checks if a user is blocked before exposing certain functionality to the user in a Profile popup. The new unblock button also has a fail-safe unblock confirmation popup

disable the chat input if 1-on-1 chat recipient has been blocked.
This commit is contained in:
hydrogen 2020-12-02 11:10:22 +02:00 committed by Iuri Matias
parent 1e245a3375
commit 8fd28dfad6
4 changed files with 41 additions and 4 deletions

View File

@ -28,6 +28,8 @@ StackLayout {
chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason) chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
} }
property bool isBlocked: Utils.isContactBlocked(chatsModel.activeChannel.id, profileModel.getBlockedContacts())
Component.onCompleted: { Component.onCompleted: {
chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason) chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
} }
@ -236,6 +238,8 @@ StackLayout {
if (chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat) return true; if (chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat) return true;
return chatsModel.activeChannel.isMember return chatsModel.activeChannel.isMember
} }
enabled: !isBlocked
chatInputPlaceholder: isBlocked ? qsTr("This user has been blocked.") : qsTr("Type a message.")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
recentStickers: chatsModel.recentStickers recentStickers: chatsModel.recentStickers
stickerPackList: chatsModel.stickerPacks stickerPackList: chatsModel.stickerPacks

View File

@ -22,10 +22,13 @@ ModalPopup {
property bool showQR: false property bool showQR: false
property bool isEnsVerified: false property bool isEnsVerified: false
property bool noFooter: false property bool noFooter: false
property bool isBlocked: false
signal blockButtonClicked(name: string, address: string) signal blockButtonClicked(name: string, address: string)
signal unblockButtonClicked(name: string, address: string)
signal removeButtonClicked(address: string) signal removeButtonClicked(address: string)
signal contactUnblocked(publicKey: string)
signal contactBlocked(publicKey: string) signal contactBlocked(publicKey: string)
signal contactAdded(publicKey: string) signal contactAdded(publicKey: string)
signal contactRemoved(publicKey: string) signal contactRemoved(publicKey: string)
@ -37,6 +40,7 @@ ModalPopup {
identicon = identiconParam || "" identicon = identiconParam || ""
text = textParam || "" text = textParam || ""
isEnsVerified = chatsModel.isEnsVerified(this.fromAuthor) isEnsVerified = chatsModel.isEnsVerified(this.fromAuthor)
isBlocked = Utils.isContactBlocked(this.fromAuthor, profileModel.getBlockedContacts());
alias = chatsModel.alias(this.fromAuthor) || "" alias = chatsModel.alias(this.fromAuthor) || ""
showQR = false showQR = false
@ -136,6 +140,17 @@ ModalPopup {
} }
} }
UnblockContactConfirmationDialog {
id: unblockContactConfirmationDialog
onUnblockButtonClicked: {
profileModel.unblockContact(fromAuthor)
unblockContactConfirmationDialog.close();
popup.close()
contactUnblocked(fromAuthor)
}
}
ConfirmationDialog { ConfirmationDialog {
id: removeContactConfirmationDialog id: removeContactConfirmationDialog
// % "Remove contact" // % "Remove contact"
@ -361,6 +376,7 @@ ModalPopup {
//% "Send Message" //% "Send Message"
label: qsTrId("send-message") label: qsTrId("send-message")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
visible: !isBlocked
onClicked: { onClicked: {
if (tabBar.currentIndex !== 0) if (tabBar.currentIndex !== 0)
tabBar.currentIndex = 0 tabBar.currentIndex = 0
@ -371,15 +387,20 @@ ModalPopup {
StyledButton { StyledButton {
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: addToContactsButton.width + 32 anchors.rightMargin: isBlocked ? 0 : addToContactsButton.width + 32
btnColor: Style.current.lightRed btnColor: Style.current.lightRed
btnBorderWidth: 1 btnBorderWidth: 1
btnBorderColor: Style.current.grey btnBorderColor: Style.current.grey
textColor: Style.current.red textColor: Style.current.red
//% "Block User" label: isBlocked ? qsTr("Unblock User") : qsTr("Block User")
label: qsTrId("block-user")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
onClicked: { onClicked: {
if (isBlocked) {
unblockContactConfirmationDialog.contactName = userName;
unblockContactConfirmationDialog.contactAddress = fromAuthor;
unblockContactConfirmationDialog.open();
return;
}
blockContactConfirmationDialog.contactName = userName; blockContactConfirmationDialog.contactName = userName;
blockContactConfirmationDialog.contactAddress = fromAuthor; blockContactConfirmationDialog.contactAddress = fromAuthor;
blockContactConfirmationDialog.open(); blockContactConfirmationDialog.open();
@ -396,6 +417,7 @@ ModalPopup {
//% "Add to contacts" //% "Add to contacts"
qsTrId("add-to-contacts") qsTrId("add-to-contacts")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
visible: !isBlocked
onClicked: { onClicked: {
if (profileModel.isAdded(fromAuthor)) { if (profileModel.isAdded(fromAuthor)) {
removeContactConfirmationDialog.parentPopup = profilePopup; removeContactConfirmationDialog.parentPopup = profilePopup;

View File

@ -197,4 +197,13 @@ QtObject {
default: return network 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;
}
} }

View File

@ -32,6 +32,8 @@ Rectangle {
property int chatType property int chatType
property string chatInputPlaceholder: qsTr("Type a message")
property alias textInput: messageInputField property alias textInput: messageInputField
height: { height: {
@ -626,7 +628,7 @@ Rectangle {
wrapMode: TextArea.Wrap wrapMode: TextArea.Wrap
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.top: parent.top anchors.top: parent.top
placeholderText: qsTr("Type a message") placeholderText: chatInputPlaceholder
placeholderTextColor: Style.current.secondaryText placeholderTextColor: Style.current.secondaryText
selectByMouse: true selectByMouse: true
color: Style.current.textColor color: Style.current.textColor