From 5dd59a8c136918fb9c678db628c709141a5bd2c5 Mon Sep 17 00:00:00 2001
From: Tobias Fella <fella@posteo.de>
Date: Tue, 4 Jul 2023 22:24:23 +0200
Subject: [PATCH] Pick libQuotient 0.8 fixes

---
 src/controller.cpp  | 22 ++++++++++------------
 src/login.cpp       |  2 +-
 src/neochatroom.cpp | 10 ----------
 src/neochatroom.h   |  1 -
 4 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/src/controller.cpp b/src/controller.cpp
index b71953fd..d9a81137 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -125,18 +125,18 @@ Controller::Controller(QObject *parent)
     }
 #endif
 
-    connect(&AccountRegistry::instance(), &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged);
+    connect(&Accounts, &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged);
 
 #ifdef QUOTIENT_07
     static int oldAccountCount = 0;
-    connect(&AccountRegistry::instance(), &AccountRegistry::accountCountChanged, this, [=]() {
-        if (AccountRegistry::instance().size() > oldAccountCount) {
-            auto connection = AccountRegistry::instance().accounts()[AccountRegistry::instance().size() - 1];
-            connect(connection, &Connection::syncDone, this, [=]() {
+    connect(&Accounts, &AccountRegistry::accountCountChanged, this, [this]() {
+        if (Accounts.size() > oldAccountCount) {
+            auto connection = Accounts.accounts()[Accounts.size() - 1];
+            connect(connection, &Connection::syncDone, this, [this, connection]() {
                 handleNotifications(connection);
             });
         }
-        oldAccountCount = AccountRegistry::instance().size();
+        oldAccountCount = Accounts.size();
     });
 #endif
 }
@@ -277,10 +277,10 @@ void Controller::logout(Connection *conn, bool serverSideLogout)
     job.start();
     loop.exec();
 
-    if (AccountRegistry::instance().count() > 1) {
+    if (Accounts.count() > 1) {
         // Only set the connection if the the account being logged out is currently active
         if (conn == activeConnection()) {
-            setActiveConnection(AccountRegistry::instance().accounts()[0]);
+            setActiveConnection(Accounts.accounts()[0]);
         }
     } else {
         setActiveConnection(nullptr);
@@ -295,9 +295,7 @@ void Controller::addConnection(Connection *c)
 {
     Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection");
 
-#ifndef QUOTIENT_07
-    AccountRegistry::instance().add(c);
-#endif
+    Accounts.add(c);
 
     c->setLazyLoading(true);
 
@@ -548,7 +546,7 @@ NeochatChangePasswordJob::NeochatChangePasswordJob(const QString &newPassword, b
 
 int Controller::accountCount() const
 {
-    return AccountRegistry::instance().count();
+    return Accounts.count();
 }
 
 bool Controller::quitOnLastWindowClosed()
diff --git a/src/login.cpp b/src/login.cpp
index 1121875f..7a7a3783 100644
--- a/src/login.cpp
+++ b/src/login.cpp
@@ -43,7 +43,7 @@ void Login::init()
             return;
         }
 
-        m_isLoggedIn = AccountRegistry::instance().isLoggedIn(m_matrixId);
+        m_isLoggedIn = Accounts.isLoggedIn(m_matrixId);
         Q_EMIT isLoggedInChanged();
         if (m_isLoggedIn) {
             return;
diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp
index bda53004..59afb831 100644
--- a/src/neochatroom.cpp
+++ b/src/neochatroom.cpp
@@ -63,8 +63,6 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
     : Room(connection, std::move(roomId), joinState)
 {
     connect(connection, &Connection::accountDataChanged, this, &NeoChatRoom::updatePushNotificationState);
-    connect(this, &NeoChatRoom::notificationCountChanged, this, &NeoChatRoom::countChanged);
-    connect(this, &NeoChatRoom::highlightCountChanged, this, &NeoChatRoom::countChanged);
     connect(this, &Room::fileTransferCompleted, this, [this] {
         setFileUploadingProgress(0);
         setHasFileUploading(false);
@@ -339,14 +337,6 @@ void NeoChatRoom::onRedaction(const RoomEvent &prevEvent, const RoomEvent & /*af
     }
 }
 
-void NeoChatRoom::countChanged()
-{
-    if (displayed() && !hasUnreadMessages()) {
-        resetNotificationCount();
-        resetHighlightCount();
-    }
-}
-
 QDateTime NeoChatRoom::lastActiveTime()
 {
     if (timelineSize() == 0) {
diff --git a/src/neochatroom.h b/src/neochatroom.h
index 6341eb1b..4dcedbaa 100644
--- a/src/neochatroom.h
+++ b/src/neochatroom.h
@@ -385,7 +385,6 @@ private:
 #endif
 
 private Q_SLOTS:
-    void countChanged();
     void updatePushNotificationState(QString type);
 
 Q_SIGNALS:
-- 
2.41.0

