Remove map from room_id to QPixmap from ChatPage
The avatars are loaded from cache
This commit is contained in:
parent
4f6ffb6e73
commit
0028fdfe6c
@ -166,6 +166,9 @@ public:
|
||||
bool isFormatValid();
|
||||
void setCurrentFormat();
|
||||
|
||||
//! Retrieves the saved room avatar.
|
||||
QImage getRoomAvatar(const QString &id);
|
||||
|
||||
//! Adds a user to the read list for the given event.
|
||||
//!
|
||||
//! There should be only one user id present in a receipt list per room.
|
||||
|
@ -168,9 +168,6 @@ private:
|
||||
QString current_room_;
|
||||
QString current_community_;
|
||||
|
||||
std::map<QString, QPixmap> roomAvatars_;
|
||||
std::map<QString, QPixmap> community_avatars_;
|
||||
|
||||
UserInfoWidget *user_info_widget_;
|
||||
|
||||
std::map<QString, QSharedPointer<Community>> communities_;
|
||||
|
37
src/Cache.cc
37
src/Cache.cc
@ -859,6 +859,43 @@ Cache::getInviteRoomTopic(lmdb::txn &txn, lmdb::dbi &db)
|
||||
return QString();
|
||||
}
|
||||
|
||||
QImage
|
||||
Cache::getRoomAvatar(const QString &room_id)
|
||||
{
|
||||
auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
|
||||
|
||||
lmdb::val response;
|
||||
|
||||
if (!lmdb::dbi_get(txn, roomsDb_, lmdb::val(room_id.toStdString()), response)) {
|
||||
txn.commit();
|
||||
return QImage();
|
||||
}
|
||||
|
||||
std::string media_url;
|
||||
|
||||
try {
|
||||
RoomInfo info = json::parse(std::string(response.data(), response.size()));
|
||||
media_url = std::move(info.avatar_url);
|
||||
|
||||
if (media_url.empty()) {
|
||||
txn.commit();
|
||||
return QImage();
|
||||
}
|
||||
} catch (const json::exception &e) {
|
||||
qWarning() << "failed to parse room info" << e.what()
|
||||
<< QString::fromStdString(std::string(response.data(), response.size()));
|
||||
}
|
||||
|
||||
if (!lmdb::dbi_get(txn, mediaDb_, lmdb::val(media_url), response)) {
|
||||
txn.commit();
|
||||
return QImage();
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
|
||||
return QImage::fromData(QByteArray(response.data(), response.size()));
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
Cache::joinedRooms()
|
||||
{
|
||||
|
@ -459,7 +459,6 @@ ChatPage::logout()
|
||||
void
|
||||
ChatPage::resetUI()
|
||||
{
|
||||
roomAvatars_.clear();
|
||||
room_list_->clear();
|
||||
top_bar_->reset();
|
||||
user_info_widget_->reset();
|
||||
@ -571,8 +570,6 @@ ChatPage::initialSyncCompleted(const mtx::responses::Sync &response)
|
||||
void
|
||||
ChatPage::updateTopBarAvatar(const QString &roomid, const QPixmap &img)
|
||||
{
|
||||
roomAvatars_.emplace(roomid, img);
|
||||
|
||||
if (current_room_ != roomid)
|
||||
return;
|
||||
|
||||
@ -646,15 +643,18 @@ ChatPage::changeTopRoomInfo(const QString &room_id)
|
||||
top_bar_->updateRoomName(name);
|
||||
top_bar_->updateRoomTopic(QString::fromStdString(room_info[room_id].topic));
|
||||
|
||||
if (roomAvatars_.find(room_id) != roomAvatars_.end())
|
||||
top_bar_->updateRoomAvatar(roomAvatars_[room_id].toImage());
|
||||
else
|
||||
top_bar_->updateRoomAvatarFromName(name);
|
||||
auto img = cache_->getRoomAvatar(room_id);
|
||||
|
||||
if (img.isNull())
|
||||
top_bar_->updateRoomAvatarFromName(name);
|
||||
else
|
||||
top_bar_->updateRoomAvatar(img);
|
||||
|
||||
current_room_ = room_id;
|
||||
} catch (const lmdb::error &e) {
|
||||
qWarning() << "failed to change top bar room info" << e.what();
|
||||
}
|
||||
|
||||
current_room_ = room_id;
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user