aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp13
-rw-r--r--lib/connection.h5
-rw-r--r--lib/csapi/capabilities.cpp30
-rw-r--r--lib/csapi/capabilities.h23
-rw-r--r--lib/csapi/gtad.yaml3
-rw-r--r--lib/util.h1
6 files changed, 56 insertions, 19 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 88fb547f..2a2d4822 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -90,6 +90,7 @@ class Connection::Private
DirectChatUsersMap directChatUsers;
std::unordered_map<QString, EventPtr> accountData;
QString userId;
+ int syncLoopTimeout = -1;
SyncJob* syncJob = nullptr;
@@ -230,6 +231,11 @@ void Connection::doConnectToServer(const QString& user, const QString& password,
});
}
+void Connection::syncLoopIteration()
+{
+ sync(d->syncLoopTimeout);
+}
+
void Connection::connectWithToken(const QString& userId,
const QString& accessToken,
const QString& deviceId)
@@ -319,6 +325,13 @@ void Connection::sync(int timeout)
});
}
+void Connection::syncLoop(int timeout)
+{
+ d->syncLoopTimeout = timeout;
+ connect(this, &Connection::syncDone, this, &Connection::syncLoopIteration);
+ syncLoopIteration(); // initial sync to start the loop
+}
+
void Connection::onSyncSuccess(SyncData &&data, bool fromCache) {
d->data->setLastEvent(data.nextBatch());
for (auto&& roomData: data.takeRoomData())
diff --git a/lib/connection.h b/lib/connection.h
index 9e4c1a26..8c938df2 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -371,6 +371,8 @@ namespace QMatrixClient
void logout();
void sync(int timeout = -1);
+ void syncLoop(int timeout = -1);
+
void stopSync();
QString nextBatchToken() const;
@@ -679,6 +681,9 @@ namespace QMatrixClient
*/
void onSyncSuccess(SyncData &&data, bool fromCache = false);
+ protected slots:
+ void syncLoopIteration();
+
private:
class Private;
std::unique_ptr<Private> d;
diff --git a/lib/csapi/capabilities.cpp b/lib/csapi/capabilities.cpp
index a8e79f6b..210423f5 100644
--- a/lib/csapi/capabilities.cpp
+++ b/lib/csapi/capabilities.cpp
@@ -28,17 +28,26 @@ namespace QMatrixClient
{
static void fillFrom(const QJsonObject& jo, GetCapabilitiesJob::RoomVersionsCapability& result)
{
- fromJson(jo.value("default"_ls), result.isDefault);
+ fromJson(jo.value("default"_ls), result.defaultVersion);
fromJson(jo.value("available"_ls), result.available);
}
};
+
+ template <> struct JsonObjectConverter<GetCapabilitiesJob::Capabilities>
+ {
+ static void fillFrom(QJsonObject jo, GetCapabilitiesJob::Capabilities& result)
+ {
+ fromJson(jo.take("m.change_password"_ls), result.changePassword);
+ fromJson(jo.take("m.room_versions"_ls), result.roomVersions);
+ fromJson(jo, result.additionalProperties);
+ }
+ };
} // namespace QMatrixClient
class GetCapabilitiesJob::Private
{
public:
- Omittable<ChangePasswordCapability> changePassword;
- Omittable<RoomVersionsCapability> roomVersions;
+ Capabilities capabilities;
};
QUrl GetCapabilitiesJob::makeRequestUrl(QUrl baseUrl)
@@ -58,21 +67,18 @@ GetCapabilitiesJob::GetCapabilitiesJob()
GetCapabilitiesJob::~GetCapabilitiesJob() = default;
-const Omittable<GetCapabilitiesJob::ChangePasswordCapability>& GetCapabilitiesJob::changePassword() const
-{
- return d->changePassword;
-}
-
-const Omittable<GetCapabilitiesJob::RoomVersionsCapability>& GetCapabilitiesJob::roomVersions() const
+const GetCapabilitiesJob::Capabilities& GetCapabilitiesJob::capabilities() const
{
- return d->roomVersions;
+ return d->capabilities;
}
BaseJob::Status GetCapabilitiesJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
- fromJson(json.value("m.change_password"_ls), d->changePassword);
- fromJson(json.value("m.room_versions"_ls), d->roomVersions);
+ if (!json.contains("capabilities"_ls))
+ return { JsonParseError,
+ "The key 'capabilities' not found in the response" };
+ fromJson(json.value("capabilities"_ls), d->capabilities);
return Success;
}
diff --git a/lib/csapi/capabilities.h b/lib/csapi/capabilities.h
index e38483bc..39e2f4d1 100644
--- a/lib/csapi/capabilities.h
+++ b/lib/csapi/capabilities.h
@@ -6,6 +6,7 @@
#include "jobs/basejob.h"
+#include <QtCore/QJsonObject>
#include "converters.h"
#include <QtCore/QHash>
@@ -33,11 +34,24 @@ namespace QMatrixClient
struct RoomVersionsCapability
{
/// The default room version the server is using for new rooms.
- QString isDefault;
+ QString defaultVersion;
/// A detailed description of the room versions the server supports.
QHash<QString, QString> available;
};
+ /// Gets information about the server's supported feature set
+ /// and other relevant capabilities.
+ struct Capabilities
+ {
+ /// Capability to indicate if the user can change their password.
+ Omittable<ChangePasswordCapability> changePassword;
+ /// The room versions the server supports.
+ Omittable<RoomVersionsCapability> roomVersions;
+ /// The custom capabilities the server supports, using the
+ /// Java package naming convention.
+ QHash<QString, QJsonObject> additionalProperties;
+ };
+
// Construction/destruction
explicit GetCapabilitiesJob();
@@ -54,10 +68,9 @@ namespace QMatrixClient
// Result properties
- /// Capability to indicate if the user can change their password.
- const Omittable<ChangePasswordCapability>& changePassword() const;
- /// The room versions the server supports.
- const Omittable<RoomVersionsCapability>& roomVersions() const;
+ /// Gets information about the server's supported feature set
+ /// and other relevant capabilities.
+ const Capabilities& capabilities() const;
protected:
Status parseJson(const QJsonDocument& data) override;
diff --git a/lib/csapi/gtad.yaml b/lib/csapi/gtad.yaml
index 21a59a5c..a44f803a 100644
--- a/lib/csapi/gtad.yaml
+++ b/lib/csapi/gtad.yaml
@@ -5,7 +5,8 @@ analyzer:
identifiers:
signed: signedData
unsigned: unsignedData
- default: isDefault
+ PushRule/default: isDefault
+ default: defaultVersion # getCapabilities/RoomVersionsCapability
origin_server_ts: originServerTimestamp # Instead of originServerTs
start: begin # Because start() is a method in BaseJob
m.upload.size: uploadSize
diff --git a/lib/util.h b/lib/util.h
index 420b0984..596872e2 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -159,7 +159,6 @@ namespace QMatrixClient
}
value_type&& release() { _omitted = true; return std::move(_value); }
- operator const value_type&() const & { return value(); }
const value_type* operator->() const & { return &value(); }
value_type* operator->() & { return &editValue(); }
const value_type& operator*() const & { return value(); }