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)
}
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

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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