Access to user profile encapsulated in profile store

This commit is contained in:
Michał Cieślak 2024-10-15 11:31:46 +02:00 committed by Michał
parent dc3a1ca39b
commit c4828a094b
5 changed files with 76 additions and 69 deletions

View File

@ -35,7 +35,7 @@ QtObject {
// Each `ChatLayout` has its own chatCommunitySectionModule // Each `ChatLayout` has its own chatCommunitySectionModule
// (on the backend chat and community sections share the same module since they are actually the same) // (on the backend chat and community sections share the same module since they are actually the same)
property var chatCommunitySectionModule property var chatCommunitySectionModule
readonly property var sectionDetails: _d.sectionDetailsInstantiator.count ? _d.sectionDetailsInstantiator.objectAt(0) : null readonly property var sectionDetails: d.sectionDetailsInstantiator.count ? d.sectionDetailsInstantiator.objectAt(0) : null
property var communityItemsModel: chatCommunitySectionModule.model property var communityItemsModel: chatCommunitySectionModule.model
@ -148,9 +148,9 @@ QtObject {
readonly property string overviewChartData: chatCommunitySectionModule.overviewChartData readonly property string overviewChartData: chatCommunitySectionModule.overviewChartData
readonly property bool isUserAllowedToSendMessage: _d.isUserAllowedToSendMessage readonly property bool isUserAllowedToSendMessage: d.isUserAllowedToSendMessage
readonly property string chatInputPlaceHolderText: _d.chatInputPlaceHolderText readonly property string chatInputPlaceHolderText: d.chatInputPlaceHolderText
readonly property var oneToOneChatContact: _d.oneToOneChatContact readonly property var oneToOneChatContact: d.oneToOneChatContact
// Since qml component doesn't follow encaptulation from the backend side, we're introducing // Since qml component doesn't follow encaptulation from the backend side, we're introducing
// a method which will return appropriate chat content module for selected chat/channel // a method which will return appropriate chat content module for selected chat/channel
function currentChatContentModule() { function currentChatContentModule() {
@ -288,8 +288,6 @@ QtObject {
property var communitiesModuleInst: communitiesModule property var communitiesModuleInst: communitiesModule
property var communitiesList: communitiesModuleInst.model property var communitiesList: communitiesModuleInst.model
property var userProfileInst: userProfile
property string signingPhrase: walletSection.signingPhrase property string signingPhrase: walletSection.signingPhrase
property string channelEmoji: chatCommunitySectionModule && chatCommunitySectionModule.emoji ? chatCommunitySectionModule.emoji : "" property string channelEmoji: chatCommunitySectionModule && chatCommunitySectionModule.emoji ? chatCommunitySectionModule.emoji : ""
@ -306,7 +304,7 @@ QtObject {
readonly property int loginType: getLoginType() readonly property int loginType: getLoginType()
property string name: userProfileInst.name property string name: d.userProfileInst.name
property StickersStore stickersStore: StickersStore { property StickersStore stickersStore: StickersStore {
stickersModule: stickersModuleInst stickersModule: stickersModuleInst
@ -317,7 +315,7 @@ QtObject {
} }
function isCurrentUser(pubkey) { function isCurrentUser(pubkey) {
return userProfileInst.pubKey === pubkey return d.userProfileInst.pubKey === pubkey
} }
function displayName(name, pubkey) { function displayName(name, pubkey) {
@ -325,7 +323,7 @@ QtObject {
} }
function myPublicKey() { function myPublicKey() {
return userProfileInst.pubKey return d.userProfileInst.pubKey
} }
function createCommunity(args = { function createCommunity(args = {
@ -601,12 +599,12 @@ QtObject {
} }
function getLoginType() { function getLoginType() {
if(!userProfileInst) if(!d.userProfileInst)
return Constants.LoginType.Password return Constants.LoginType.Password
if(userProfileInst.usingBiometricLogin) if(d.userProfileInst.usingBiometricLogin)
return Constants.LoginType.Biometrics return Constants.LoginType.Biometrics
if(userProfileInst.isKeycardUser) if(d.userProfileInst.isKeycardUser)
return Constants.LoginType.Keycard return Constants.LoginType.Keycard
return Constants.LoginType.Password return Constants.LoginType.Password
} }
@ -638,7 +636,10 @@ QtObject {
} }
readonly property QtObject _d: QtObject { readonly property QtObject _d: QtObject {
id: _d id: d
readonly property var userProfileInst: userProfile
readonly property var sectionDetailsInstantiator: Instantiator { readonly property var sectionDetailsInstantiator: Instantiator {
model: SortFilterProxyModel { model: SortFilterProxyModel {
sourceModel: mainModuleInst.sectionsModel sourceModel: mainModuleInst.sectionsModel
@ -664,51 +665,51 @@ QtObject {
readonly property bool amIMember: chatCommunitySectionModule ? chatCommunitySectionModule.amIMember : false readonly property bool amIMember: chatCommunitySectionModule ? chatCommunitySectionModule.amIMember : false
property var oneToOneChatContact: undefined property var oneToOneChatContact: undefined
readonly property string oneToOneChatContactName: !!_d.oneToOneChatContact ? ProfileUtils.displayName(_d.oneToOneChatContact.localNickname, readonly property string oneToOneChatContactName: !!d.oneToOneChatContact ? ProfileUtils.displayName(d.oneToOneChatContact.localNickname,
_d.oneToOneChatContact.name, d.oneToOneChatContact.name,
_d.oneToOneChatContact.displayName, d.oneToOneChatContact.displayName,
_d.oneToOneChatContact.alias) : "" d.oneToOneChatContact.alias) : ""
//Update oneToOneChatContact when the contact is updated //Update oneToOneChatContact when the contact is updated
readonly property var myContactsModelConnection: Connections { readonly property var myContactsModelConnection: Connections {
target: root.contactsStore.myContactsModel ?? null target: root.contactsStore.myContactsModel ?? null
enabled: _d.activeChatType === Constants.chatType.oneToOne enabled: d.activeChatType === Constants.chatType.oneToOne
function onItemChanged(pubKey) { function onItemChanged(pubKey) {
if (pubKey === _d.activeChatId) { if (pubKey === d.activeChatId) {
_d.oneToOneChatContact = Utils.getContactDetailsAsJson(pubKey, false) d.oneToOneChatContact = Utils.getContactDetailsAsJson(pubKey, false)
} }
} }
} }
readonly property var receivedContactsReqModelConnection: Connections { readonly property var receivedContactsReqModelConnection: Connections {
target: root.contactsStore.receivedContactRequestsModel ?? null target: root.contactsStore.receivedContactRequestsModel ?? null
enabled: _d.activeChatType === Constants.chatType.oneToOne enabled: d.activeChatType === Constants.chatType.oneToOne
function onItemChanged(pubKey) { function onItemChanged(pubKey) {
if (pubKey === _d.activeChatId) { if (pubKey === d.activeChatId) {
_d.oneToOneChatContact = Utils.getContactDetailsAsJson(pubKey, false) d.oneToOneChatContact = Utils.getContactDetailsAsJson(pubKey, false)
} }
} }
} }
readonly property var sentContactReqModelConnection: Connections { readonly property var sentContactReqModelConnection: Connections {
target: root.contactsStore.sentContactRequestsModel ?? null target: root.contactsStore.sentContactRequestsModel ?? null
enabled: _d.activeChatType === Constants.chatType.oneToOne enabled: d.activeChatType === Constants.chatType.oneToOne
function onItemChanged(pubKey) { function onItemChanged(pubKey) {
if (pubKey === _d.activeChatId) { if (pubKey === d.activeChatId) {
_d.oneToOneChatContact = Utils.getContactDetailsAsJson(pubKey, false) d.oneToOneChatContact = Utils.getContactDetailsAsJson(pubKey, false)
} }
} }
} }
readonly property bool isUserAllowedToSendMessage: { readonly property bool isUserAllowedToSendMessage: {
if (_d.activeChatType === Constants.chatType.oneToOne && _d.oneToOneChatContact) { if (d.activeChatType === Constants.chatType.oneToOne && d.oneToOneChatContact) {
return _d.oneToOneChatContact.contactRequestState === Constants.ContactRequestState.Mutual return d.oneToOneChatContact.contactRequestState === Constants.ContactRequestState.Mutual
} else if (_d.activeChatType === Constants.chatType.privateGroupChat) { } else if (d.activeChatType === Constants.chatType.privateGroupChat) {
return _d.amIMember return d.amIMember
} else if (_d.activeChatType === Constants.chatType.communityChat) { } else if (d.activeChatType === Constants.chatType.communityChat) {
return currentChatContentModule().chatDetails.canPost return currentChatContentModule().chatDetails.canPost
} }
@ -716,10 +717,10 @@ QtObject {
} }
readonly property string chatInputPlaceHolderText: { readonly property string chatInputPlaceHolderText: {
if(!_d.isUserAllowedToSendMessage && _d.activeChatType === Constants.chatType.privateGroupChat) { if(!d.isUserAllowedToSendMessage && d.activeChatType === Constants.chatType.privateGroupChat) {
return qsTr("You need to be a member of this group to send messages") return qsTr("You need to be a member of this group to send messages")
} else if(!_d.isUserAllowedToSendMessage && _d.activeChatType === Constants.chatType.oneToOne) { } else if(!d.isUserAllowedToSendMessage && d.activeChatType === Constants.chatType.oneToOne) {
return qsTr("Add %1 as a contact to send a message").arg(_d.oneToOneChatContactName) return qsTr("Add %1 as a contact to send a message").arg(d.oneToOneChatContactName)
} }
return qsTr("Message") return qsTr("Message")
@ -727,8 +728,8 @@ QtObject {
//Update oneToOneChatContact when activeChat id changes //Update oneToOneChatContact when activeChat id changes
Binding on oneToOneChatContact { Binding on oneToOneChatContact {
when: _d.activeChatId && _d.activeChatType === Constants.chatType.oneToOne when: d.activeChatId && d.activeChatType === Constants.chatType.oneToOne
value: Utils.getContactDetailsAsJson(_d.activeChatId, false) value: Utils.getContactDetailsAsJson(d.activeChatId, false)
restoreMode: Binding.RestoreBindingOrValue restoreMode: Binding.RestoreBindingOrValue
} }
} }

View File

@ -23,14 +23,14 @@ import SortFilterProxyModel 0.2
import AppLayouts.Communities.popups 1.0 import AppLayouts.Communities.popups 1.0
import AppLayouts.Communities.panels 1.0 import AppLayouts.Communities.panels 1.0
import AppLayouts.Profile.stores 1.0 import AppLayouts.Profile.stores 1.0 as ProfileStores
import AppLayouts.Chat.stores 1.0 as ChatStores
import "../helpers" import "../helpers"
import "../controls" import "../controls"
import "../popups" import "../popups"
import "../panels" import "../panels"
import "../../Wallet" import "../../Wallet"
import "../stores"
Item { Item {
id: root id: root
@ -40,9 +40,9 @@ Item {
property var parentModule property var parentModule
property SharedStores.RootStore sharedRootStore property SharedStores.RootStore sharedRootStore
property RootStore rootStore property ChatStores.RootStore rootStore
property CreateChatPropertiesStore createChatPropertiesStore property ChatStores.CreateChatPropertiesStore createChatPropertiesStore
property ContactsStore contactsStore property ProfileStores.ContactsStore contactsStore
property var emojiPopup property var emojiPopup
property var stickersPopup property var stickersPopup
@ -101,11 +101,11 @@ Item {
model: !!d.activeChatContentModule ? d.activeChatContentModule.inputAreaModule.urlsModel : null model: !!d.activeChatContentModule ? d.activeChatContentModule.inputAreaModule.urlsModel : null
} }
readonly property UsersStore activeUsersStore: UsersStore { readonly property ChatStores.UsersStore activeUsersStore: ChatStores.UsersStore {
usersModule: !!d.activeChatContentModule ? d.activeChatContentModule.usersModule : null usersModule: !!d.activeChatContentModule ? d.activeChatContentModule.usersModule : null
} }
readonly property MessageStore activeMessagesStore: MessageStore { readonly property ChatStores.MessageStore activeMessagesStore: ChatStores.MessageStore {
messageModule: d.activeChatContentModule ? d.activeChatContentModule.messagesModule : null messageModule: d.activeChatContentModule ? d.activeChatContentModule.messagesModule : null
chatSectionModule: root.rootStore.chatCommunitySectionModule chatSectionModule: root.rootStore.chatCommunitySectionModule
} }
@ -372,7 +372,7 @@ Item {
} }
onKeyUpPress: { onKeyUpPress: {
d.activeMessagesStore.setEditModeOnLastMessage(root.rootStore.userProfileInst.pubKey) d.activeMessagesStore.setEditModeOnLastMessage(root.contactsStore.myPublicKey)
} }
onLinkPreviewReloaded: (link) => d.activeChatContentModule.inputAreaModule.reloadLinkPreview(link) onLinkPreviewReloaded: (link) => d.activeChatContentModule.inputAreaModule.reloadLinkPreview(link)

View File

@ -8,8 +8,6 @@ import SortFilterProxyModel 0.2
import AppLayouts.Profile.stores 1.0 as ProfileStores import AppLayouts.Profile.stores 1.0 as ProfileStores
import AppLayouts.Wallet.stores 1.0 as WalletStore import AppLayouts.Wallet.stores 1.0 as WalletStore
import "../Profile/stores"
QtObject { QtObject {
id: root id: root
@ -27,12 +25,12 @@ QtObject {
readonly property int loginType: getLoginType() readonly property int loginType: getLoginType()
function getLoginType() { function getLoginType() {
if(!userProfileInst) if(!d.userProfileInst)
return Constants.LoginType.Password return Constants.LoginType.Password
if(userProfileInst.usingBiometricLogin) if(d.userProfileInst.usingBiometricLogin)
return Constants.LoginType.Biometrics return Constants.LoginType.Biometrics
if(userProfileInst.isKeycardUser) if(d.userProfileInst.isKeycardUser)
return Constants.LoginType.Keycard return Constants.LoginType.Keycard
return Constants.LoginType.Password return Constants.LoginType.Password
} }
@ -136,7 +134,7 @@ QtObject {
appSearchModule: root.mainModuleInst.appSearchModule appSearchModule: root.mainModuleInst.appSearchModule
} }
property ProfileSectionStore profileSectionStore: ProfileSectionStore { property ProfileStores.ProfileSectionStore profileSectionStore: ProfileStores.ProfileSectionStore {
} }
property var chatSearchModel: mainModuleInst.chatSearchModel property var chatSearchModel: mainModuleInst.chatSearchModel
@ -149,7 +147,7 @@ QtObject {
mainModuleInst.switchTo(sectionId, chatId) mainModuleInst.switchTo(sectionId, chatId)
} }
property var userProfileInst: userProfile
readonly property var accounts: walletSectionAccounts.accounts readonly property var accounts: walletSectionAccounts.accounts
property ProfileStores.ContactsStore contactStore: profileSectionStore.contactsStore property ProfileStores.ContactsStore contactStore: profileSectionStore.contactsStore
@ -166,6 +164,12 @@ QtObject {
property var flatNetworks: networksModule.flatNetworks property var flatNetworks: networksModule.flatNetworks
readonly property QtObject _d: QtObject {
id: d
readonly property var userProfileInst: userProfile
}
function getEtherscanLink(chainID) { function getEtherscanLink(chainID) {
return networksModule.getBlockExplorerURL(chainID) return networksModule.getBlockExplorerURL(chainID)
} }
@ -207,7 +211,7 @@ QtObject {
} }
function setCurrentUserStatus(newStatus) { function setCurrentUserStatus(newStatus) {
if (userProfileInst && userProfileInst.currentUserStatus !== newStatus) { if (d.userProfileInst && d.userProfileInst.currentUserStatus !== newStatus) {
mainModuleInst.setCurrentUserStatus(newStatus) mainModuleInst.setCurrentUserStatus(newStatus)
} }
} }

View File

@ -39,11 +39,12 @@ import StatusQ.Layout 0.1
import StatusQ.Popups 0.1 import StatusQ.Popups 0.1
import StatusQ.Popups.Dialog 0.1 import StatusQ.Popups.Dialog 0.1
import AppLayouts.stores 1.0 as AppStores
import AppLayouts.Chat.stores 1.0 as ChatStores import AppLayouts.Chat.stores 1.0 as ChatStores
import AppLayouts.Communities.stores 1.0 import AppLayouts.Communities.stores 1.0
import AppLayouts.Wallet.stores 1.0 as WalletStores import AppLayouts.Profile.stores 1.0 as ProfileStores
import AppLayouts.Wallet.popups 1.0 as WalletPopups import AppLayouts.Wallet.popups 1.0 as WalletPopups
import AppLayouts.Wallet.stores 1.0 as WalletStores
import AppLayouts.stores 1.0 as AppStores
import mainui.activitycenter.stores 1.0 import mainui.activitycenter.stores 1.0
import mainui.activitycenter.popups 1.0 import mainui.activitycenter.popups 1.0
@ -59,7 +60,9 @@ Item {
currencyStore: appMain.currencyStore currencyStore: appMain.currencyStore
} }
property AppStores.RootStore rootStore: AppStores.RootStore {} readonly property AppStores.RootStore rootStore: AppStores.RootStore {}
readonly property ProfileStores.ProfileSectionStore profileSectionStore: rootStore.profileSectionStore
readonly property ProfileStores.ProfileStore profileStore: profileSectionStore.profileStore
property ChatStores.RootStore rootChatStore: ChatStores.RootStore { property ChatStores.RootStore rootChatStore: ChatStores.RootStore {
contactsStore: appMain.rootStore.contactStore contactsStore: appMain.rootStore.contactStore
@ -106,7 +109,7 @@ Item {
rootStore: appMain.rootStore rootStore: appMain.rootStore
rootChatStore: appMain.rootChatStore rootChatStore: appMain.rootChatStore
communityTokensStore: appMain.communityTokensStore communityTokensStore: appMain.communityTokensStore
profileStore: appMain.rootStore.profileSectionStore.profileStore profileStore: appMain.profileStore
sendModalPopup: sendModal sendModalPopup: sendModal
} }
@ -651,7 +654,7 @@ Item {
walletAssetsStore: appMain.walletAssetsStore walletAssetsStore: appMain.walletAssetsStore
sendModalPopup: sendModal sendModalPopup: sendModal
isWalletEnabled: appMain.rootStore.profileSectionStore.profileStore.isWalletEnabled isWalletEnabled: appMain.profileStore.isWalletEnabled
} }
} }
@ -823,16 +826,16 @@ Item {
objectName: "statusProfileNavBarTabButton" objectName: "statusProfileNavBarTabButton"
property bool opened: false property bool opened: false
name: appMain.rootStore.userProfileInst.name name: appMain.profileStore.name
icon.source: appMain.rootStore.userProfileInst.icon icon.source: appMain.profileStore.icon
implicitWidth: 32 implicitWidth: 32
implicitHeight: 32 implicitHeight: 32
identicon.asset.width: width identicon.asset.width: width
identicon.asset.height: height identicon.asset.height: height
identicon.asset.useAcronymForLetterIdenticon: true identicon.asset.useAcronymForLetterIdenticon: true
identicon.asset.color: Utils.colorForPubkey(appMain.rootStore.userProfileInst.pubKey) identicon.asset.color: Utils.colorForPubkey(appMain.profileStore.pubkey)
identicon.ringSettings.ringSpecModel: Utils.getColorHashAsJson(appMain.rootStore.userProfileInst.pubKey, identicon.ringSettings.ringSpecModel: Utils.getColorHashAsJson(appMain.profileStore.pubkey,
appMain.rootStore.userProfileInst.preferredName) appMain.profileStore.preferredName)
badge.visible: true badge.visible: true
badge.anchors { badge.anchors {
@ -849,7 +852,7 @@ Item {
badge.border.width: 2 badge.border.width: 2
badge.border.color: hovered ? Theme.palette.statusBadge.hoverBorderColor : Theme.palette.statusAppNavBar.backgroundColor badge.border.color: hovered ? Theme.palette.statusBadge.hoverBorderColor : Theme.palette.statusAppNavBar.backgroundColor
badge.color: { badge.color: {
switch(appMain.rootStore.userProfileInst.currentUserStatus){ switch(appMain.profileStore.currentUserStatus){
case Constants.currentUserStatus.automatic: case Constants.currentUserStatus.automatic:
case Constants.currentUserStatus.alwaysOnline: case Constants.currentUserStatus.alwaysOnline:
return Style.current.green; return Style.current.green;
@ -866,12 +869,12 @@ Item {
y: profileButton.y - userStatusContextMenu.height + profileButton.height y: profileButton.y - userStatusContextMenu.height + profileButton.height
x: profileButton.x + profileButton.width + 5 x: profileButton.x + profileButton.width + 5
pubKey: appMain.rootStore.userProfileInst.pubKey pubKey: appMain.profileStore.pubkey
name: appMain.rootStore.userProfileInst.name name: appMain.profileStore.name
icon: appMain.rootStore.userProfileInst.icon icon: appMain.profileStore.icon
isEnsVerified: !!appMain.rootStore.userProfileInst.preferredName isEnsVerified: !!appMain.profileStore.preferredName
currentUserStatus: appMain.rootStore.userProfileInst.currentUserStatus currentUserStatus: appMain.profileStore.currentUserStatus
onViewProfileRequested: Global.openProfilePopup(pubKey) onViewProfileRequested: Global.openProfilePopup(pubKey)
onCopyLinkRequested: ClipboardUtils.setText(appMain.rootStore.contactStore.getLinkToProfile(pubKey)) onCopyLinkRequested: ClipboardUtils.setText(appMain.rootStore.contactStore.getLinkToProfile(pubKey))

View File

@ -8,7 +8,6 @@ QtObject {
property var profileSectionModuleInst: profileSectionModule property var profileSectionModuleInst: profileSectionModule
property var privacyModule: profileSectionModuleInst.privacyModule property var privacyModule: profileSectionModuleInst.privacyModule
property var userProfileInst: !!Global.userProfile? Global.userProfile : null
property var appSettingsInst: Global.appIsReady && !!appSettings? appSettings : null property var appSettingsInst: Global.appIsReady && !!appSettings? appSettings : null
property var accountSensitiveSettings: Global.appIsReady && !!localAccountSensitiveSettings? localAccountSensitiveSettings : null property var accountSensitiveSettings: Global.appIsReady && !!localAccountSensitiveSettings? localAccountSensitiveSettings : null
property real volume: !!appSettingsInst ? appSettingsInst.volume * 0.01 : 0.5 property real volume: !!appSettingsInst ? appSettingsInst.volume * 0.01 : 0.5