Skip to content

Commit

Permalink
refactor into a single ProfileContextMenu component
Browse files Browse the repository at this point in the history
refactor into a single ProfileContextMenu component

refactor into a single ProfileContextMenu component

simplify imports

remove unused store field

move methods from utils to contacts store

remove onClosed signal

remove unused param
  • Loading branch information
iurimatias committed Sep 17, 2024
1 parent 88d1f1f commit 2349473
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 614 deletions.
2 changes: 1 addition & 1 deletion storybook/pages/MessageContextMenuPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ SplitView {
ProfileContextMenu {
anchors.centerIn: parent
hideDisabledItems: false
profileType: profileTypeSelector.currentText
profileType: profileTypeSelector.currentValue
trustStatus: trustStatusSelector.currentValue
contactType: contactTypeSelector.currentValue
ensVerified: ensVerifiedCheckBox.checked
Expand Down
8 changes: 1 addition & 7 deletions ui/app/AppLayouts/Chat/panels/UserListPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ Item {
ringSettings.ringSpecModel: model.colorHash
onClicked: {
if (mouse.button === Qt.RightButton) {
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = Utils.getProfileContext(model.pubKey, userProfile.pubKey)
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = root.store.contactsStore.getProfileContext(model.pubKey, userProfile.pubKey)

Global.openMenu(profileContextMenuComponent, this, {
profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname,
myPublicKey: root.store.myPublicKey(),
selectedUserPublicKey: model.pubKey,
selectedUserDisplayName: nickName || userName,
selectedUserIcon: model.icon,
Expand Down Expand Up @@ -171,10 +170,8 @@ Item {
id: profileContextMenuComponent

ProfileContextMenu {
store: root.store
margins: 8
onOpenProfileClicked: (publicKey) => {
console.log("UserListPanel.qml:1: open profile clicked", publicKey)
Global.openProfilePopup(publicKey, null)
}
onCreateOneToOneChat: (communityId, chatId, ensName) => {
Expand Down Expand Up @@ -215,9 +212,6 @@ Item {
const contactDetails = publicKey === "" ? {} : Utils.getContactDetailsAsJson(publicKey, true, true)
Global.blockContactRequested(publicKey, contactDetails)
}
onClosed: {
destroy()
}
}
}
}
7 changes: 1 addition & 6 deletions ui/app/AppLayouts/Communities/panels/MembersTabPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Item {

onClicked: {
if(mouse.button === Qt.RightButton) {
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = Utils.getProfileContext(model.pubKey, Global.userProfile.pubKey)
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = root.rootStore.contactsStore.getProfileContext(model.pubKey, Global.userProfile.pubKey)

Global.openMenu(memberContextMenuComponent, this, {
profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname,
Expand All @@ -325,8 +325,6 @@ Item {

ProfileContextMenu {
id: memberContextMenuView
store: root.rootStore
myPublicKey: Global.userProfile.pubKey

onOpenProfileClicked: {
Global.openProfilePopup(publicKey, null)
Expand All @@ -335,9 +333,6 @@ Item {
Global.changeAppSectionBySectionType(Constants.appSection.chat)
root.rootStore.chatCommunitySectionModule.createOneToOneChat(communityId, chatId, ensName)
}
onClosed: {
destroy()
}
}
}

Expand Down
38 changes: 38 additions & 0 deletions ui/app/AppLayouts/Profile/stores/ContactsStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,42 @@ QtObject {
function getLinkToProfile(publicKey) {
return root.contactsModule.shareUserUrlWithData(publicKey)
}

function getProfileContext(publicKey, myPublicKey, isBridgedAccount = false) {
const contactDetails = Utils.getContactDetailsAsJson(publicKey, true, true);
const isBlocked = contactDetails ? contactDetails.isBlocked : false;

const profileType = getProfileType(publicKey, myPublicKey, isBridgedAccount, isBlocked);
const contactType = getContactType(contactDetails ? contactDetails.contactRequestState : Constants.ContactRequestState.None, contactDetails ? contactDetails.isContact : false);
const trustStatus = contactDetails ? contactDetails.trustStatus : Constants.trustStatus.unknown;
const ensVerified = contactDetails ? contactDetails.ensVerified : false;
const onlineStatus = contactDetails ? contactDetails.onlineStatus : Constants.onlineStatus.unknown;
const hasLocalNickname = contactDetails ? !!contactDetails.localNickname : false;

return { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname };
}

function getProfileType(publicKey, myPublicKey, isBridgedAccount, isBlocked) {
if (publicKey === myPublicKey) {
return Constants.profileType.self;
}
if (isBridgedAccount) {
return Constants.profileType.bridged;
}
if (isBlocked) {
return Constants.profileType.blocked;
}
return Constants.profileType.regular;
}

function getContactType(contactRequestState, isContact) {
switch (contactRequestState) {
case Constants.ContactRequestState.Received:
return Constants.contactType.contactRequestReceived;
case Constants.ContactRequestState.Sent:
return Constants.contactType.contactRequestSent;
default:
return isContact ? Constants.contactType.contact : Constants.contactType.nonContact;
}
}
}
6 changes: 1 addition & 5 deletions ui/app/AppLayouts/Profile/views/ContactsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SettingsContentBase {
}

function openContextMenu(publicKey, name, icon) {
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = Utils.getProfileContext(publicKey, root.contactsStore.myPublicKey)
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = root.contactsStore.getProfileContext(publicKey, root.contactsStore.myPublicKey)

Global.openMenu(contactContextMenuComponent, this, {
profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname,
Expand All @@ -54,7 +54,6 @@ SettingsContentBase {
id: contactContextMenuComponent
ProfileContextMenu {
id: contactContextMenu
store: ({contactsStore: root.contactsStore})

onOpenProfileClicked: (pubkey) => {
Global.openProfilePopup(pubkey, null, null)
Expand Down Expand Up @@ -96,9 +95,6 @@ SettingsContentBase {
const contactDetails = publicKey === "" ? {} : Utils.getContactDetailsAsJson(publicKey, true, true)
Global.blockContactRequested(publicKey, contactDetails)
}
onClosed: {
destroy()
}
}
}
SearchBox {
Expand Down
9 changes: 1 addition & 8 deletions ui/imports/shared/views/chat/MessageView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Loader {
}
const publicKey = isReply ? quotedMessageFrom : root.senderId
const isBridgedAccount = isReply ? (quotedMessageContentType === Constants.messageContentType.bridgeMessageType) : root.isBridgeMessage
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = Utils.getProfileContext(publicKey, root.rootStore.contactsStore.myPublicKey, isBridgedAccount)
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = root.contactsStore.getProfileContext(publicKey, root.rootStore.contactsStore.myPublicKey, isBridgedAccount)

const params = { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname,
selectedUserPublicKey: isReply ? quotedMessageFrom : root.senderId,
Expand Down Expand Up @@ -1173,10 +1173,7 @@ Loader {
Component {
id: profileContextMenuComponent
ProfileContextMenu {
store: root.rootStore

onOpenProfileClicked: (publicKey) => {
console.log("MessageView.qml:1: open profile clicked", publicKey)
Global.openProfilePopup(publicKey, null)
}
onCreateOneToOneChat: (communityId, chatId, ensName) => {
Expand Down Expand Up @@ -1220,10 +1217,6 @@ Loader {
onOpened: {
root.setMessageActive(root.messageId, true)
}
onClosed: {
root.setMessageActive(root.messageId, false)
destroy()
}
}
}
Component {
Expand Down
Loading

0 comments on commit 2349473

Please sign in to comment.