Merge pull request #215 from thunder2/pr/2862

Pr/2862
This commit is contained in:
defnax 2024-07-03 15:38:35 +02:00 committed by GitHub
commit b90e75e912
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 17 deletions

View File

@ -898,20 +898,24 @@ bool RsFriendListModel::getPeerOnlineStatus(const EntryIndex& e) const
return (noded && (noded->node_info.state & RS_PEER_STATE_CONNECTED)); return (noded && (noded->node_info.state & RS_PEER_STATE_CONNECTED));
} }
bool RsFriendListModel::getProfileStatus(const HierarchicalProfileInformation *profileInfo, uint32_t &status) const const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getBestNodeInformation(const HierarchicalProfileInformation *profileInfo, uint32_t *status) const
{ {
status = RS_STATUS_OFFLINE; if (status) {
*status = RS_STATUS_OFFLINE;
if (!profileInfo) {
return false;
} }
if (!profileInfo) {
return NULL;
}
const RsFriendListModel::HierarchicalNodeInformation *bestNodeInformation = NULL;
int bestStatusIndex = 0; int bestStatusIndex = 0;
/* Find the best status */ /* Find the best status */
for (uint32_t i = 0; i < profileInfo->child_node_indices.size(); ++i) { for (uint32_t i = 0; i < profileInfo->child_node_indices.size(); ++i) {
const RsFriendListModel::HierarchicalNodeInformation &nodeInformation = mLocations[profileInfo->child_node_indices[i]];
StatusInfo statusInfo; StatusInfo statusInfo;
rsStatus->getStatus(mLocations[profileInfo->child_node_indices[i]].node_info.id, statusInfo); rsStatus->getStatus(nodeInformation.node_info.id, statusInfo);
int statusIndex = 0; int statusIndex = 0;
switch (statusInfo.status) { switch (statusInfo.status) {
@ -942,15 +946,19 @@ bool RsFriendListModel::getProfileStatus(const HierarchicalProfileInformation *p
if (bestStatusIndex == 0 || statusIndex > bestStatusIndex) { if (bestStatusIndex == 0 || statusIndex > bestStatusIndex) {
/* first status or better status */ /* first status or better status */
bestStatusIndex = statusIndex; bestStatusIndex = statusIndex;
status = statusInfo.status; bestNodeInformation = &nodeInformation;
if (status) {
*status = statusInfo.status;
}
} }
} }
if (bestStatusIndex == 0) { if (bestStatusIndex == 0) {
return false; return NULL;
} }
return true; return bestNodeInformation;
} }
QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) const QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) const
@ -987,22 +995,37 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons
if(!isProfileExpanded(entry)) if(!isProfileExpanded(entry))
{ {
QPixmap sslAvatar; QPixmap sslAvatar;
bool foundAvatar = false;
const HierarchicalProfileInformation *hn = getProfileInfo(entry); const HierarchicalProfileInformation *hn = getProfileInfo(entry);
uint32_t status = RS_STATUS_OFFLINE;
const HierarchicalNodeInformation *bestNodeInformation = NULL;
for(uint32_t i=0;i<hn->child_node_indices.size();++i) { if (mDisplayStatusIcon) {
if(AvatarDefs::getAvatarFromSslId(RsPeerId(mLocations[hn->child_node_indices[i]].node_info.id.toStdString()), sslAvatar, "")) { bestNodeInformation = getBestNodeInformation(hn, &status);
break; if (bestNodeInformation) {
if (AvatarDefs::getAvatarFromSslId(RsPeerId(bestNodeInformation->node_info.id.toStdString()), sslAvatar, "")) {
/* Use avatar from best node */
foundAvatar = true;
}
} }
} }
if (sslAvatar.isNull()) { if (!foundAvatar) {
/* Use first available avatar */
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, "")) {
foundAvatar = true;
break;
}
}
}
if (!foundAvatar || sslAvatar.isNull()) {
sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE); sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE);
} }
if (mDisplayStatusIcon) { if (mDisplayStatusIcon) {
uint32_t status; if (bestNodeInformation) {
if (getProfileStatus(hn, status)) {
QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(status)); QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(status));
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon)));
} }

View File

@ -223,7 +223,7 @@ private:
uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings); uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings);
bool getProfileStatus(const HierarchicalProfileInformation *profileInfo, uint32_t &status) const; const HierarchicalNodeInformation *getBestNodeInformation(const HierarchicalProfileInformation *profileInfo, uint32_t *status = NULL) const;
QStringList mFilterStrings; QStringList mFilterStrings;
FilterType mFilterType; FilterType mFilterType;

View File

@ -54,6 +54,7 @@
#include "gui/chat/ChatUserNotify.h" #include "gui/chat/ChatUserNotify.h"
#include "gui/connect/ConnectProgressDialog.h" #include "gui/connect/ConnectProgressDialog.h"
#include "gui/common/ElidedLabel.h" #include "gui/common/ElidedLabel.h"
#include "gui/notifyqt.h"
#include "NewFriendList.h" #include "NewFriendList.h"
#include "ui_NewFriendList.h" #include "ui_NewFriendList.h"
@ -202,6 +203,9 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::PEER_CONNECTION ); rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::PEER_CONNECTION );
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_gssp, RsEventType::GOSSIP_DISCOVERY ); rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_gssp, RsEventType::GOSSIP_DISCOVERY );
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(QString)), this, SLOT(forceUpdateDisplay()));
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(forceUpdateDisplay()));
mModel = new RsFriendListModel(ui->peerTreeWidget); mModel = new RsFriendListModel(ui->peerTreeWidget);
mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this); mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this);