avatars: fix duplication glitch when switching accounts

There was a timing issue between when a new account is connected
and the moment where the avatar cache is cleared. Thus, the ui
would use the cache of the previous account for certain
conversations.

GitLab: #1832
GitLab: #1559
Change-Id: I0319b3d81e0b6dfec9b5408806dfd48ff220ea9d
This commit is contained in:
Andreas Hatziiliou
2024-11-15 17:04:45 -05:00
parent 6ddd6a7f9e
commit 950e32e9a6
3 changed files with 20 additions and 3 deletions

View File

@ -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();
}

View File

@ -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);

View File

@ -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;
}
}