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 {
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 {
id: reactionModel
}

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@ import "../components"
Rectangle {
property int iconSize: 16
property bool reopenGroupDialog: false
id: chatTopBarContent
color: Style.current.background
height: 56
@ -40,8 +39,7 @@ Rectangle {
groupInfoPopup.open()
break;
case Constants.chatTypeOneToOne:
chatTopBarContent.reopenGroupDialog = false
profilePopup.openPopup(chatsModel.activeChannel.name, chatsModel.activeChannel.id, chatsModel.activeChannel.identicon)
openProfilePopup(chatsModel.activeChannel.name, chatsModel.activeChannel.id, chatsModel.activeChannel.identicon)
break;
}
}
@ -81,8 +79,6 @@ Rectangle {
}
MouseArea {
property bool menuOpened: false
id: mouseArea
anchors.fill: parent
hoverEnabled: true
@ -99,23 +95,15 @@ Rectangle {
menu = groupContextMenu
}
if (!menuOpened) {
menu.arrowX = menu.width - 40
menu.popup(moreActionsBtn.x, moreActionsBtn.height)
menuOpened = true
} else {
menu.dismiss()
menuOpened = false
}
}
cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton
PopupMenu {
id: chatContextMenu
onClosed: {
mouseArea.menuOpened = false
}
Action {
icon.source: "../../../img/close.svg"
icon.width: chatTopBarContent.iconSize
@ -145,9 +133,6 @@ Rectangle {
PopupMenu {
id: groupContextMenu
onClosed: {
mouseArea.menuOpened = false
}
Action {
icon.source: "../../../img/group_chat.svg"
icon.width: chatTopBarContent.iconSize
@ -184,23 +169,6 @@ Rectangle {
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 "../../../shared"
import "."
import "components"
SplitView {
id: chatView
@ -33,6 +34,61 @@ SplitView {
id: chatColumn
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 {
id: groupInfoPopup
profileClick: {
profilePopup.openPopup.bind(profilePopup)
}
onClosed: {
mouseArea.menuOpened = false
}
@ -143,7 +134,7 @@ ScrollView {
chatsModel.setActiveChannelByIndex(channelContextMenu.channelIndex)
chatGroupsListView.currentIndex = channelContextMenu.channelIndex
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) {
return groupInfoPopup.open()

View File

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

View File

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

View File

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

View File

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

View File

@ -8,14 +8,18 @@ ModalPopup {
id: blockContactConfirmationDialog
height: 237
width: 400
property Popup parentPopup
property string contactAddress: ""
property string contactName: ""
signal blockButtonClicked()
title: qsTrId("block-user")
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
anchors.left: parent.left
anchors.right: parent.right

View File

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