refactor: open profile popup

This commit is contained in:
Richard Ramos 2020-10-02 09:02:56 -04:00 committed by Iuri Matias
parent 261460f8fb
commit 2fb9d569f7
14 changed files with 105 additions and 111 deletions

View File

@ -129,46 +129,10 @@ StackLayout {
} }
} }
ProfilePopup {
id: profilePopup
onBlockButtonClicked: {
blockContactConfirmationDialog.contactName = name
chatColumnLayout.contact = address
blockContactConfirmationDialog.open()
}
onRemoveButtonClicked: {
chatColumnLayout.contactToRemove = address
removeContactConfirmationDialog.open()
}
}
ImagePopup { ImagePopup {
id: imagePopup id: imagePopup
} }
BlockContactConfirmationDialog {
id: blockContactConfirmationDialog
onBlockButtonClicked: {
profileModel.blockContact(blockContactConfirmationDialog.contactAddress)
blockContactConfirmationDialog.close()
profilePopup.close()
}
}
ConfirmationDialog {
id: removeContactConfirmationDialog
// % "Remove contact"
title: qsTrId("remove-contact")
//% "Are you sure you want to remove this contact?"
confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-")
onConfirmButtonClicked: {
if (profileModel.isAdded(chatColumnLayout.contactToRemove)) {
profileModel.removeContact(chatColumnLayout.contactToRemove)
}
removeContactConfirmationDialog.close()
}
}
EmojiReactions { EmojiReactions {
id: reactionModel id: reactionModel
} }

View File

