Don't use shared pointers for cache
This commit is contained in:
parent
4c4ea557b3
commit
ebed87ea57
@ -17,27 +17,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QHash>
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
class TimelineItem;
|
|
||||||
class Cache;
|
|
||||||
|
|
||||||
class AvatarProvider : public QObject
|
class AvatarProvider : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void init(QSharedPointer<Cache> cache) { cache_ = cache; }
|
|
||||||
//! The callback is called with the downloaded avatar for the given user
|
//! The callback is called with the downloaded avatar for the given user
|
||||||
//! or the avatar is downloaded first and then saved for re-use.
|
//! or the avatar is downloaded first and then saved for re-use.
|
||||||
static void resolve(const QString &room_id,
|
static void resolve(const QString &room_id,
|
||||||
const QString &userId,
|
const QString &userId,
|
||||||
QObject *receiver,
|
QObject *receiver,
|
||||||
std::function<void(QImage)> callback);
|
std::function<void(QImage)> callback);
|
||||||
|
|
||||||
private:
|
|
||||||
static QSharedPointer<Cache> cache_;
|
|
||||||
};
|
};
|
||||||
|
@ -435,3 +435,11 @@ private:
|
|||||||
QString localUserId_;
|
QString localUserId_;
|
||||||
QString cacheDirectory_;
|
QString cacheDirectory_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace cache {
|
||||||
|
void
|
||||||
|
init(const QString &userId, QObject *parent);
|
||||||
|
|
||||||
|
Cache *
|
||||||
|
client();
|
||||||
|
}
|
||||||
|
@ -69,7 +69,6 @@ public:
|
|||||||
static ChatPage *instance() { return instance_; }
|
static ChatPage *instance() { return instance_; }
|
||||||
|
|
||||||
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
|
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
|
||||||
QSharedPointer<Cache> cache() { return cache_; }
|
|
||||||
void deleteConfigs();
|
void deleteConfigs();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -183,9 +182,6 @@ private:
|
|||||||
|
|
||||||
// Global user settings.
|
// Global user settings.
|
||||||
QSharedPointer<UserSettings> userSettings_;
|
QSharedPointer<UserSettings> userSettings_;
|
||||||
|
|
||||||
// LMDB wrapper.
|
|
||||||
QSharedPointer<Cache> cache_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Collection>
|
template<class Collection>
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "Cache.h"
|
|
||||||
#include "SuggestionsPopup.hpp"
|
#include "SuggestionsPopup.hpp"
|
||||||
#include "TextField.h"
|
#include "TextField.h"
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ class QuickSwitcher : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QuickSwitcher(QSharedPointer<Cache> cache, QWidget *parent = nullptr);
|
QuickSwitcher(QWidget *parent = nullptr);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void closing();
|
void closing();
|
||||||
@ -77,6 +76,4 @@ private:
|
|||||||
|
|
||||||
//! Autocomplete popup box with the room suggestions.
|
//! Autocomplete popup box with the room suggestions.
|
||||||
SuggestionsPopup popup_;
|
SuggestionsPopup popup_;
|
||||||
//! Cache client for room quering.
|
|
||||||
QSharedPointer<Cache> cache_;
|
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,6 @@ class OverlayModal;
|
|||||||
class RoomInfoListItem;
|
class RoomInfoListItem;
|
||||||
class Sync;
|
class Sync;
|
||||||
class UserSettings;
|
class UserSettings;
|
||||||
class Cache;
|
|
||||||
struct DescInfo;
|
struct DescInfo;
|
||||||
struct RoomInfo;
|
struct RoomInfo;
|
||||||
|
|
||||||
@ -41,7 +40,6 @@ class RoomList : public QWidget
|
|||||||
public:
|
public:
|
||||||
RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent = 0);
|
RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent = 0);
|
||||||
|
|
||||||
void setCache(QSharedPointer<Cache> cache) { cache_ = cache; }
|
|
||||||
void initialize(const QMap<QString, RoomInfo> &info);
|
void initialize(const QMap<QString, RoomInfo> &info);
|
||||||
void sync(const std::map<QString, RoomInfo> &info);
|
void sync(const std::map<QString, RoomInfo> &info);
|
||||||
|
|
||||||
@ -102,7 +100,6 @@ private:
|
|||||||
//! Which rooms to include in the room list.
|
//! Which rooms to include in the room list.
|
||||||
std::vector<QString> roomFilter_;
|
std::vector<QString> roomFilter_;
|
||||||
|
|
||||||
QSharedPointer<Cache> cache_;
|
|
||||||
QSharedPointer<UserSettings> userSettings_;
|
QSharedPointer<UserSettings> userSettings_;
|
||||||
|
|
||||||
bool isSortPending_ = false;
|
bool isSortPending_ = false;
|
||||||
|
@ -36,8 +36,6 @@
|
|||||||
|
|
||||||
#include "emoji/PickButton.h"
|
#include "emoji/PickButton.h"
|
||||||
|
|
||||||
class Cache;
|
|
||||||
|
|
||||||
namespace dialogs {
|
namespace dialogs {
|
||||||
class PreviewUploadOverlay;
|
class PreviewUploadOverlay;
|
||||||
}
|
}
|
||||||
@ -131,7 +129,6 @@ public:
|
|||||||
|
|
||||||
QColor borderColor() const { return borderColor_; }
|
QColor borderColor() const { return borderColor_; }
|
||||||
void setBorderColor(QColor &color) { borderColor_ = color; }
|
void setBorderColor(QColor &color) { borderColor_ = color; }
|
||||||
void setCache(QSharedPointer<Cache> cache) { cache_ = cache; }
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void openFileSelection();
|
void openFileSelection();
|
||||||
@ -172,7 +169,5 @@ private:
|
|||||||
FlatButton *sendMessageBtn_;
|
FlatButton *sendMessageBtn_;
|
||||||
emoji::PickButton *emojiBtn_;
|
emoji::PickButton *emojiBtn_;
|
||||||
|
|
||||||
QSharedPointer<Cache> cache_;
|
|
||||||
|
|
||||||
QColor borderColor_;
|
QColor borderColor_;
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
|
||||||
class Avatar;
|
class Avatar;
|
||||||
class Cache;
|
|
||||||
class FlatButton;
|
class FlatButton;
|
||||||
class QHBoxLayout;
|
class QHBoxLayout;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
@ -38,7 +37,7 @@ class MemberList : public QFrame
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MemberList(const QString &room_id, QSharedPointer<Cache> cache, QWidget *parent = nullptr);
|
MemberList(const QString &room_id, QWidget *parent = nullptr);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addUsers(const std::vector<RoomMember> &users);
|
void addUsers(const std::vector<RoomMember> &users);
|
||||||
@ -57,7 +56,6 @@ private:
|
|||||||
QString room_id_;
|
QString room_id_;
|
||||||
QLabel *topLabel_;
|
QLabel *topLabel_;
|
||||||
QListWidget *list_;
|
QListWidget *list_;
|
||||||
QSharedPointer<Cache> cache_;
|
|
||||||
FlatButton *moreBtn_;
|
FlatButton *moreBtn_;
|
||||||
};
|
};
|
||||||
} // dialogs
|
} // dialogs
|
||||||
|
@ -59,9 +59,7 @@ class RoomSettings : public QFrame
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
RoomSettings(const QString &room_id,
|
RoomSettings(const QString &room_id, QWidget *parent = nullptr);
|
||||||
QSharedPointer<Cache> cache,
|
|
||||||
QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void closing();
|
void closing();
|
||||||
@ -74,8 +72,6 @@ private:
|
|||||||
|
|
||||||
void setAvatar(const QImage &img) { avatarImg_ = img; }
|
void setAvatar(const QImage &img) { avatarImg_ = img; }
|
||||||
|
|
||||||
QSharedPointer<Cache> cache_;
|
|
||||||
|
|
||||||
// Button section
|
// Button section
|
||||||
FlatButton *saveBtn_;
|
FlatButton *saveBtn_;
|
||||||
FlatButton *cancelBtn_;
|
FlatButton *cancelBtn_;
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
|
||||||
QSharedPointer<Cache> AvatarProvider::cache_;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AvatarProvider::resolve(const QString &room_id,
|
AvatarProvider::resolve(const QString &room_id,
|
||||||
const QString &user_id,
|
const QString &user_id,
|
||||||
@ -33,13 +31,13 @@ AvatarProvider::resolve(const QString &room_id,
|
|||||||
const auto key = QString("%1 %2").arg(room_id).arg(user_id);
|
const auto key = QString("%1 %2").arg(room_id).arg(user_id);
|
||||||
const auto avatarUrl = Cache::avatarUrl(room_id, user_id);
|
const auto avatarUrl = Cache::avatarUrl(room_id, user_id);
|
||||||
|
|
||||||
if (!Cache::AvatarUrls.contains(key) || cache_.isNull())
|
if (!Cache::AvatarUrls.contains(key) || !cache::client())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (avatarUrl.isEmpty())
|
if (avatarUrl.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto data = cache_->image(avatarUrl);
|
auto data = cache::client()->image(avatarUrl);
|
||||||
if (!data.isNull()) {
|
if (!data.isNull()) {
|
||||||
callback(QImage::fromData(data));
|
callback(QImage::fromData(data));
|
||||||
return;
|
return;
|
||||||
@ -61,7 +59,7 @@ AvatarProvider::resolve(const QString &room_id,
|
|||||||
buffer.open(QIODevice::WriteOnly);
|
buffer.open(QIODevice::WriteOnly);
|
||||||
img.save(&buffer, "PNG");
|
img.save(&buffer, "PNG");
|
||||||
|
|
||||||
cache_->saveImage(avatarUrl, data);
|
cache::client()->saveImage(avatarUrl, data);
|
||||||
});
|
});
|
||||||
callback(img);
|
callback(img);
|
||||||
});
|
});
|
||||||
|
19
src/Cache.cc
19
src/Cache.cc
@ -53,6 +53,25 @@ static constexpr const char *NOTIFICATIONS_DB = "sent_notifications";
|
|||||||
using CachedReceipts = std::multimap<uint64_t, std::string, std::greater<uint64_t>>;
|
using CachedReceipts = std::multimap<uint64_t, std::string, std::greater<uint64_t>>;
|
||||||
using Receipts = std::map<std::string, std::map<std::string, uint64_t>>;
|
using Receipts = std::map<std::string, std::map<std::string, uint64_t>>;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
Cache *instance_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace cache {
|
||||||
|
void
|
||||||
|
init(const QString &user_id, QObject *parent)
|
||||||
|
{
|
||||||
|
if (!instance_)
|
||||||
|
instance_ = new Cache(user_id, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache *
|
||||||
|
client()
|
||||||
|
{
|
||||||
|
return instance_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Cache::Cache(const QString &userId, QObject *parent)
|
Cache::Cache(const QString &userId, QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
, env_{nullptr}
|
, env_{nullptr}
|
||||||
|
@ -323,7 +323,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
|||||||
|
|
||||||
// We remove any invites with the same room_id.
|
// We remove any invites with the same room_id.
|
||||||
try {
|
try {
|
||||||
cache_->removeInvite(room_id.toStdString());
|
cache::client()->removeInvite(room_id.toStdString());
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
emit showNotification(QString("Failed to remove invite: %1")
|
emit showNotification(QString("Failed to remove invite: %1")
|
||||||
.arg(QString::fromStdString(e.what())));
|
.arg(QString::fromStdString(e.what())));
|
||||||
@ -416,7 +416,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
|||||||
[this](const std::vector<std::string> &rooms) { view_manager_->initialize(rooms); });
|
[this](const std::vector<std::string> &rooms) { view_manager_->initialize(rooms); });
|
||||||
connect(this, &ChatPage::syncUI, this, [this](const mtx::responses::Rooms &rooms) {
|
connect(this, &ChatPage::syncUI, this, [this](const mtx::responses::Rooms &rooms) {
|
||||||
try {
|
try {
|
||||||
room_list_->cleanupInvites(cache_->invites());
|
room_list_->cleanupInvites(cache::client()->invites());
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
qWarning() << "failed to retrieve invites" << e.what();
|
qWarning() << "failed to retrieve invites" << e.what();
|
||||||
}
|
}
|
||||||
@ -484,7 +484,7 @@ ChatPage::deleteConfigs()
|
|||||||
settings.remove("");
|
settings.remove("");
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
cache_->deleteData();
|
cache::client()->deleteData();
|
||||||
|
|
||||||
http::client()->reset();
|
http::client()->reset();
|
||||||
}
|
}
|
||||||
@ -497,28 +497,24 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
|
|||||||
http::client()->getOwnProfile();
|
http::client()->getOwnProfile();
|
||||||
http::client()->getOwnCommunities();
|
http::client()->getOwnCommunities();
|
||||||
|
|
||||||
cache_ = QSharedPointer<Cache>(new Cache(userid));
|
cache::init(userid, this);
|
||||||
room_list_->setCache(cache_);
|
|
||||||
text_input_->setCache(cache_);
|
|
||||||
|
|
||||||
AvatarProvider::init(cache_);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cache_->setup();
|
cache::client()->setup();
|
||||||
|
|
||||||
if (!cache_->isFormatValid()) {
|
if (!cache::client()->isFormatValid()) {
|
||||||
cache_->deleteData();
|
cache::client()->deleteData();
|
||||||
cache_->setup();
|
cache::client()->setup();
|
||||||
cache_->setCurrentFormat();
|
cache::client()->setCurrentFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache_->isInitialized()) {
|
if (cache::client()->isInitialized()) {
|
||||||
loadStateFromCache();
|
loadStateFromCache();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
qCritical() << "Cache failure" << e.what();
|
qCritical() << "Cache failure" << e.what();
|
||||||
cache_->deleteData();
|
cache::client()->deleteData();
|
||||||
qInfo() << "Falling back to initial sync ...";
|
qInfo() << "Falling back to initial sync ...";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,16 +530,16 @@ ChatPage::syncCompleted(const mtx::responses::Sync &response)
|
|||||||
|
|
||||||
QtConcurrent::run([this, res = std::move(response)]() {
|
QtConcurrent::run([this, res = std::move(response)]() {
|
||||||
try {
|
try {
|
||||||
cache_->saveState(res);
|
cache::client()->saveState(res);
|
||||||
emit syncUI(res.rooms);
|
emit syncUI(res.rooms);
|
||||||
emit syncRoomlist(cache_->roomUpdates(res));
|
emit syncRoomlist(cache::client()->roomUpdates(res));
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
std::cout << "save cache error:" << e.what() << '\n';
|
std::cout << "save cache error:" << e.what() << '\n';
|
||||||
// TODO: retry sync.
|
// TODO: retry sync.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit continueSync(cache_->nextBatchToken());
|
emit continueSync(cache::client()->nextBatchToken());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,16 +552,16 @@ ChatPage::initialSyncCompleted(const mtx::responses::Sync &response)
|
|||||||
|
|
||||||
QtConcurrent::run([this, res = std::move(response)]() {
|
QtConcurrent::run([this, res = std::move(response)]() {
|
||||||
try {
|
try {
|
||||||
cache_->saveState(res);
|
cache::client()->saveState(res);
|
||||||
emit initializeViews(std::move(res.rooms));
|
emit initializeViews(std::move(res.rooms));
|
||||||
emit initializeRoomList(cache_->roomInfo());
|
emit initializeRoomList(cache::client()->roomInfo());
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
qWarning() << "cache error:" << QString::fromStdString(e.what());
|
qWarning() << "cache error:" << QString::fromStdString(e.what());
|
||||||
emit retryInitialSync();
|
emit retryInitialSync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit continueSync(cache_->nextBatchToken());
|
emit continueSync(cache::client()->nextBatchToken());
|
||||||
emit contentLoaded();
|
emit contentLoaded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -591,8 +587,8 @@ ChatPage::updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_na
|
|||||||
if (!avatar_url.isValid())
|
if (!avatar_url.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!cache_.isNull()) {
|
if (cache::client()) {
|
||||||
auto data = cache_->image(avatar_url.toString());
|
auto data = cache::client()->image(avatar_url.toString());
|
||||||
if (!data.isNull()) {
|
if (!data.isNull()) {
|
||||||
user_info_widget_->setAvatar(QImage::fromData(data));
|
user_info_widget_->setAvatar(QImage::fromData(data));
|
||||||
return;
|
return;
|
||||||
@ -635,7 +631,7 @@ ChatPage::changeTopRoomInfo(const QString &room_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto room_info = cache_->getRoomInfo({room_id.toStdString()});
|
auto room_info = cache::client()->getRoomInfo({room_id.toStdString()});
|
||||||
|
|
||||||
if (room_info.find(room_id) == room_info.end())
|
if (room_info.find(room_id) == room_info.end())
|
||||||
return;
|
return;
|
||||||
@ -646,7 +642,7 @@ ChatPage::changeTopRoomInfo(const QString &room_id)
|
|||||||
top_bar_->updateRoomName(name);
|
top_bar_->updateRoomName(name);
|
||||||
top_bar_->updateRoomTopic(QString::fromStdString(room_info[room_id].topic));
|
top_bar_->updateRoomTopic(QString::fromStdString(room_info[room_id].topic));
|
||||||
|
|
||||||
auto img = cache_->getRoomAvatar(room_id);
|
auto img = cache::client()->getRoomAvatar(room_id);
|
||||||
|
|
||||||
if (img.isNull())
|
if (img.isNull())
|
||||||
top_bar_->updateRoomAvatarFromName(name);
|
top_bar_->updateRoomAvatarFromName(name);
|
||||||
@ -679,10 +675,10 @@ ChatPage::loadStateFromCache()
|
|||||||
|
|
||||||
QtConcurrent::run([this]() {
|
QtConcurrent::run([this]() {
|
||||||
try {
|
try {
|
||||||
cache_->populateMembers();
|
cache::client()->populateMembers();
|
||||||
|
|
||||||
emit initializeEmptyViews(cache_->joinedRooms());
|
emit initializeEmptyViews(cache::client()->joinedRooms());
|
||||||
emit initializeRoomList(cache_->roomInfo());
|
emit initializeRoomList(cache::client()->roomInfo());
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
std::cout << "load cache error:" << e.what() << '\n';
|
std::cout << "load cache error:" << e.what() << '\n';
|
||||||
// TODO Clear cache and restart.
|
// TODO Clear cache and restart.
|
||||||
@ -690,7 +686,7 @@ ChatPage::loadStateFromCache()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start receiving events.
|
// Start receiving events.
|
||||||
emit continueSync(cache_->nextBatchToken());
|
emit continueSync(cache::client()->nextBatchToken());
|
||||||
|
|
||||||
// Check periodically if the timelines have been loaded.
|
// Check periodically if the timelines have been loaded.
|
||||||
emit startConsesusTimer();
|
emit startConsesusTimer();
|
||||||
@ -702,7 +698,7 @@ ChatPage::showQuickSwitcher()
|
|||||||
{
|
{
|
||||||
if (quickSwitcher_.isNull()) {
|
if (quickSwitcher_.isNull()) {
|
||||||
quickSwitcher_ = QSharedPointer<QuickSwitcher>(
|
quickSwitcher_ = QSharedPointer<QuickSwitcher>(
|
||||||
new QuickSwitcher(cache_, this),
|
new QuickSwitcher(this),
|
||||||
[](QuickSwitcher *switcher) { switcher->deleteLater(); });
|
[](QuickSwitcher *switcher) { switcher->deleteLater(); });
|
||||||
|
|
||||||
connect(quickSwitcher_.data(),
|
connect(quickSwitcher_.data(),
|
||||||
@ -731,8 +727,8 @@ void
|
|||||||
ChatPage::removeRoom(const QString &room_id)
|
ChatPage::removeRoom(const QString &room_id)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
cache_->removeRoom(room_id);
|
cache::client()->removeRoom(room_id);
|
||||||
cache_->removeInvite(room_id.toStdString());
|
cache::client()->removeInvite(room_id.toStdString());
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
qCritical() << "The cache couldn't be updated: " << e.what();
|
qCritical() << "The cache couldn't be updated: " << e.what();
|
||||||
// TODO: Notify the user.
|
// TODO: Notify the user.
|
||||||
@ -800,7 +796,7 @@ ChatPage::showReadReceipts(const QString &event_id)
|
|||||||
receiptsModal_->setColor(QColor(30, 30, 30, 170));
|
receiptsModal_->setColor(QColor(30, 30, 30, 170));
|
||||||
}
|
}
|
||||||
|
|
||||||
receiptsDialog_->addUsers(cache_->readReceipts(event_id, current_room_));
|
receiptsDialog_->addUsers(cache::client()->readReceipts(event_id, current_room_));
|
||||||
receiptsModal_->show();
|
receiptsModal_->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -858,23 +854,24 @@ ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (item.read) {
|
if (item.read) {
|
||||||
cache_->removeReadNotification(event_id);
|
cache::client()->removeReadNotification(event_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cache_->isNotificationSent(event_id)) {
|
if (!cache::client()->isNotificationSent(event_id)) {
|
||||||
const auto room_id = QString::fromStdString(item.room_id);
|
const auto room_id = QString::fromStdString(item.room_id);
|
||||||
const auto user_id = utils::event_sender(item.event);
|
const auto user_id = utils::event_sender(item.event);
|
||||||
|
|
||||||
// We should only sent one notification per event.
|
// We should only sent one notification per event.
|
||||||
cache_->markSentNotification(event_id);
|
cache::client()->markSentNotification(event_id);
|
||||||
|
|
||||||
// Don't send a notification when the current room is opened.
|
// Don't send a notification when the current room is opened.
|
||||||
if (isRoomActive(room_id))
|
if (isRoomActive(room_id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
NotificationsManager::postNotification(
|
NotificationsManager::postNotification(
|
||||||
QString::fromStdString(cache_->singleRoomInfo(item.room_id).name),
|
QString::fromStdString(
|
||||||
|
cache::client()->singleRoomInfo(item.room_id).name),
|
||||||
Cache::displayName(room_id, user_id),
|
Cache::displayName(room_id, user_id),
|
||||||
utils::event_body(item.event));
|
utils::event_body(item.event));
|
||||||
}
|
}
|
||||||
|
@ -276,8 +276,8 @@ MainWindow::openRoomSettings(const QString &room_id)
|
|||||||
{
|
{
|
||||||
const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : "";
|
const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : "";
|
||||||
|
|
||||||
roomSettingsDialog_ = QSharedPointer<dialogs::RoomSettings>(
|
roomSettingsDialog_ =
|
||||||
new dialogs::RoomSettings(roomToSearch, chat_page_->cache(), this));
|
QSharedPointer<dialogs::RoomSettings>(new dialogs::RoomSettings(roomToSearch, this));
|
||||||
|
|
||||||
connect(roomSettingsDialog_.data(), &dialogs::RoomSettings::closing, this, [this]() {
|
connect(roomSettingsDialog_.data(), &dialogs::RoomSettings::closing, this, [this]() {
|
||||||
roomSettingsModal_->hide();
|
roomSettingsModal_->hide();
|
||||||
@ -294,8 +294,8 @@ MainWindow::openMemberListDialog(const QString &room_id)
|
|||||||
{
|
{
|
||||||
const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : "";
|
const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : "";
|
||||||
|
|
||||||
memberListDialog_ = QSharedPointer<dialogs::MemberList>(
|
memberListDialog_ =
|
||||||
new dialogs::MemberList(roomToSearch, chat_page_->cache(), this));
|
QSharedPointer<dialogs::MemberList>(new dialogs::MemberList(roomToSearch, this));
|
||||||
|
|
||||||
memberListModal_ =
|
memberListModal_ =
|
||||||
QSharedPointer<OverlayModal>(new OverlayModal(this, memberListDialog_.data()));
|
QSharedPointer<OverlayModal>(new OverlayModal(this, memberListDialog_.data()));
|
||||||
|
@ -56,9 +56,8 @@ RoomSearchInput::hideEvent(QHideEvent *event)
|
|||||||
TextField::hideEvent(event);
|
TextField::hideEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
QuickSwitcher::QuickSwitcher(QSharedPointer<Cache> cache, QWidget *parent)
|
QuickSwitcher::QuickSwitcher(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, cache_{cache}
|
|
||||||
{
|
{
|
||||||
qRegisterMetaType<std::vector<RoomSearchResult>>();
|
qRegisterMetaType<std::vector<RoomSearchResult>>();
|
||||||
setMaximumWidth(450);
|
setMaximumWidth(450);
|
||||||
@ -93,7 +92,8 @@ QuickSwitcher::QuickSwitcher(QSharedPointer<Cache> cache, QWidget *parent)
|
|||||||
|
|
||||||
QtConcurrent::run([this, query = query.toLower()]() {
|
QtConcurrent::run([this, query = query.toLower()]() {
|
||||||
try {
|
try {
|
||||||
emit queryResults(cache_->searchRooms(query.toStdString()));
|
emit queryResults(
|
||||||
|
cache::client()->searchRooms(query.toStdString()));
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
qWarning() << "room search failed:" << e.what();
|
qWarning() << "room search failed:" << e.what();
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,8 @@ RoomList::RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
|||||||
const QPixmap &img,
|
const QPixmap &img,
|
||||||
const QString &url,
|
const QString &url,
|
||||||
const QByteArray &data) {
|
const QByteArray &data) {
|
||||||
if (!cache_.isNull())
|
if (cache::client())
|
||||||
cache_->saveImage(url, data);
|
cache::client()->saveImage(url, data);
|
||||||
|
|
||||||
updateRoomAvatar(room_id, img);
|
updateRoomAvatar(room_id, img);
|
||||||
});
|
});
|
||||||
@ -97,8 +97,8 @@ RoomList::updateAvatar(const QString &room_id, const QString &url)
|
|||||||
|
|
||||||
QByteArray savedImgData;
|
QByteArray savedImgData;
|
||||||
|
|
||||||
if (!cache_.isNull())
|
if (cache::client())
|
||||||
savedImgData = cache_->image(url);
|
savedImgData = cache::client()->image(url);
|
||||||
|
|
||||||
if (savedImgData.isEmpty()) {
|
if (savedImgData.isEmpty()) {
|
||||||
http::client()->fetchRoomAvatar(room_id, url);
|
http::client()->fetchRoomAvatar(room_id, url);
|
||||||
|
@ -453,12 +453,12 @@ TextInputWidget::TextInputWidget(QWidget *parent)
|
|||||||
input_->setFixedHeight(textInputHeight);
|
input_->setFixedHeight(textInputHeight);
|
||||||
});
|
});
|
||||||
connect(input_, &FilteredTextEdit::showSuggestions, this, [this](const QString &q) {
|
connect(input_, &FilteredTextEdit::showSuggestions, this, [this](const QString &q) {
|
||||||
if (q.isEmpty() || cache_.isNull())
|
if (q.isEmpty() || !cache::client())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QtConcurrent::run([this, q = q.toLower().toStdString()]() {
|
QtConcurrent::run([this, q = q.toLower().toStdString()]() {
|
||||||
try {
|
try {
|
||||||
emit input_->resultsRetrieved(cache_->searchUsers(
|
emit input_->resultsRetrieved(cache::client()->searchUsers(
|
||||||
ChatPage::instance()->currentRoom().toStdString(), q));
|
ChatPage::instance()->currentRoom().toStdString(), q));
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
|
@ -56,10 +56,9 @@ MemberItem::MemberItem(const RoomMember &member, QWidget *parent)
|
|||||||
topLayout_->addLayout(textLayout_, 1);
|
topLayout_->addLayout(textLayout_, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemberList::MemberList(const QString &room_id, QSharedPointer<Cache> cache, QWidget *parent)
|
MemberList::MemberList(const QString &room_id, QWidget *parent)
|
||||||
: QFrame(parent)
|
: QFrame(parent)
|
||||||
, room_id_{room_id}
|
, room_id_{room_id}
|
||||||
, cache_{cache}
|
|
||||||
{
|
{
|
||||||
setMaximumSize(420, 380);
|
setMaximumSize(420, 380);
|
||||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
@ -99,11 +98,11 @@ MemberList::MemberList(const QString &room_id, QSharedPointer<Cache> cache, QWid
|
|||||||
const size_t numMembers = list_->count() - 1;
|
const size_t numMembers = list_->count() - 1;
|
||||||
|
|
||||||
if (numMembers > 0)
|
if (numMembers > 0)
|
||||||
addUsers(cache_->getMembers(room_id_.toStdString(), numMembers));
|
addUsers(cache::client()->getMembers(room_id_.toStdString(), numMembers));
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addUsers(cache_->getMembers(room_id_.toStdString()));
|
addUsers(cache::client()->getMembers(room_id_.toStdString()));
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
qCritical() << e.what();
|
qCritical() << e.what();
|
||||||
}
|
}
|
||||||
|
@ -15,18 +15,17 @@
|
|||||||
|
|
||||||
using namespace dialogs;
|
using namespace dialogs;
|
||||||
|
|
||||||
RoomSettings::RoomSettings(const QString &room_id, QSharedPointer<Cache> cache, QWidget *parent)
|
RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
|
||||||
: QFrame(parent)
|
: QFrame(parent)
|
||||||
, cache_{cache}
|
|
||||||
, room_id_{std::move(room_id)}
|
, room_id_{std::move(room_id)}
|
||||||
{
|
{
|
||||||
setMaximumWidth(385);
|
setMaximumWidth(385);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto res = cache_->getRoomInfo({room_id_.toStdString()});
|
auto res = cache::client()->getRoomInfo({room_id_.toStdString()});
|
||||||
info_ = res[room_id_];
|
info_ = res[room_id_];
|
||||||
|
|
||||||
setAvatar(QImage::fromData(cache_->image(info_.avatar_url)));
|
setAvatar(QImage::fromData(cache::client()->image(info_.avatar_url)));
|
||||||
} catch (const lmdb::error &e) {
|
} catch (const lmdb::error &e) {
|
||||||
qWarning() << "failed to retrieve room info from cache" << room_id;
|
qWarning() << "failed to retrieve room info from cache" << room_id;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user