feat(@desktop/chat): New profile context menu states

Close #6113
This commit is contained in:
MishkaRogachev 2022-06-20 17:48:38 +03:00 committed by Iuri Matias
parent 9ebe9ec2c5
commit 2251f870a0
13 changed files with 137 additions and 57 deletions

View File

@ -123,6 +123,12 @@ QtObject:
proc isMyMutualContact*(self: View, publicKey: string): bool {.slot.} = proc isMyMutualContact*(self: View, publicKey: string): bool {.slot.} =
return self.myMutualContactsModel.isContactWithIdAdded(publicKey) return self.myMutualContactsModel.isContactWithIdAdded(publicKey)
proc isBlockedContact*(self: View, publicKey: string): bool {.slot.} =
return self.blockedContactsModel.isContactWithIdAdded(publicKey)
proc hasPendingContactRequest*(self: View, publicKey: string): bool {.slot.} =
return self.sentContactRequestsModel.isContactWithIdAdded(publicKey)
proc sendContactRequest*(self: View, publicKey: string, message: string) {.slot.} = proc sendContactRequest*(self: View, publicKey: string, message: string) {.slot.} =
self.delegate.sendContactRequest(publicKey, message) self.delegate.sendContactRequest(publicKey, message)

View File

@ -191,7 +191,7 @@ ModalPopup {
} }
onOpenProfileClicked: { onOpenProfileClicked: {
Global.openProfilePopup(publicKey) Global.openProfilePopup(publicKey, null, state)
} }
} }
} }

View File

@ -384,7 +384,7 @@ ColumnLayout {
} }
onOpenProfileClicked: { onOpenProfileClicked: {
Global.openProfilePopup(publicKey) Global.openProfilePopup(publicKey, null, state)
} }
onDeleteMessage: { onDeleteMessage: {

View File

@ -191,7 +191,7 @@ StatusAppThreePanelLayout {
store: root.rootStore store: root.rootStore
onOpenProfileClicked: { onOpenProfileClicked: {
Global.openProfilePopup(publicKey) Global.openProfilePopup(publicKey, null, state)
} }
onCreateOneToOneChat: { onCreateOneToOneChat: {
Global.changeAppSectionBySectionType(Constants.appSection.chat) Global.changeAppSectionBySectionType(Constants.appSection.chat)

View File

@ -36,6 +36,14 @@ QtObject {
return root.contactsModule.isMyMutualContact(pubKey) return root.contactsModule.isMyMutualContact(pubKey)
} }
function isBlockedContact(pubKey) {
return root.contactsModule.isBlockedContact(pubKey)
}
function hasPendingContactRequest(pubKey) {
return root.contactsModule.hasPendingContactRequest(pubKey)
}
function joinPrivateChat(pubKey) { function joinPrivateChat(pubKey) {
Global.changeAppSectionBySectionType(Constants.appSection.chat) Global.changeAppSectionBySectionType(Constants.appSection.chat)
root.contactsModule.switchToOrCreateOneToOneChat(pubKey) root.contactsModule.switchToOrCreateOneToOneChat(pubKey)

View File

@ -119,7 +119,7 @@ SettingsContentBase {
} }
onOpenChangeNicknamePopup: { onOpenChangeNicknamePopup: {
Global.openProfilePopup(publicKey, null, true) Global.openProfilePopup(publicKey, null, "openNickname")
} }
} }
@ -140,7 +140,7 @@ SettingsContentBase {
} }
onOpenChangeNicknamePopup: { onOpenChangeNicknamePopup: {
Global.openProfilePopup(publicKey, null, true) Global.openProfilePopup(publicKey, null, "openNickname")
} }
} }
@ -181,7 +181,7 @@ SettingsContentBase {
} }
onOpenChangeNicknamePopup: { onOpenChangeNicknamePopup: {
Global.openProfilePopup(publicKey, null, true) Global.openProfilePopup(publicKey, null, "openNickname")
} }
onContactRequestAccepted: { onContactRequestAccepted: {
@ -207,7 +207,7 @@ SettingsContentBase {
} }
onOpenChangeNicknamePopup: { onOpenChangeNicknamePopup: {
Global.openProfilePopup(publicKey, null, true) Global.openProfilePopup(publicKey, null, "openNickname")
} }
} }

