Jonathan Rainville 50132c5a0e
Refactor contacts models to have a single model, remove useless properties and improve updating (#16667)
* refactor(contacts): refactor 5 contact models into one and filter in QML

Fixes #16549

Refactors the 5 types of contact models (all, mutuals, banned, received and sent) into only the `allContacts` and use an Adaptor on the QML side to filter into the needed models.
This cleans the Nim side a lot and makes applying updates to the contacts' model way simpler.

* chore(contacts): remove useless and duplicated contact properties

OptionalName and isSyncing were never used.
DefaultDisplayName was not really used and is actually a duplication of preferredDisplayName, so I replaced the limited usages of DefaultDisplayName by preferredDisplayName

* refactor(contacts): improve updates by not removing and re-adding

We used to update contact items by removing them from the models and re-adding them. This is highly inefficient.
Instead, the proper way is to update only the values that changed.

* user_model: onItemChanged signal removed

* user_model: sorting by online status no longer needed on nim side

* Chat/RootStore: contactsModel property removed

* ContactsStore encapsulation improved

* ContactsStore: contacts model adaptor moved outside store

---------

Co-authored-by: Michał Cieślak <michalcieslak@status.im>
2024-11-28 09:15:34 -05:00

116 lines
4.9 KiB
QML

import QtQuick 2.15
import QtQml 2.15
import utils 1.0
QtObject {
id: root
property var profileModule
property string pubkey: userProfile.pubKey
property string compressedPubKey: userProfile.compressedPubKey
property string name: userProfile.name
property string username: userProfile.username
property string displayName: userProfile.displayName
property string preferredName: userProfile.preferredName
property string profileLargeImage: userProfile.largeImage
property string icon: userProfile.icon
property bool userDeclinedBackupBanner: Global.appIsReady? localAccountSensitiveSettings.userDeclinedBackupBanner : false
property var privacyStore: profileSectionModule.privacyModule
readonly property string keyUid: userProfile.keyUid
readonly property bool isKeycardUser: userProfile.isKeycardUser
readonly property int currentUserStatus: userProfile.currentUserStatus
readonly property var thumbnailImage: userProfile.thumbnailImage
readonly property var largeImage: userProfile.largeImage
readonly property int colorId: Utils.colorIdForPubkey(root.pubkey)
readonly property var colorHash: Utils.getColorHashAsJson(root.pubkey)
readonly property string bio: profileModule.bio
readonly property string socialLinksJson: profileModule.socialLinksJson
readonly property var socialLinksModel: profileModule.socialLinksModel
readonly property var temporarySocialLinksModel: profileModule.temporarySocialLinksModel // for editing purposes
readonly property var temporarySocialLinksJson: profileModule.temporarySocialLinksJson
readonly property bool socialLinksDirty: profileModule.socialLinksDirty
readonly property bool isWalletEnabled: Global.appIsReady? mainModule.sectionsModel.getItemEnabledBySectionType(Constants.appSection.wallet) : true
readonly property var showcasePreferencesCommunitiesModel: profileModule.showcasePreferencesCommunitiesModel
readonly property var showcasePreferencesAccountsModel: profileModule.showcasePreferencesAccountsModel
readonly property var showcasePreferencesCollectiblesModel: profileModule.showcasePreferencesCollectiblesModel
readonly property var showcasePreferencesAssetsModel: profileModule.showcasePreferencesAssetsModel
readonly property var showcasePreferencesSocialLinksModel: profileModule.showcasePreferencesSocialLinksModel
readonly property bool isFirstShowcaseInteraction: localAccountSettings.isFirstShowcaseInteraction
// The following signals wrap the settings / preferences save request responses in one unique result (identity + preferences result)
signal profileSettingsSaveSucceeded()
signal profileSettingsSaveFailed()
// The following signals describe separate save request responses between identity and preferences
signal profileIdentitySaveSucceeded()
signal profileIdentitySaveFailed()
signal profileShowcasePreferencesSaveSucceeded()
signal profileShowcasePreferencesSaveFailed()
readonly property Connections profileModuleConnections: Connections {
target: root.profileModule
function onProfileIdentitySaveSucceeded() {
root.profileIdentitySaveSucceeded()
}
function onProfileIdentitySaveFailed() {
root.profileIdentitySaveFailed()
}
function onProfileShowcasePreferencesSaveSucceeded() {
root.profileShowcasePreferencesSaveSucceeded()
}
function onProfileShowcasePreferencesSaveFailed() {
root.profileShowcasePreferencesSaveFailed()
}
}
function getQrCodeSource(text) {
return globalUtils.qrCode(text)
}
function saveProfileIdentityChanges(displayName, bio, imageInfo) {
const changes = Object.assign({},
displayName !== undefined && { displayName },
bio !== undefined && { bio },
imageInfo !== undefined && { image: imageInfo })
const json = JSON.stringify(changes)
root.profileModule.saveProfileIdentityChanges(json)
}
function getProfileShowcaseEntriesLimit() {
return root.profileModule.getProfileShowcaseEntriesLimit()
}
function getProfileShowcaseSocialLinksLimit() {
return root.profileModule.getProfileShowcaseSocialLinksLimit()
}
function saveProfileShowcasePreferences(json) {
root.profileModule.saveProfileShowcasePreferences(json)
}
function requestProfileShowcasePreferences() {
root.profileModule.requestProfileShowcasePreferences()
}
function setIsFirstShowcaseInteraction() {
root.profileModule.setIsFirstShowcaseInteraction()
}
onUserDeclinedBackupBannerChanged: {
if (userDeclinedBackupBanner !== localAccountSensitiveSettings.userDeclinedBackupBanner) {
localAccountSensitiveSettings.userDeclinedBackupBanner = userDeclinedBackupBanner
}
}
}