diff --git a/src/app/avatarregistry.cpp b/src/app/avatarregistry.cpp index 24d9f7d60eb4955d972ca31bb157f19436103808..19b8074db3980792b2a999a6b1d3a26e0d7dd419 100644 --- a/src/app/avatarregistry.cpp +++ b/src/app/avatarregistry.cpp @@ -56,11 +56,15 @@ AvatarRegistry::addOrUpdateImage(const QString& id) } return uid; } - +// HACK: There is still a timing issue with when this function is called. +// The reason that avatar duplication was happening is that when the LRC account id is changed via +// the account combobox, the ui updates itself and calls getUID for the avatars that it needs to +// load, although by this point, the cache has not yet been cleared here. This ends up executing +// after the getUID calls. void AvatarRegistry::connectAccount() { - uidMap_.clear(); + clearCache(); connect(lrcInstance_->getCurrentContactModel(), &ContactModel::profileUpdated, this, @@ -93,3 +97,9 @@ AvatarRegistry::getUid(const QString& id) } return it.value(); } + +void +AvatarRegistry::clearCache() +{ + uidMap_.clear(); +} diff --git a/src/app/avatarregistry.h b/src/app/avatarregistry.h index 6076896a6d1c671d824ea2e0fa4337a6b45f7bdc..1b46400963eb36c3a3425c1d68789929bd553389 100644 --- a/src/app/avatarregistry.h +++ b/src/app/avatarregistry.h @@ -45,6 +45,8 @@ public: // add or update a specific image in the cache Q_SLOT QString addOrUpdateImage(const QString& id); + Q_INVOKABLE void clearCache(); + Q_SIGNALS: void avatarUidChanged(const QString& id); diff --git a/src/app/mainview/components/AccountComboBoxPopup.qml b/src/app/mainview/components/AccountComboBoxPopup.qml index 35118d23310582c8df9bf93f06fe4c8a5b3fe229..a63c0ec6f76ea9f359d7148fa63ff308156e6e8a 100644 --- a/src/app/mainview/components/AccountComboBoxPopup.qml +++ b/src/app/mainview/components/AccountComboBoxPopup.qml @@ -24,6 +24,7 @@ import net.jami.Models 1.1 import net.jami.Adapters 1.1 import net.jami.Constants 1.1 import net.jami.Enums 1.1 +import net.jami.Helpers 1.1 import "../../commoncomponents" Popup { @@ -35,7 +36,7 @@ Popup { // limit the number of accounts shown at once implicitHeight: { - return visible ? Math.min(JamiTheme.accountListItemHeight * Math.min(6, listView.model.count + 1) + 96, appWindow.height - parent.height) : 0; + return visible ? Math.min(JamiTheme.accountListItemHeight * Math.min(6, listView.model.count + 1) + 91, appWindow.height - parent.height) : 0; } padding: 0 modal: true @@ -224,8 +225,12 @@ Popup { delegate: AccountItemDelegate { height: JamiTheme.accountListItemHeight width: root.width + onClicked: { root.close(); + // This is a workaround for the synchronicity issue + // in AvatarRegistry::connectAccount() + AvatarRegistry.clearCache(); LRCInstance.currentAccountId = ID; } }