Fix avatar loading in multiple places and prefers name instead of
display name for avatar fallback. This also fixes a bug where users didn't get their avatar loaded in the room list. Fix #209
This commit is contained in:
@@ -303,6 +303,7 @@ inline QVariantMap userAtEvent(NeoChatUser *user, NeoChatRoom *room, const RoomE
|
||||
{"avatarMediaId", user->avatarMediaId(room)},
|
||||
{"avatarUrl", user->avatarUrl(room)},
|
||||
{"displayName", user->displayname(room)},
|
||||
{"display", user->name()},
|
||||
{"color", user->color()},
|
||||
{"object", QVariant::fromValue(user)},
|
||||
};
|
||||
|
||||
@@ -288,7 +288,7 @@ QString NeoChatRoom::avatarMediaId() const
|
||||
const auto dcUsers = directChatUsers();
|
||||
for (const auto u : dcUsers) {
|
||||
if (u != localUser()) {
|
||||
return u->avatarMediaId();
|
||||
return u->avatarMediaId(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -256,6 +256,9 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
NeoChatRoom *room = m_rooms.at(index.row());
|
||||
if (role == NameRole) {
|
||||
return !room->name().isEmpty() ? room->name() : room->displayName();
|
||||
}
|
||||
if (role == DisplayNameRole) {
|
||||
return room->displayName();
|
||||
}
|
||||
if (role == AvatarRole) {
|
||||
@@ -324,6 +327,7 @@ QHash<int, QByteArray> RoomListModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "name";
|
||||
roles[DisplayNameRole] = "displayName";
|
||||
roles[AvatarRole] = "avatar";
|
||||
roles[TopicRole] = "topic";
|
||||
roles[CategoryRole] = "category";
|
||||
|
||||
@@ -39,6 +39,7 @@ class RoomListModel : public QAbstractListModel
|
||||
public:
|
||||
enum EventRoles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
DisplayNameRole,
|
||||
AvatarRole,
|
||||
TopicRole,
|
||||
CategoryRole,
|
||||
|
||||
Reference in New Issue
Block a user