aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.h
diff options
context:
space:
mode:
authorHubert Chathi <uhoreg@debian.org>2020-04-20 18:01:38 -0400
committerHubert Chathi <uhoreg@debian.org>2020-04-20 18:01:38 -0400
commit035d428becd62869b88793bb48d59410056b1f31 (patch)
tree0cd837955fa1037c74ee524a089ff1b788b75861 /lib/connection.h
parent688dc682e0c6ae12dc87d781ffe53c974dad60df (diff)
parentd8e1f4ee70902e2b9e5e9c699423d7f3fafe6238 (diff)
downloadlibquotient-035d428becd62869b88793bb48d59410056b1f31.tar.gz
libquotient-035d428becd62869b88793bb48d59410056b1f31.zip
Update upstream source from tag 'upstream/0.5.3.2'
Update to upstream version '0.5.3.2' with Debian dir 49a325a077f4a2ebcd5b73adf3782a6fb5ecb3fe
Diffstat (limited to 'lib/connection.h')
-rw-r--r--lib/connection.h92
1 files changed, 88 insertions, 4 deletions
diff --git a/lib/connection.h b/lib/connection.h
index ea5be51a..b0dfeb5e 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -18,6 +18,8 @@
#pragma once
+#include "csapi/login.h"
+#include "ssosession.h"
#include "csapi/create_room.h"
#include "joinstate.h"
#include "events/accountdataevents.h"
@@ -30,6 +32,8 @@
#include <functional>
#include <memory>
+Q_DECLARE_METATYPE(QMatrixClient::GetLoginFlowsJob::LoginFlow)
+
namespace QMatrixClient
{
class Room;
@@ -51,6 +55,28 @@ namespace QMatrixClient
class SendMessageJob;
class LeaveRoomJob;
+ // To simplify comparisons of LoginFlows
+
+ inline bool operator==(const GetLoginFlowsJob::LoginFlow& lhs,
+ const GetLoginFlowsJob::LoginFlow& rhs)
+ {
+ return lhs.type == rhs.type;
+ }
+
+ inline bool operator!=(const GetLoginFlowsJob::LoginFlow& lhs,
+ const GetLoginFlowsJob::LoginFlow& rhs)
+ {
+ return !(lhs == rhs);
+ }
+
+ /// Predefined login flows
+ namespace LoginFlows {
+ using LoginFlow = GetLoginFlowsJob::LoginFlow;
+ static const LoginFlow Password { "m.login.password" };
+ static const LoginFlow SSO { "m.login.sso" };
+ static const LoginFlow Token { "m.login.token" };
+ }
+
class Connection;
using room_factory_t = std::function<Room*(Connection*, const QString&,
@@ -95,9 +121,6 @@ namespace QMatrixClient
class Connection: public QObject {
Q_OBJECT
- /** Whether or not the rooms state should be cached locally
- * \sa loadState(), saveState()
- */
Q_PROPERTY(User* localUser READ user NOTIFY stateChanged)
Q_PROPERTY(QString localUserId READ userId NOTIFY stateChanged)
Q_PROPERTY(QString deviceId READ deviceId NOTIFY stateChanged)
@@ -105,6 +128,9 @@ namespace QMatrixClient
Q_PROPERTY(QString defaultRoomVersion READ defaultRoomVersion NOTIFY capabilitiesLoaded)
Q_PROPERTY(QUrl homeserver READ homeserver WRITE setHomeserver NOTIFY homeserverChanged)
Q_PROPERTY(QString domain READ domain NOTIFY homeserverChanged)
+ Q_PROPERTY(QVector<QMatrixClient::GetLoginFlowsJob::LoginFlow> loginFlows READ loginFlows NOTIFY loginFlowsChanged)
+ Q_PROPERTY(bool supportsSso READ supportsSso NOTIFY loginFlowsChanged)
+ Q_PROPERTY(bool supportsPasswordAuth READ supportsPasswordAuth NOTIFY loginFlowsChanged)
Q_PROPERTY(bool cacheState READ cacheState WRITE setCacheState NOTIFY cacheStateChanged)
Q_PROPERTY(bool lazyLoading READ lazyLoading WRITE setLazyLoading NOTIFY lazyLoadingChanged)
@@ -128,11 +154,38 @@ namespace QMatrixClient
virtual ~Connection();
/** Get all Invited and Joined rooms
+ *
+ * \deprecated
+ * Use allRooms(), roomsWithTag(), or rooms(JoinStates) instead
* \return a hashmap from a composite key - room name and whether
* it's an Invite rather than Join - to room pointers
*/
QHash<QPair<QString, bool>, Room*> roomMap() const;
+ /** Get all rooms known within this Connection
+ *
+ * This includes Invite, Join and Leave rooms, in no particular order.
+ * \note Leave rooms will only show up in the list if they have been left
+ * in the same running session. The library doesn't cache left rooms
+ * between runs and it doesn't retrieve the full list of left rooms
+ * from the server.
+ * \sa rooms, room, roomsWithTag
+ */
+ Q_INVOKABLE QVector<Room*> allRooms() const;
+
+ /** Get rooms that have either of the given join state(s)
+ *
+ * This method returns, in no particular order, rooms which join state
+ * matches the mask passed in \p joinStates.
+ * \note Similar to allRooms(), this won't retrieve the full list of
+ * Leave rooms from the server.
+ * \sa allRooms, room, roomsWithTag
+ */
+ Q_INVOKABLE QVector<Room*> rooms(JoinStates joinStates) const;
+
+ /** Get the total number of rooms in the given join state(s) */
+ Q_INVOKABLE int roomsCount(JoinStates joinStates) const;
+
/** Check whether the account has data of the given type
* Direct chats map is not supported by this method _yet_.
*/
@@ -246,6 +299,12 @@ namespace QMatrixClient
QUrl homeserver() const;
/** Get the domain name used for ids/aliases on the server */
QString domain() const;
+ /** Get the list of supported login flows */
+ QVector<GetLoginFlowsJob::LoginFlow> loginFlows() const;
+ /** Check whether the current homeserver supports password auth */
+ bool supportsPasswordAuth() const;
+ /** Check whether the current homeserver supports SSO */
+ bool supportsSso() const;
/** Find a room by its id and a mask of applicable states */
Q_INVOKABLE Room* room(const QString& roomId,
JoinStates states = JoinState::Invite|JoinState::Join) const;
@@ -372,6 +431,21 @@ namespace QMatrixClient
std::forward<JobArgTs>(jobArgs)...);
}
+ /** Get a request URL for a job with specified type and arguments
+ *
+ * This calls JobT::makeRequestUrl() prepending the connection's
+ * homeserver to the list of arguments.
+ */
+ template <typename JobT, typename... JobArgTs>
+ QUrl getUrlForApi(JobArgTs&&... jobArgs) const
+ {
+ return JobT::makeRequestUrl(homeserver(),
+ std::forward<JobArgTs>(jobArgs)...);
+ }
+
+ Q_INVOKABLE SsoSession* prepareForSso(
+ const QString& initialDeviceName, const QString& deviceId = {});
+
/** Generate a new transaction id. Transaction id's are unique within
* a single Connection object
*/
@@ -407,7 +481,16 @@ namespace QMatrixClient
void connectToServer(const QString& user, const QString& password,
const QString& initialDeviceName,
const QString& deviceId = {});
- void connectWithToken(const QString& userId, const QString& accessToken,
+ void loginWithToken(const QByteArray& loginToken,
+ const QString& initialDeviceName,
+ const QString& deviceId = {});
+ void assumeIdentity(const QString& userId, const QString& accessToken,
+ const QString& deviceId);
+ /*! @deprecated
+ * Use assumeIdentity() if you have an access token or
+ * loginWithToken() if you have a login token.
+ */
+ void connectWithToken(const QString& userId, const QString& accessToken,
const QString& deviceId);
/// Explicitly request capabilities from the server
void reloadCapabilities();
@@ -550,6 +633,7 @@ namespace QMatrixClient
void resolveError(QString error);
void homeserverChanged(QUrl baseUrl);
+ void loginFlowsChanged();
void capabilitiesLoaded();
void connected();