@ -232,7 +232,6 @@ ScrollView {
responseTo: model.responseTo responseTo: model.responseTo
authorCurrentMsg: msgDelegate.ListView.section authorCurrentMsg: msgDelegate.ListView.section
authorPrevMsg: msgDelegate.ListView.previousSection authorPrevMsg: msgDelegate.ListView.previousSection
profileClick: profilePopup.setPopupData.bind(profilePopup)
imageClick: imagePopup.openPopup.bind(imagePopup) imageClick: imagePopup.openPopup.bind(imagePopup)
messageId: model.messageId messageId: model.messageId
emojiReactions: model.emojiReactions emojiReactions: model.emojiReactions

View File

@ -37,7 +37,7 @@ Item {
onLinkActivated: function (linkClicked) { onLinkActivated: function (linkClicked) {
switch (linkClicked) { switch (linkClicked) {
case "shareKey": case "shareKey":
profilePopup.openPopup(profileModel.profile.username, profileModel.profile.pubKey, profileModel.profile.identicon); openProfilePopup(profileModel.profile.username, profileModel.profile.pubKey, profileModel.profile.identicon);
break; break;
case "invite": inviteFriendsPopup.open(); break; case "invite": inviteFriendsPopup.open(); break;
default: //no idea what was clicked default: //no idea what was clicked
@ -48,12 +48,6 @@ Item {
InviteFriendsPopup { InviteFriendsPopup {
id: inviteFriendsPopup id: inviteFriendsPopup
} }
ProfilePopup {
id: profilePopup
height: 330
noFooter: true
}
} }
/*##^## /*##^##
Designer { Designer {

View File

@ -41,7 +41,6 @@ Item {
property int repliedMessageType: replyMessageIndex > -1 ? parseInt(chatsModel.messageList.getMessageData(replyMessageIndex, "contentType")) : 0; property int repliedMessageType: replyMessageIndex > -1 ? parseInt(chatsModel.messageList.getMessageData(replyMessageIndex, "contentType")) : 0;
property string repliedMessageImage: replyMessageIndex > -1 ? chatsModel.messageList.getMessageData(replyMessageIndex, "image") : ""; property string repliedMessageImage: replyMessageIndex > -1 ? chatsModel.messageList.getMessageData(replyMessageIndex, "image") : "";
property var profileClick: function () {}
property var imageClick: function () {} property var imageClick: function () {}
property var scrollToBottom: function () {} property var scrollToBottom: function () {}
@ -75,11 +74,9 @@ Item {
break; break;
} }
} }
profileClick(userName, fromAuthor, identicon, "", nickname);
messageContextMenu.isProfile = !!isProfileClick messageContextMenu.isProfile = !!isProfileClick
messageContextMenu.isSticker = isSticker messageContextMenu.isSticker = isSticker
messageContextMenu.popup() messageContextMenu.show(userName, fromAuthor, identicon, "", nickname)
// Position the center of the menu where the mouse is // Position the center of the menu where the mouse is
messageContextMenu.x = messageContextMenu.x - messageContextMenu.width / 2 messageContextMenu.x = messageContextMenu.x - messageContextMenu.width / 2
} }

View File

@ -35,7 +35,7 @@ Item {
if (link.startsWith('//')) { if (link.startsWith('//')) {
let pk = link.replace("//", ""); let pk = link.replace("//", "");
profilePopup.openPopup(chatsModel.userNameOrAlias(pk), pk, chatsModel.generateIdenticon(pk)) openProfilePopup(chatsModel.userNameOrAlias(pk), pk, chatsModel.generateIdenticon(pk))
return; return;
} }

View File

@ -8,7 +8,6 @@ import "../components"
Rectangle { Rectangle {
property int iconSize: 16 property int iconSize: 16
property bool reopenGroupDialog: false
id: chatTopBarContent id: chatTopBarContent
color: Style.current.background color: Style.current.background
height: 56 height: 56
@ -40,8 +39,7 @@ Rectangle {
groupInfoPopup.open() groupInfoPopup.open()
break; break;
case Constants.chatTypeOneToOne: case Constants.chatTypeOneToOne:
chatTopBarContent.reopenGroupDialog = false openProfilePopup(chatsModel.activeChannel.name, chatsModel.activeChannel.id, chatsModel.activeChannel.identicon)
profilePopup.openPopup(chatsModel.activeChannel.name, chatsModel.activeChannel.id, chatsModel.activeChannel.identicon)
break; break;
} }
} }
@ -81,8 +79,6 @@ Rectangle {
} }
MouseArea { MouseArea {
property bool menuOpened: false
id: mouseArea id: mouseArea
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
@ -99,23 +95,15 @@ Rectangle {
menu = groupContextMenu menu = groupContextMenu
} }
if (!menuOpened) { menu.arrowX = menu.width - 40
menu.arrowX = menu.width - 40 menu.popup(moreActionsBtn.x, moreActionsBtn.height)
menu.popup(moreActionsBtn.x, moreActionsBtn.height)
menuOpened = true
} else {
menu.dismiss()
menuOpened = false
}
} }
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
PopupMenu { PopupMenu {
id: chatContextMenu id: chatContextMenu
onClosed: {
mouseArea.menuOpened = false
}
Action { Action {
icon.source: "../../../img/close.svg" icon.source: "../../../img/close.svg"
icon.width: chatTopBarContent.iconSize icon.width: chatTopBarContent.iconSize
@ -145,9 +133,6 @@ Rectangle {
PopupMenu { PopupMenu {
id: groupContextMenu id: groupContextMenu
onClosed: {
mouseArea.menuOpened = false
}
Action { Action {
icon.source: "../../../img/group_chat.svg" icon.source: "../../../img/group_chat.svg"
icon.width: chatTopBarContent.iconSize icon.width: chatTopBarContent.iconSize
@ -184,23 +169,6 @@ Rectangle {
GroupInfoPopup { GroupInfoPopup {
id: groupInfoPopup id: groupInfoPopup
profileClick: {
profilePopup.openPopup.bind(profilePopup)
chatTopBarContent.reopenGroupDialog = true
}
onClosed: {
mouseArea.menuOpened = false
}
}
ProfilePopup {
id: profilePopup
onClosed: {
if (!groupInfoPopup.opened && chatTopBarContent.reopenGroupDialog) {
groupInfoPopup.open()
chatTopBarContent.reopenGroupDialog = false
}
}
} }
} }
} }

View File

@ -4,6 +4,7 @@ import Qt.labs.settings 1.0
import "../../../imports" import "../../../imports"
import "../../../shared" import "../../../shared"
import "." import "."
import "components"
SplitView { SplitView {
id: chatView id: chatView
@ -33,6 +34,61 @@ SplitView {
id: chatColumn id: chatColumn
chatGroupsListViewCount: contactsColumn.chatGroupsListViewCount chatGroupsListViewCount: contactsColumn.chatGroupsListViewCount
} }
function openProfilePopup(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam, parentPopup){
var popup = profilePopupComponent.createObject(chatView);
if(parentPopup){
popup.parentPopup = parentPopup;
}
popup.openPopup(profileModel.profile.pubKey !== fromAuthorParam, userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam);
}
property Component profilePopupComponent: ProfilePopup {
id: profilePopup
height: 450
onClosed: {
if(profilePopup.parentPopup){
profilePopup.parentPopup.close();
}
destroy()
}
onBlockButtonClicked: {
blockContactConfirmationDialog.contactName = name;
blockContactConfirmationDialog.contactAddress = address;
blockContactConfirmationDialog.parentPopup = profilePopup;
blockContactConfirmationDialog.open();
}
onRemoveButtonClicked: {
chatColumn.contactToRemove = address;
removeContactConfirmationDialog.parentPopup = profilePopup;
removeContactConfirmationDialog.open();
}
}
BlockContactConfirmationDialog {
id: blockContactConfirmationDialog
onBlockButtonClicked: {
profileModel.blockContact(blockContactConfirmationDialog.contactAddress)
blockContactConfirmationDialog.parentPopup.close()
blockContactConfirmationDialog.close();
}
}
ConfirmationDialog {
id: removeContactConfirmationDialog
// % "Remove contact"
title: qsTrId("remove-contact")
//% "Are you sure you want to remove this contact?"
confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-")
onConfirmButtonClicked: {
if (profileModel.isAdded(chatColumn.contactToRemove)) {
profileModel.removeContact(chatColumn.contactToRemove)
}
removeContactConfirmationDialog.parentPopup.close();
removeContactConfirmationDialog.close();
}
}
} }
/*##^## /*##^##

View File

@ -73,17 +73,8 @@ ScrollView {
} }
ProfilePopup {
id: profilePopup
height: 330
noFooter: true
}
GroupInfoPopup { GroupInfoPopup {
id: groupInfoPopup id: groupInfoPopup
profileClick: {
profilePopup.openPopup.bind(profilePopup)
}
onClosed: { onClosed: {
mouseArea.menuOpened = false mouseArea.menuOpened = false
} }
@ -143,7 +134,7 @@ ScrollView {
chatsModel.setActiveChannelByIndex(channelContextMenu.channelIndex) chatsModel.setActiveChannelByIndex(channelContextMenu.channelIndex)
chatGroupsListView.currentIndex = channelContextMenu.channelIndex chatGroupsListView.currentIndex = channelContextMenu.channelIndex
if (channelContextMenu.chatType === Constants.chatTypeOneToOne) { if (channelContextMenu.chatType === Constants.chatTypeOneToOne) {
return profilePopup.openPopup(channelContextMenu.chatName, channelContextMenu.chatId, channelContextMenu.chatIdenticon) return openProfilePopup(channelContextMenu.chatName, channelContextMenu.chatId, channelContextMenu.chatIdenticon)
} }
if (channelContextMenu.chatType === Constants.chatTypePrivateGroupChat) { if (channelContextMenu.chatType === Constants.chatTypePrivateGroupChat) {
return groupInfoPopup.open() return groupInfoPopup.open()

View File

@ -13,7 +13,6 @@ ModalPopup {
property int memberCount: 1 property int memberCount: 1
readonly property int maxMembers: 10 readonly property int maxMembers: 10
property var pubKeys: [] property var pubKeys: []
property var profileClick: function() {}
function resetSelectedMembers(){ function resetSelectedMembers(){
pubKeys = []; pubKeys = [];
@ -292,10 +291,7 @@ ModalPopup {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: openProfilePopup(model.userName, model.pubKey, model.identicon, '', contactRow.nickname, popup)
popup.profileClick(model.userName, model.pubKey, model.identicon, '', contactRow.nickname)
popup.close()
}
} }
} }

View File

@ -14,6 +14,21 @@ PopupMenu {
id: messageContextMenu id: messageContextMenu
width: messageContextMenu.isProfile ? profileHeader.width : emojiContainer.width width: messageContextMenu.isProfile ? profileHeader.width : emojiContainer.width
property var identicon: ""
property var userName: ""
property string nickname: ""
property var fromAuthor: ""
property var text: ""
function show(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam){
userName = userNameParam || ""
nickname = nicknameParam || ""
fromAuthor = fromAuthorParam || ""
identicon = identiconParam || ""
text = textParam || ""
popup();
}
Item { Item {
id: emojiContainer id: emojiContainer
visible: !messageContextMenu.isProfile visible: !messageContextMenu.isProfile
@ -51,7 +66,7 @@ PopupMenu {
StatusImageIdenticon { StatusImageIdenticon {
id: profileImage id: profileImage
source: profilePopup.identicon source: identicon
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 4 anchors.topMargin: 4
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
@ -59,7 +74,7 @@ PopupMenu {
StyledText { StyledText {
id: username id: username
text: Utils.removeStatusEns(profilePopup.userName) text: Utils.removeStatusEns(userName)
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
anchors.top: profileImage.bottom anchors.top: profileImage.bottom
@ -83,7 +98,7 @@ PopupMenu {
profileHeader.hovered = false profileHeader.hovered = false
} }
onClicked: { onClicked: {
profilePopup.open() openProfilePopup(userName, fromAuthor, identicon);
messageContextMenu.close() messageContextMenu.close()
} }
} }
@ -98,7 +113,7 @@ PopupMenu {
//% "View profile" //% "View profile"
text: qsTrId("view-profile") text: qsTrId("view-profile")
onTriggered: { onTriggered: {
profilePopup.open() openProfilePopup(userName, fromAuthor, identicon);
messageContextMenu.close() messageContextMenu.close()
} }
icon.source: "../../../img/profileActive.svg" icon.source: "../../../img/profileActive.svg"
@ -112,7 +127,7 @@ PopupMenu {
//% "Reply to" //% "Reply to"
qsTrId("reply-to") qsTrId("reply-to")
onTriggered: { onTriggered: {
messageContextMenu.isProfile ? chatsModel.joinChat(profilePopup.fromAuthor, Constants.chatTypeOneToOne) : showReplyArea() messageContextMenu.isProfile ? chatsModel.joinChat(fromAuthor, Constants.chatTypeOneToOne) : showReplyArea()
messageContextMenu.close() messageContextMenu.close()
} }
icon.source: "../../../img/messageActive.svg" icon.source: "../../../img/messageActive.svg"

View File

@ -8,6 +8,10 @@ import "./"
ModalPopup { ModalPopup {
id: popup id: popup
property Popup parentPopup
property var identicon: "" property var identicon: ""
property var userName: "" property var userName: ""
property string nickname: "" property string nickname: ""
@ -33,8 +37,9 @@ ModalPopup {
alias = chatsModel.alias(this.fromAuthor) || "" alias = chatsModel.alias(this.fromAuthor) || ""
} }
function openPopup(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) { function openPopup(showFooter, userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) {
setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam)
noFooter = !showFooter;
popup.open() popup.open()
} }
@ -327,10 +332,10 @@ ModalPopup {
label: qsTrId("send-message") label: qsTrId("send-message")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
onClicked: { onClicked: {
profilePopup.close()
if (tabBar.currentIndex !== 0) if (tabBar.currentIndex !== 0)
tabBar.currentIndex = 0 tabBar.currentIndex = 0
chatsModel.joinChat(fromAuthor, Constants.chatTypeOneToOne) chatsModel.joinChat(fromAuthor, Constants.chatTypeOneToOne)
popup.close()
} }
} }
@ -362,8 +367,8 @@ ModalPopup {
popup.removeButtonClicked(fromAuthor) popup.removeButtonClicked(fromAuthor)
} else { } else {
profileModel.addContact(fromAuthor) profileModel.addContact(fromAuthor)
profilePopup.close()
} }
profilePopup.close()
} }
} }
} }

View File

@ -93,7 +93,7 @@ Rectangle {
icon.width: menuButton.iconSize icon.width: menuButton.iconSize
icon.height: menuButton.iconSize icon.height: menuButton.iconSize
text: qsTrId("view-profile") text: qsTrId("view-profile")
onTriggered: profileClick(name, address, identicon, "", localNickname) onTriggered: profileClick(true, name, address, identicon, "", localNickname)
enabled: true enabled: true
} }
Action { Action {

View File

@ -8,14 +8,18 @@ ModalPopup {
id: blockContactConfirmationDialog id: blockContactConfirmationDialog
height: 237 height: 237
width: 400 width: 400
property Popup parentPopup
property string contactAddress: "" property string contactAddress: ""
property string contactName: "" property string contactName: ""
signal blockButtonClicked() signal blockButtonClicked()
title: qsTrId("block-user") title: qsTrId("block-user")
StyledText { StyledText {
//% "Blocking will remove any messages you received from " + blockContactConfirmationDialog.contactName + " and stop new messages from reaching you." //%
text: qsTrId("blocking-will-remove-any-messages-you-received-from-----blockcontactconfirmationdialog-contactname-----and-stop-new-messages-from-reaching-you-") text: qsTr("Blocking will remove any messages you received from %1 and stop new messages from reaching you.").arg(contactName)
font.pixelSize: 15 font.pixelSize: 15
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right

View File

@ -6,6 +6,10 @@ import "./"
ModalPopup { ModalPopup {
id: confirmationDialog id: confirmationDialog
property Popup parentPopup
height: 186 height: 186
width: 400 width: 400
//% "Confirm your action" //% "Confirm your action"
@ -15,6 +19,7 @@ ModalPopup {
property string confirmButtonLabel: qsTrId("close-app-button") property string confirmButtonLabel: qsTrId("close-app-button")
//% "Are you sure you want to this?" //% "Are you sure you want to this?"
property string confirmationText: qsTrId("are-you-sure-you-want-to-this-") property string confirmationText: qsTrId("are-you-sure-you-want-to-this-")
signal confirmButtonClicked() signal confirmButtonClicked()
Text { Text {