diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp
index b16bf1d2..be4bc09e 100644
--- a/src/timeline/EventStore.cpp
+++ b/src/timeline/EventStore.cpp
@@ -242,9 +242,12 @@ EventStore::receivedSessionKey(const std::string &session_id)
return;
auto request = pending_key_requests.at(session_id);
- pending_key_requests.erase(session_id);
- olm::send_key_request_for(request.events.front(), request.request_id, true);
+ // Don't request keys again until Nheko is restarted (for now)
+ pending_key_requests[session_id].events.clear();
+
+ if (!request.events.empty())
+ olm::send_key_request_for(request.events.front(), request.request_id, true);
for (const auto &e : request.events) {
auto idx = idToIndex(e.event_id);
@@ -778,7 +781,8 @@ EventStore::fetchMore()
if (cache::client()->previousBatchToken(room_id_) != opts.from) {
nhlog::net()->warn("Cache cleared while fetching more messages, dropping "
"/messages response");
- emit fetchedMore();
+ if (!opts.to.empty())
+ emit fetchedMore();
return;
}
if (err) {
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 97af0065..93451976 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -128,6 +128,10 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
"UserProfile needs to be instantiated on the C++ side");
static auto self = this;
+ qmlRegisterSingletonType<MainWindow>(
+ "im.nheko", 1, 0, "MainWindow", [](QQmlEngine *, QJSEngine *) -> QObject * {
+ return MainWindow::instance();
+ });
qmlRegisterSingletonType<TimelineViewManager>(
"im.nheko", 1, 0, "TimelineManager", [](QQmlEngine *, QJSEngine *) -> QObject * {
return self;
diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index 23a960b8..74128865 100644
--- a/src/timeline/TimelineViewManager.h
+++ b/src/timeline/TimelineViewManager.h
@@ -36,6 +36,8 @@ class TimelineViewManager : public QObject
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
Q_PROPERTY(
bool isNarrowView MEMBER isNarrowView_ READ isNarrowView NOTIFY narrowViewChanged)
+ Q_PROPERTY(
+ bool isWindowFocused MEMBER isWindowFocused_ READ isWindowFocused NOTIFY focusChanged)
public:
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
@@ -54,6 +56,7 @@ public:
Q_INVOKABLE TimelineModel *activeTimeline() const { return timeline_; }
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
bool isNarrowView() const { return isNarrowView_; }
+ bool isWindowFocused() const { return isWindowFocused_; }
Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const;
Q_INVOKABLE QColor userColor(QString id, QColor background);
Q_INVOKABLE QString escapeEmoji(QString str) const;
@@ -83,11 +86,17 @@ signals:
void inviteUsers(QStringList users);
void showRoomList();
void narrowViewChanged();
+ void focusChanged();
public slots:
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
void receivedSessionKey(const std::string &room_id, const std::string &session_id);
void initWithMessages(const std::vector<QString> &roomIds);
+ void chatFocusChanged(bool focused)
+ {
+ isWindowFocused_ = focused;
+ emit focusChanged();
+ }
void setHistoryView(const QString &room_id);
TimelineModel *getHistoryView(const QString &room_id)
@@ -145,8 +154,9 @@ private:
TimelineModel *timeline_ = nullptr;
CallManager *callManager_ = nullptr;
- bool isInitialSync_ = true;
- bool isNarrowView_ = false;
+ bool isInitialSync_ = true;
+ bool isNarrowView_ = false;
+ bool isWindowFocused_ = false;
QHash<QString, QColor> userColors;
|