aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-03-13 18:39:59 +0100
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-03-13 18:39:59 +0100
commit4102144290312ebed7d4af69dd640835275a9675 (patch)
tree33599d55519b5d32dc82b485cb348b6f685d679c /lib/connection.cpp
parent301d29e8db272938b0977af5db872c80f89fd708 (diff)
downloadlibquotient-4102144290312ebed7d4af69dd640835275a9675.tar.gz
libquotient-4102144290312ebed7d4af69dd640835275a9675.zip
Connection: support getting the list of login flows
The flows themselves are not facilitated in any way (yet).
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r--lib/connection.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 6ad24fba..1989050e 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -30,7 +30,6 @@
#include "csapi/capabilities.h"
#include "csapi/joining.h"
#include "csapi/leaving.h"
-#include "csapi/login.h"
#include "csapi/logout.h"
#include "csapi/receipts.h"
#include "csapi/room_send.h"
@@ -111,6 +110,8 @@ public:
GetCapabilitiesJob* capabilitiesJob = nullptr;
GetCapabilitiesJob::Capabilities capabilities;
+ QVector<GetLoginFlowsJob::LoginFlow> loginFlows;
+
#ifdef Quotient_E2EE_ENABLED
QScopedPointer<EncryptionManager> encryptionManager;
#endif // Quotient_E2EE_ENABLED
@@ -1004,6 +1005,21 @@ QUrl Connection::homeserver() const { return d->data->baseUrl(); }
QString Connection::domain() const { return userId().section(':', 1); }
+QVector<GetLoginFlowsJob::LoginFlow> Connection::loginFlows() const
+{
+ return d->loginFlows;
+}
+
+bool Connection::supportsPasswordAuth() const
+{
+ return d->loginFlows.contains(LoginFlows::Password);
+}
+
+bool Connection::supportsSso() const
+{
+ return d->loginFlows.contains(LoginFlows::SSO);
+}
+
Room* Connection::room(const QString& roomId, JoinStates states) const
{
Room* room = d->roomMap.value({ roomId, false }, nullptr);
@@ -1400,11 +1416,21 @@ QByteArray Connection::generateTxnId() const
void Connection::setHomeserver(const QUrl& url)
{
- if (homeserver() == url)
- return;
+ if (homeserver() != url) {
+ d->data->setBaseUrl(url);
+ d->loginFlows.clear();
+ emit homeserverChanged(homeserver());
+ }
- d->data->setBaseUrl(url);
- emit homeserverChanged(homeserver());
+ // Whenever a homeserver is updated, retrieve available login flows from it
+ auto* j = callApi<GetLoginFlowsJob>(BackgroundRequest);
+ connect(j, &BaseJob::finished, this, [this, j] {
+ if (j->status().good())
+ d->loginFlows = j->flows();
+ else
+ d->loginFlows.clear();
+ emit loginFlowsChanged();
+ });
}
void Connection::saveRoomState(Room* r) const