Optimized avatar loading in RsFriendListModel

This commit is contained in:
thunder2 2024-07-01 16:20:11 +02:00
parent 19d613edcc
commit c8975bb2e9
2 changed files with 23 additions and 20 deletions

View File

@ -54,7 +54,9 @@ bool AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, cons
/* get avatar */
rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
if (size == 0) {
avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage);
if (!defaultImage.isEmpty()) {
avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage);
}
return false;
}

View File

@ -931,24 +931,26 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons
{
if(!isProfileExpanded(entry))
{
QPixmap sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE);
QPixmap sslOverlayIcon;
sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(onlineRole(entry,col).toInt()));
QPixmap sslAvatar;
const HierarchicalProfileInformation *hn = getProfileInfo(entry);
for(uint32_t i=0;i<hn->child_node_indices.size();++i)
if(AvatarDefs::getAvatarFromSslId(RsPeerId(mLocations[hn->child_node_indices[i]].node_info.id.toStdString()), sslAvatar))
if (mDisplayStatusIcon)
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon)));
else
return QVariant(QIcon(sslAvatar));
for(uint32_t i=0;i<hn->child_node_indices.size();++i) {
if(AvatarDefs::getAvatarFromSslId(RsPeerId(mLocations[hn->child_node_indices[i]].node_info.id.toStdString()), sslAvatar, "")) {
break;
}
}
if (mDisplayStatusIcon)
if (sslAvatar.isNull()) {
sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE);
}
if (mDisplayStatusIcon) {
QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(onlineRole(entry, col).toInt()));
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon)));
else
return QVariant(QIcon(sslAvatar));
}
return QVariant(QIcon(sslAvatar));
}
return QVariant();
@ -962,14 +964,13 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons
return QVariant();
QPixmap sslAvatar;
QPixmap sslOverlayIcon;
sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(statusRole(entry,col).toInt()));
AvatarDefs::getAvatarFromSslId(RsPeerId(hn->node_info.id.toStdString()), sslAvatar);
if (mDisplayStatusIcon)
if (mDisplayStatusIcon) {
QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(statusRole(entry, col).toInt()));
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon)));
else
return QVariant(QIcon(sslAvatar));
}
return QVariant(QIcon(sslAvatar));
}
default: return QVariant();
}