Display cached user avatars in member lists and chat messages
This commit is contained in:
1 parent
78bed5efe4
commit
694ed8e263
3 files changed
+48
-2
No files matched your search
@@ -54,6 +54,7 @@ void chat_core_save_ui_state_trampoline(void* arg);
|
||||
#include "radio_audio_engine.h"
|
||||
#include "radiopanel.h"
|
||||
#include "flagpainter.h"
|
||||
#include "avatars/avatarmanager.h"
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
@@ -336,6 +337,22 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
|
||||
, m_recorder(recorder)
|
||||
{
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
if (auto* manager = AvatarManager::instance()) connect(manager, &AvatarManager::changed, this,
|
||||
[this, manager](const QString& channel, quint64 owner) {
|
||||
if (channel != m_currentChannelId) return;
|
||||
const QImage image = manager->image(channel, owner);
|
||||
for (int row = 0; row < m_model->rowCount(); row++) {
|
||||
auto* item = m_model->item(row);
|
||||
if (item->data(MsgAuthorNodeIdRole).toULongLong() != owner) continue;
|
||||
QPixmap avatar;
|
||||
if (!image.isNull()) avatar = QPixmap::fromImage(image);
|
||||
else {
|
||||
const AccountRow account = m_db->getAccount(owner);
|
||||
avatar = makeAvatar(QColor(account.avatarColor), account.avatarLetter.isEmpty() ? authorName(owner).left(1) : account.avatarLetter);
|
||||
}
|
||||
item->setData(avatar, MsgAvatarRole);
|
||||
}
|
||||
});
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
@@ -701,6 +718,10 @@ void MessageList::loadChannel(const QString& channelId) {
|
||||
}
|
||||
|
||||
auto avatar = makeAvatar(color, letter);
|
||||
if (auto* manager = AvatarManager::instance()) {
|
||||
const QImage image = manager->image(m_currentChannelId, m.authorNodeId);
|
||||
if (!image.isNull()) avatar = QPixmap::fromImage(image);
|
||||
}
|
||||
auto time = QDateTime::fromMSecsSinceEpoch(m.timestamp).toString("HH:mm");
|
||||
|
||||
QVariantList reacts;
|
||||
@@ -775,6 +796,10 @@ void MessageList::refresh() {
|
||||
if (!m_avatarCache.contains(m.authorNodeId))
|
||||
m_avatarCache[m.authorNodeId] = color;
|
||||
auto avatar = makeAvatar(color, letter);
|
||||
if (auto* manager = AvatarManager::instance()) {
|
||||
const QImage image = manager->image(m_currentChannelId, m.authorNodeId);
|
||||
if (!image.isNull()) avatar = QPixmap::fromImage(image);
|
||||
}
|
||||
auto time = QDateTime::fromMSecsSinceEpoch(m.timestamp).toString("HH:mm");
|
||||
auto *item = new QStandardItem();
|
||||
setMsg(item, author, QString::fromUtf8(m.data), time, avatar, false,
|
||||
|
||||
Reference in new issue
Block a user