View File

@ -90,10 +90,10 @@ Item {
} }
onOpenProfilePopupRequested: { onOpenProfilePopupRequested: {
var popup = profilePopupComponent.createObject(appMain); var popup = profilePopupComponent.createObject(appMain);
if (parentPopup){ if (parentPopup) {
popup.parentPopup = parentPopup; popup.parentPopup = parentPopup;
} }
popup.openPopup(publicKey, openNicknamePopup); popup.openPopup(publicKey, state);
Global.profilePopupOpened = true; Global.profilePopupOpened = true;
} }
onOpenChangeProfilePicPopup: { onOpenChangeProfilePicPopup: {

View File

@ -0,0 +1,8 @@
import QtQuick 2.14
import StatusQ.Popups 0.1
StatusMenuItem {
text: qsTr("Send Contact Request")
icon.name: "add-contact"
}

View File

@ -1,3 +1,4 @@
ViewProfileMenuItem 1.0 ViewProfileMenuItem.qml ViewProfileMenuItem 1.0 ViewProfileMenuItem.qml
MuteChatMenuItem 1.0 MuteChatMenuItem.qml MuteChatMenuItem 1.0 MuteChatMenuItem.qml
SendMessageMenuItem 1.0 SendMessageMenuItem.qml SendMessageMenuItem 1.0 SendMessageMenuItem.qml
SendContactRequestMenuItem 1.0 SendContactRequestMenuItem.qml

View File

@ -43,29 +43,47 @@ StatusModal {
signal contactUnblocked(publicKey: string) signal contactUnblocked(publicKey: string)
signal contactBlocked(publicKey: string) signal contactBlocked(publicKey: string)
function openPopup(publicKey, openNicknamePopup) { function openPopup(publicKey, state = "") {
// All this should be improved more, but for now we leave it like this. // All this should be improved more, but for now we leave it like this.
let contactDetails = Utils.getContactDetailsAsJson(publicKey) let contactDetails = Utils.getContactDetailsAsJson(publicKey);
userPublicKey = publicKey userPublicKey = publicKey;
userDisplayName = contactDetails.displayName userDisplayName = contactDetails.displayName;
userName = contactDetails.alias userName = contactDetails.alias;
userNickname = contactDetails.localNickname userNickname = contactDetails.localNickname;
userEnsName = contactDetails.name userEnsName = contactDetails.name;
userIcon = contactDetails.displayIcon userIcon = contactDetails.displayIcon;
userIsEnsVerified = contactDetails.ensVerified userIsEnsVerified = contactDetails.ensVerified;
userIsBlocked = contactDetails.isBlocked userIsBlocked = contactDetails.isBlocked;
isAddedContact = contactDetails.isContact isAddedContact = contactDetails.isContact;
text = "" // this is most likely unneeded text = ""; // this is most likely unneeded
isCurrentUser = popup.profileStore.pubkey === publicKey isCurrentUser = popup.profileStore.pubkey === publicKey;
showFooter = !isCurrentUser showFooter = !isCurrentUser;
popup.open() popup.open();
if (openNicknamePopup) { if (state == "openNickname") {
nicknamePopup.open() nicknamePopup.open();
} else if (state == "contactRequest") {
sendContactRequestModal.open()
} else if (state == "blockUser") {
blockUser();
} else if (state == "unblockUser") {
unblockUser();
} }
} }
function blockUser() {
contentItem.blockContactConfirmationDialog.contactName = userName;
contentItem.blockContactConfirmationDialog.contactAddress = userPublicKey;
contentItem.blockContactConfirmationDialog.open();
}
function unblockUser() {
contentItem.unblockContactConfirmationDialog.contactName = userName;
contentItem.unblockContactConfirmationDialog.contactAddress = userPublicKey;
contentItem.unblockContactConfirmationDialog.open();
}
header.title: userDisplayName + qsTr("'s Profile") header.title: userDisplayName + qsTr("'s Profile")
header.subTitle: userIsEnsVerified ? userName : Utils.getElidedCompressedPk(userPublicKey) header.subTitle: userIsEnsVerified ? userName : Utils.getElidedCompressedPk(userPublicKey)
header.subTitleElide: Text.ElideMiddle header.subTitleElide: Text.ElideMiddle
@ -315,17 +333,7 @@ StatusModal {
qsTr("Unblock User") : qsTr("Unblock User") :
qsTr("Block User") qsTr("Block User")
type: StatusBaseButton.Type.Danger type: StatusBaseButton.Type.Danger
onClicked: { onClicked: userIsBlocked ? unblockUser() : blockUser()
if (userIsBlocked) {
contentItem.unblockContactConfirmationDialog.contactName = userName;
contentItem.unblockContactConfirmationDialog.contactAddress = userPublicKey;
contentItem.unblockContactConfirmationDialog.open();
return;
}
contentItem.blockContactConfirmationDialog.contactName = userName;
contentItem.blockContactConfirmationDialog.contactAddress = userPublicKey;
contentItem.blockContactConfirmationDialog.open();
}
}, },
StatusFlatButton { StatusFlatButton {

View File

@ -27,7 +27,7 @@ StatusModal {
readonly property int contentMargins: 16 readonly property int contentMargins: 16
} }
contentItem: ColumnLayout { ColumnLayout {
id: content id: content
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right

View File

@ -17,7 +17,6 @@ import shared.controls.chat.menuItems 1.0
StatusPopupMenu { StatusPopupMenu {
id: root id: root
width: emojiContainer.visible ? emojiContainer.width : 176
property var store property var store
property var reactionModel property var reactionModel
@ -26,9 +25,6 @@ StatusPopupMenu {
property string myPublicKey: "" property string myPublicKey: ""
property bool amIChatAdmin: false property bool amIChatAdmin: false
property bool pinMessageAllowedForMembers: false property bool pinMessageAllowedForMembers: false
property bool isMyMessage: {
return root.messageSenderId !== "" && root.messageSenderId == root.myPublicKey
}
property int chatType: Constants.chatType.publicChat property int chatType: Constants.chatType.publicChat
property string messageId: "" property string messageId: ""
@ -49,12 +45,28 @@ StatusPopupMenu {
property bool pinnedMessage: false property bool pinnedMessage: false
property bool canPin: false property bool canPin: false
readonly property bool isMyMessage: {
return root.messageSenderId !== "" && root.messageSenderId == root.myPublicKey;
}
readonly property bool isMe: {
return root.selectedUserPublicKey == root.store.contactsStore.myPublicKey;
}
readonly property bool isMyMutualContact: {
return root.selectedUserPublicKey !== "" && root.store.contactsStore.isMyMutualContact(root.selectedUserPublicKey);
}
readonly property bool isBlockedContact: {
return root.selectedUserPublicKey !== "" && root.store.contactsStore.isBlockedContact(root.selectedUserPublicKey);
}
readonly property bool hasPendingContactRequest: {
return root.selectedUserPublicKey !== "" && root.store.contactsStore.hasPendingContactRequest(root.selectedUserPublicKey);
}
property var setXPosition: function() {return 0} property var setXPosition: function() {return 0}
property var setYPosition: function() {return 0} property var setYPosition: function() {return 0}
property var emojiReactionsReactedByUser: [] property var emojiReactionsReactedByUser: []
signal openProfileClicked(string publicKey) signal openProfileClicked(string publicKey, string state)
signal pinMessage(string messageId) signal pinMessage(string messageId)
signal unpinMessage(string messageId) signal unpinMessage(string messageId)
signal pinnedMessagesLimitReached(string messageId) signal pinnedMessagesLimitReached(string messageId)
@ -66,14 +78,6 @@ StatusPopupMenu {
signal deleteMessage(string messageId) signal deleteMessage(string messageId)
signal editClicked(string messageId) signal editClicked(string messageId)
onHeightChanged: {
root.y = setYPosition()
}
onWidthChanged: {
root.x = setXPosition()
}
function show(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam, emojiReactionsModel) { function show(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam, emojiReactionsModel) {
let newEmojiReactions = [] let newEmojiReactions = []
if (!!emojiReactionsModel) { if (!!emojiReactionsModel) {
@ -91,6 +95,11 @@ StatusPopupMenu {
popup() popup()
} }
onHeightChanged: { root.y = setYPosition(); }
onWidthChanged: { root.x = setXPosition(); }
width: Math.max(emojiContainer.visible ? emojiContainer.width : 0, 200)
Item { Item {
id: emojiContainer id: emojiContainer
width: emojiRow.width width: emojiRow.width
@ -163,22 +172,62 @@ StatusPopupMenu {
ViewProfileMenuItem { ViewProfileMenuItem {
id: viewProfileAction id: viewProfileAction
enabled: root.isProfile && !root.pinnedPopup
onTriggered: { onTriggered: {
root.openProfileClicked(root.selectedUserPublicKey) root.openProfileClicked(root.selectedUserPublicKey, "")
root.close() root.close()
} }
enabled: root.isProfile && !root.pinnedPopup
} }
SendMessageMenuItem { SendMessageMenuItem {
id: sendMessageMenuItem id: sendMessageMenuItem
enabled: root.isProfile && root.store.contactsStore.isMyMutualContact(root.selectedUserPublicKey) enabled: root.isProfile && root.isMyMutualContact && !root.isBlockedContact
onTriggered: { onTriggered: {
root.createOneToOneChat("", root.selectedUserPublicKey, "") root.createOneToOneChat("", root.selectedUserPublicKey, "")
root.close() root.close()
} }
} }
SendContactRequestMenuItem {
enabled: root.isProfile && !root.isMe && !root.isMyMutualContact
&& !root.isBlockedContact && !root.hasPendingContactRequest
onTriggered: {
root.openProfileClicked(root.selectedUserPublicKey, "contactRequest")
root.close()
}
}
StatusMenuItem {
text: qsTr("Block User")
icon.name: "cancel"
icon.color: Style.current.danger
enabled: root.isProfile && !root.isMe && !root.isBlockedContact
onTriggered: {
root.openProfileClicked(root.selectedUserPublicKey, "blockUser")
root.close()
}
}
StatusMenuItem {
text: qsTr("Unblock User")
icon.name: "remove"
enabled: root.isProfile && !root.isMe && root.isBlockedContact
onTriggered: {
root.openProfileClicked(root.selectedUserPublicKey, "unblockUser")
root.close()
}
}
StatusMenuItem {
text: qsTr("Rename")
icon.name: "edit_pencil"
enabled: root.isProfile && !root.isMe
onTriggered: {
root.openProfileClicked(root.selectedUserPublicKey, "openNickname")
root.close()
}
}
StatusMenuItem { StatusMenuItem {
id: replyToMenuItem id: replyToMenuItem
text: qsTr("Reply to") text: qsTr("Reply to")

View File

@ -29,12 +29,12 @@ QtObject {
signal openCreateChatView() signal openCreateChatView()
signal closeCreateChatView() signal closeCreateChatView()
signal openProfilePopupRequested(string publicKey, var parentPopup, bool openNicknamePopup) signal openProfilePopupRequested(string publicKey, var parentPopup, string state)
signal openChangeProfilePicPopup() signal openChangeProfilePicPopup()
signal displayToastMessage(string title, string subTitle, string icon, bool loading, int ephNotifType, string url) signal displayToastMessage(string title, string subTitle, string icon, bool loading, int ephNotifType, string url)
function openProfilePopup(publicKey, parentPopup, openNicknamePopup){ function openProfilePopup(publicKey, parentPopup, state = "") {
openProfilePopupRequested(publicKey, parentPopup, openNicknamePopup); openProfilePopupRequested(publicKey, parentPopup, state);
} }
function openPopup(popupComponent, params = {}) { function openPopup(popupComponent, params = {}) {