aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--events/eventcontent.h4
-rw-r--r--events/roommessageevent.cpp5
-rw-r--r--events/roommessageevent.h1
-rw-r--r--jobs/downloadfilejob.cpp5
-rw-r--r--jobs/downloadfilejob.h3
-rw-r--r--jobs/generated/administrative_contact.cpp12
-rw-r--r--jobs/generated/administrative_contact.h14
-rw-r--r--jobs/generated/content-repo.cpp74
-rw-r--r--jobs/generated/content-repo.h28
-rw-r--r--jobs/generated/directory.cpp12
-rw-r--r--jobs/generated/directory.h14
-rw-r--r--jobs/generated/leaving.cpp12
-rw-r--r--jobs/generated/leaving.h14
-rw-r--r--jobs/generated/list_public_rooms.cpp40
-rw-r--r--jobs/generated/list_public_rooms.h7
-rw-r--r--jobs/generated/logout.cpp6
-rw-r--r--jobs/generated/logout.h7
-rw-r--r--jobs/generated/profile.cpp18
-rw-r--r--jobs/generated/profile.h21
-rw-r--r--jobs/generated/versions.cpp6
-rw-r--r--jobs/generated/versions.h7
-rw-r--r--jobs/generated/whoami.cpp6
-rw-r--r--jobs/generated/whoami.h7
-rw-r--r--jobs/mediathumbnailjob.cpp7
-rw-r--r--jobs/mediathumbnailjob.h4
-rw-r--r--room.cpp54
-rw-r--r--room.h2
27 files changed, 355 insertions, 35 deletions
diff --git a/events/eventcontent.h b/events/eventcontent.h
index 4afbaff3..9d44aec0 100644
--- a/events/eventcontent.h
+++ b/events/eventcontent.h
@@ -200,6 +200,7 @@ namespace QMatrixClient
explicit TypedBase(const QJsonObject& o = {}) : Base(o) { }
virtual QMimeType type() const = 0;
virtual const FileInfo* fileInfo() const { return nullptr; }
+ virtual const Thumbnail* thumbnailInfo() const { return nullptr; }
};
/**
@@ -256,6 +257,9 @@ namespace QMatrixClient
"thumbnailMediaId", thumbnail.mediaId());
}
+ const Thumbnail* thumbnailInfo() const override
+ { return &thumbnail; }
+
public:
Thumbnail thumbnail;
diff --git a/events/roommessageevent.cpp b/events/roommessageevent.cpp
index 8c088f21..dec0ca50 100644
--- a/events/roommessageevent.cpp
+++ b/events/roommessageevent.cpp
@@ -128,6 +128,11 @@ bool RoomMessageEvent::hasFileContent() const
return content() && content()->fileInfo();
}
+bool RoomMessageEvent::hasThumbnail() const
+{
+ return content() && content()->thumbnailInfo();
+}
+
QJsonObject RoomMessageEvent::toJson() const
{
QJsonObject obj = _content ? _content->toJson() : QJsonObject();
diff --git a/events/roommessageevent.h b/events/roommessageevent.h
index 2a5eeb7e..a55564ed 100644
--- a/events/roommessageevent.h
+++ b/events/roommessageevent.h
@@ -61,6 +61,7 @@ namespace QMatrixClient
QMimeType mimeType() const;
bool hasTextContent() const;
bool hasFileContent() const;
+ bool hasThumbnail() const;
QJsonObject toJson() const;
diff --git a/jobs/downloadfilejob.cpp b/jobs/downloadfilejob.cpp
index 06fa3b48..07d14197 100644
--- a/jobs/downloadfilejob.cpp
+++ b/jobs/downloadfilejob.cpp
@@ -20,6 +20,11 @@ class DownloadFileJob::Private
QScopedPointer<QFile> tempFile;
};
+QUrl DownloadFileJob::makeRequestUrl(QUrl baseUrl, const QUrl& mxcUri)
+{
+ return makeRequestUrl(baseUrl, mxcUri.authority(), mxcUri.path().mid(1));
+}
+
DownloadFileJob::DownloadFileJob(const QString& serverName,
const QString& mediaId,
const QString& localFilename)
diff --git a/jobs/downloadfilejob.h b/jobs/downloadfilejob.h
index d798506c..1815a7c8 100644
--- a/jobs/downloadfilejob.h
+++ b/jobs/downloadfilejob.h
@@ -9,6 +9,9 @@ namespace QMatrixClient
public:
enum { FileError = BaseJob::UserDefinedError + 1 };
+ using GetContentJob::makeRequestUrl;
+ static QUrl makeRequestUrl(QUrl baseUrl, const QUrl& mxcUri);
+
DownloadFileJob(const QString& serverName, const QString& mediaId,
const QString& localFilename = {});
diff --git a/jobs/generated/administrative_contact.cpp b/jobs/generated/administrative_contact.cpp
index 479bee52..1af57941 100644
--- a/jobs/generated/administrative_contact.cpp
+++ b/jobs/generated/administrative_contact.cpp
@@ -42,6 +42,12 @@ class GetAccount3PIDsJob::Private
QVector<ThirdPartyIdentifier> threepids;
};
+QUrl GetAccount3PIDsJob::makeRequestUrl(QUrl baseUrl)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/account/3pid");
+}
+
GetAccount3PIDsJob::GetAccount3PIDsJob()
: BaseJob(HttpVerb::Get, "GetAccount3PIDsJob",
basePath % "/account/3pid")
@@ -102,6 +108,12 @@ Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind)
setRequestData(_data);
}
+QUrl RequestTokenTo3PIDJob::makeRequestUrl(QUrl baseUrl)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/account/3pid/email/requestToken");
+}
+
RequestTokenTo3PIDJob::RequestTokenTo3PIDJob()
: BaseJob(HttpVerb::Post, "RequestTokenTo3PIDJob",
basePath % "/account/3pid/email/requestToken", false)
diff --git a/jobs/generated/administrative_contact.h b/jobs/generated/administrative_contact.h
index 67563719..c8429d39 100644
--- a/jobs/generated/administrative_contact.h
+++ b/jobs/generated/administrative_contact.h
@@ -29,6 +29,13 @@ namespace QMatrixClient
// End of inner data structures
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetAccount3PIDsJob. This function can be used when
+ * a URL for GetAccount3PIDsJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl);
+
explicit GetAccount3PIDsJob();
~GetAccount3PIDsJob() override;
@@ -64,6 +71,13 @@ namespace QMatrixClient
class RequestTokenTo3PIDJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * RequestTokenTo3PIDJob. This function can be used when
+ * a URL for RequestTokenTo3PIDJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl);
+
explicit RequestTokenTo3PIDJob();
};
} // namespace QMatrixClient
diff --git a/jobs/generated/content-repo.cpp b/jobs/generated/content-repo.cpp
index 93aa838c..51011251 100644
--- a/jobs/generated/content-repo.cpp
+++ b/jobs/generated/content-repo.cpp
@@ -19,17 +19,22 @@ class UploadContentJob::Private
QString contentUri;
};
+BaseJob::Query queryToUploadContent(const QString& filename)
+{
+ BaseJob::Query _q;
+ if (!filename.isEmpty())
+ _q.addQueryItem("filename", filename);
+ return _q;
+}
+
UploadContentJob::UploadContentJob(QIODevice* content, const QString& filename, const QString& contentType)
: BaseJob(HttpVerb::Post, "UploadContentJob",
- basePath % "/upload")
+ basePath % "/upload",
+ queryToUploadContent(filename))
, d(new Private)
{
setRequestHeader("Content-Type", contentType.toLatin1());
- QUrlQuery _q;
- if (!filename.isEmpty())
- _q.addQueryItem("filename", filename);
- setRequestQuery(_q);
setRequestData(Data(content));
}
@@ -58,6 +63,12 @@ class GetContentJob::Private
QIODevice* content;
};
+QUrl GetContentJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/download/" % serverName % "/" % mediaId);
+}
+
GetContentJob::GetContentJob(const QString& serverName, const QString& mediaId)
: BaseJob(HttpVerb::Get, "GetContentJob",
basePath % "/download/" % serverName % "/" % mediaId, false)
@@ -99,6 +110,12 @@ class GetContentOverrideNameJob::Private
QIODevice* content;
};
+QUrl GetContentOverrideNameJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, const QString& fileName)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/download/" % serverName % "/" % mediaId % "/" % fileName);
+}
+
GetContentOverrideNameJob::GetContentOverrideNameJob(const QString& serverName, const QString& mediaId, const QString& fileName)
: BaseJob(HttpVerb::Get, "GetContentOverrideNameJob",
basePath % "/download/" % serverName % "/" % mediaId % "/" % fileName, false)
@@ -139,17 +156,30 @@ class GetContentThumbnailJob::Private
QIODevice* content;
};
-GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width, int height, const QString& method)
- : BaseJob(HttpVerb::Get, "GetContentThumbnailJob",
- basePath % "/thumbnail/" % serverName % "/" % mediaId, false)
- , d(new Private)
+BaseJob::Query queryToGetContentThumbnail(int width, int height, const QString& method)
{
- QUrlQuery _q;
+ BaseJob::Query _q;
_q.addQueryItem("width", QString("%1").arg(width));
_q.addQueryItem("height", QString("%1").arg(height));
if (!method.isEmpty())
_q.addQueryItem("method", method);
- setRequestQuery(_q);
+ return _q;
+}
+
+QUrl GetContentThumbnailJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, int width, int height, const QString& method)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/thumbnail/" % serverName % "/" % mediaId,
+ queryToGetContentThumbnail(width, height, method));
+}
+
+GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width, int height, const QString& method)
+ : BaseJob(HttpVerb::Get, "GetContentThumbnailJob",
+ basePath % "/thumbnail/" % serverName % "/" % mediaId,
+ queryToGetContentThumbnail(width, height, method),
+ {}, false)
+ , d(new Private)
+{
setExpectedContentTypes({ "image/jpeg", "image/png" });
}
@@ -179,15 +209,27 @@ class GetUrlPreviewJob::Private
QString ogImage;
};
+BaseJob::Query queryToGetUrlPreview(const QString& url, double ts)
+{
+ BaseJob::Query _q;
+ _q.addQueryItem("url", url);
+ _q.addQueryItem("ts", QString("%1").arg(ts));
+ return _q;
+}
+
+QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QString& url, double ts)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/preview_url",
+ queryToGetUrlPreview(url, ts));
+}
+
GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, double ts)
: BaseJob(HttpVerb::Get, "GetUrlPreviewJob",
- basePath % "/preview_url")
+ basePath % "/preview_url",
+ queryToGetUrlPreview(url, ts))
, d(new Private)
{
- QUrlQuery _q;
- _q.addQueryItem("url", url);
- _q.addQueryItem("ts", QString("%1").arg(ts));
- setRequestQuery(_q);
}
GetUrlPreviewJob::~GetUrlPreviewJob() = default;
diff --git a/jobs/generated/content-repo.h b/jobs/generated/content-repo.h
index 0796322b..b4ea562f 100644
--- a/jobs/generated/content-repo.h
+++ b/jobs/generated/content-repo.h
@@ -32,6 +32,13 @@ namespace QMatrixClient
class GetContentJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetContentJob. This function can be used when
+ * a URL for GetContentJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId);
+
explicit GetContentJob(const QString& serverName, const QString& mediaId);
~GetContentJob() override;
@@ -50,6 +57,13 @@ namespace QMatrixClient
class GetContentOverrideNameJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetContentOverrideNameJob. This function can be used when
+ * a URL for GetContentOverrideNameJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, const QString& fileName);
+
explicit GetContentOverrideNameJob(const QString& serverName, const QString& mediaId, const QString& fileName);
~GetContentOverrideNameJob() override;
@@ -68,6 +82,13 @@ namespace QMatrixClient
class GetContentThumbnailJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetContentThumbnailJob. This function can be used when
+ * a URL for GetContentThumbnailJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, int width = {}, int height = {}, const QString& method = {});
+
explicit GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width = {}, int height = {}, const QString& method = {});
~GetContentThumbnailJob() override;
@@ -85,6 +106,13 @@ namespace QMatrixClient
class GetUrlPreviewJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetUrlPreviewJob. This function can be used when
+ * a URL for GetUrlPreviewJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& url, double ts = {});
+
explicit GetUrlPreviewJob(const QString& url, double ts = {});
~GetUrlPreviewJob() override;
diff --git a/jobs/generated/directory.cpp b/jobs/generated/directory.cpp
index 4e61ed74..9428dcee 100644
--- a/jobs/generated/directory.cpp
+++ b/jobs/generated/directory.cpp
@@ -29,6 +29,12 @@ class GetRoomIdByAliasJob::Private
QVector<QString> servers;
};
+QUrl GetRoomIdByAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/room/" % roomAlias);
+}
+
GetRoomIdByAliasJob::GetRoomIdByAliasJob(const QString& roomAlias)
: BaseJob(HttpVerb::Get, "GetRoomIdByAliasJob",
basePath % "/room/" % roomAlias, false)
@@ -56,6 +62,12 @@ BaseJob::Status GetRoomIdByAliasJob::parseJson(const QJsonDocument& data)
return Success;
}
+QUrl DeleteRoomAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/room/" % roomAlias);
+}
+
DeleteRoomAliasJob::DeleteRoomAliasJob(const QString& roomAlias)
: BaseJob(HttpVerb::Delete, "DeleteRoomAliasJob",
basePath % "/room/" % roomAlias)
diff --git a/jobs/generated/directory.h b/jobs/generated/directory.h
index eeda563b..87591240 100644
--- a/jobs/generated/directory.h
+++ b/jobs/generated/directory.h
@@ -22,6 +22,13 @@ namespace QMatrixClient
class GetRoomIdByAliasJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetRoomIdByAliasJob. This function can be used when
+ * a URL for GetRoomIdByAliasJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomAlias);
+
explicit GetRoomIdByAliasJob(const QString& roomAlias);
~GetRoomIdByAliasJob() override;
@@ -39,6 +46,13 @@ namespace QMatrixClient
class DeleteRoomAliasJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * DeleteRoomAliasJob. This function can be used when
+ * a URL for DeleteRoomAliasJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomAlias);
+
explicit DeleteRoomAliasJob(const QString& roomAlias);
};
} // namespace QMatrixClient
diff --git a/jobs/generated/leaving.cpp b/jobs/generated/leaving.cpp
index 89c110dd..fbc40d11 100644
--- a/jobs/generated/leaving.cpp
+++ b/jobs/generated/leaving.cpp
@@ -12,12 +12,24 @@ using namespace QMatrixClient;
static const auto basePath = QStringLiteral("/_matrix/client/r0");
+QUrl LeaveRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/rooms/" % roomId % "/leave");
+}
+
LeaveRoomJob::LeaveRoomJob(const QString& roomId)
: BaseJob(HttpVerb::Post, "LeaveRoomJob",
basePath % "/rooms/" % roomId % "/leave")
{
}
+QUrl ForgetRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/rooms/" % roomId % "/forget");
+}
+
ForgetRoomJob::ForgetRoomJob(const QString& roomId)
: BaseJob(HttpVerb::Post, "ForgetRoomJob",
basePath % "/rooms/" % roomId % "/forget")
diff --git a/jobs/generated/leaving.h b/jobs/generated/leaving.h
index cd39b612..9bae2363 100644
--- a/jobs/generated/leaving.h
+++ b/jobs/generated/leaving.h
@@ -15,12 +15,26 @@ namespace QMatrixClient
class LeaveRoomJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * LeaveRoomJob. This function can be used when
+ * a URL for LeaveRoomJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
+
explicit LeaveRoomJob(const QString& roomId);
};
class ForgetRoomJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * ForgetRoomJob. This function can be used when
+ * a URL for ForgetRoomJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
+
explicit ForgetRoomJob(const QString& roomId);
};
} // namespace QMatrixClient
diff --git a/jobs/generated/list_public_rooms.cpp b/jobs/generated/list_public_rooms.cpp
index a2c0e406..39653300 100644
--- a/jobs/generated/list_public_rooms.cpp
+++ b/jobs/generated/list_public_rooms.cpp
@@ -66,18 +66,31 @@ class GetPublicRoomsJob::Private
double totalRoomCountEstimate;
};
-GetPublicRoomsJob::GetPublicRoomsJob(double limit, const QString& since, const QString& server)
- : BaseJob(HttpVerb::Get, "GetPublicRoomsJob",
- basePath % "/publicRooms", false)
- , d(new Private)
+BaseJob::Query queryToGetPublicRooms(double limit, const QString& since, const QString& server)
{
- QUrlQuery _q;
+ BaseJob::Query _q;
_q.addQueryItem("limit", QString("%1").arg(limit));
if (!since.isEmpty())
_q.addQueryItem("since", since);
if (!server.isEmpty())
_q.addQueryItem("server", server);
- setRequestQuery(_q);
+ return _q;
+}
+
+QUrl GetPublicRoomsJob::makeRequestUrl(QUrl baseUrl, double limit, const QString& since, const QString& server)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/publicRooms",
+ queryToGetPublicRooms(limit, since, server));
+}
+
+GetPublicRoomsJob::GetPublicRoomsJob(double limit, const QString& since, const QString& server)
+ : BaseJob(HttpVerb::Get, "GetPublicRoomsJob",
+ basePath % "/publicRooms",
+ queryToGetPublicRooms(limit, since, server),
+ {}, false)
+ , d(new Private)
+{
}
GetPublicRoomsJob::~GetPublicRoomsJob() = default;
@@ -194,15 +207,20 @@ class QueryPublicRoomsJob::Private
double totalRoomCountEstimate;
};
+BaseJob::Query queryToQueryPublicRooms(const QString& server)
+{
+ BaseJob::Query _q;
+ if (!server.isEmpty())
+ _q.addQueryItem("server", server);
+ return _q;
+}
+
QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, double limit, const QString& since, const Filter& filter)
: BaseJob(HttpVerb::Post, "QueryPublicRoomsJob",
- basePath % "/publicRooms")
+ basePath % "/publicRooms",
+ queryToQueryPublicRooms(server))
, d(new Private)
{
- QUrlQuery _q;
- if (!server.isEmpty())
- _q.addQueryItem("server", server);
- setRequestQuery(_q);
QJsonObject _data;
_data.insert("limit", toJson(limit));
if (!since.isEmpty())
diff --git a/jobs/generated/list_public_rooms.h b/jobs/generated/list_public_rooms.h
index 7dcb8cf7..5c281de3 100644
--- a/jobs/generated/list_public_rooms.h
+++ b/jobs/generated/list_public_rooms.h
@@ -36,6 +36,13 @@ namespace QMatrixClient
// End of inner data structures
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetPublicRoomsJob. This function can be used when
+ * a URL for GetPublicRoomsJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, double limit = {}, const QString& since = {}, const QString& server = {});
+
explicit GetPublicRoomsJob(double limit = {}, const QString& since = {}, const QString& server = {});
~GetPublicRoomsJob() override;
diff --git a/jobs/generated/logout.cpp b/jobs/generated/logout.cpp
index f7f8eff9..83139842 100644
--- a/jobs/generated/logout.cpp
+++ b/jobs/generated/logout.cpp
@@ -12,6 +12,12 @@ using namespace QMatrixClient;
static const auto basePath = QStringLiteral("/_matrix/client/r0");
+QUrl LogoutJob::makeRequestUrl(QUrl baseUrl)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/logout");
+}
+
LogoutJob::LogoutJob()
: BaseJob(HttpVerb::Post, "LogoutJob",
basePath % "/logout")
diff --git a/jobs/generated/logout.h b/jobs/generated/logout.h
index d2b85db5..7640ba55 100644
--- a/jobs/generated/logout.h
+++ b/jobs/generated/logout.h
@@ -15,6 +15,13 @@ namespace QMatrixClient
class LogoutJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * LogoutJob. This function can be used when
+ * a URL for LogoutJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl);
+
explicit LogoutJob();
};
} // namespace QMatrixClient
diff --git a/jobs/generated/profile.cpp b/jobs/generated/profile.cpp
index 9523ca96..1f7092d7 100644
--- a/jobs/generated/profile.cpp
+++ b/jobs/generated/profile.cpp
@@ -28,6 +28,12 @@ class GetDisplayNameJob::Private
QString displayname;
};
+QUrl GetDisplayNameJob::makeRequestUrl(QUrl baseUrl, const QString& userId)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/profile/" % userId % "/displayname");
+}
+
GetDisplayNameJob::GetDisplayNameJob(const QString& userId)
: BaseJob(HttpVerb::Get, "GetDisplayNameJob",
basePath % "/profile/" % userId % "/displayname", false)
@@ -65,6 +71,12 @@ class GetAvatarUrlJob::Private
QString avatarUrl;
};
+QUrl GetAvatarUrlJob::makeRequestUrl(QUrl baseUrl, const QString& userId)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/profile/" % userId % "/avatar_url");
+}
+
GetAvatarUrlJob::GetAvatarUrlJob(const QString& userId)
: BaseJob(HttpVerb::Get, "GetAvatarUrlJob",
basePath % "/profile/" % userId % "/avatar_url", false)
@@ -93,6 +105,12 @@ class GetUserProfileJob::Private
QString displayname;
};
+QUrl GetUserProfileJob::makeRequestUrl(QUrl baseUrl, const QString& userId)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/profile/" % userId);
+}
+
GetUserProfileJob::GetUserProfileJob(const QString& userId)
: BaseJob(HttpVerb::Get, "GetUserProfileJob",
basePath % "/profile/" % userId, false)
diff --git a/jobs/generated/profile.h b/jobs/generated/profile.h
index 1e09791d..024130f5 100644
--- a/jobs/generated/profile.h
+++ b/jobs/generated/profile.h
@@ -21,6 +21,13 @@ namespace QMatrixClient
class GetDisplayNameJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetDisplayNameJob. This function can be used when
+ * a URL for GetDisplayNameJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId);
+
explicit GetDisplayNameJob(const QString& userId);
~GetDisplayNameJob() override;
@@ -43,6 +50,13 @@ namespace QMatrixClient
class GetAvatarUrlJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetAvatarUrlJob. This function can be used when
+ * a URL for GetAvatarUrlJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId);
+
explicit GetAvatarUrlJob(const QString& userId);
~GetAvatarUrlJob() override;
@@ -59,6 +73,13 @@ namespace QMatrixClient
class GetUserProfileJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetUserProfileJob. This function can be used when
+ * a URL for GetUserProfileJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId);
+
explicit GetUserProfileJob(const QString& userId);
~GetUserProfileJob() override;
diff --git a/jobs/generated/versions.cpp b/jobs/generated/versions.cpp
index 938c1d34..b12594ca 100644
--- a/jobs/generated/versions.cpp
+++ b/jobs/generated/versions.cpp
@@ -18,6 +18,12 @@ class GetVersionsJob::Private
QVector<QString> versions;
};
+QUrl GetVersionsJob::makeRequestUrl(QUrl baseUrl)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/versions");
+}
+
GetVersionsJob::GetVersionsJob()
: BaseJob(HttpVerb::Get, "GetVersionsJob",
basePath % "/versions", false)
diff --git a/jobs/generated/versions.h b/jobs/generated/versions.h
index 686d7069..18f6bb44 100644
--- a/jobs/generated/versions.h
+++ b/jobs/generated/versions.h
@@ -16,6 +16,13 @@ namespace QMatrixClient
class GetVersionsJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetVersionsJob. This function can be used when
+ * a URL for GetVersionsJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl);
+
explicit GetVersionsJob();
~GetVersionsJob() override;
diff --git a/jobs/generated/whoami.cpp b/jobs/generated/whoami.cpp
index 4f7b052c..cc38fa4d 100644
--- a/jobs/generated/whoami.cpp
+++ b/jobs/generated/whoami.cpp
@@ -18,6 +18,12 @@ class GetTokenOwnerJob::Private
QString userId;
};
+QUrl GetTokenOwnerJob::makeRequestUrl(QUrl baseUrl)
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath % "/account/whoami");
+}
+
GetTokenOwnerJob::GetTokenOwnerJob()
: BaseJob(HttpVerb::Get, "GetTokenOwnerJob",
basePath % "/account/whoami")
diff --git a/jobs/generated/whoami.h b/jobs/generated/whoami.h
index 8e1952da..835232ee 100644
--- a/jobs/generated/whoami.h
+++ b/jobs/generated/whoami.h
@@ -15,6 +15,13 @@ namespace QMatrixClient
class GetTokenOwnerJob : public BaseJob
{
public:
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * GetTokenOwnerJob. This function can be used when
+ * a URL for GetTokenOwnerJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl);
+
explicit GetTokenOwnerJob();
~GetTokenOwnerJob() override;
diff --git a/jobs/mediathumbnailjob.cpp b/jobs/mediathumbnailjob.cpp
index ec82f57b..261978ec 100644
--- a/jobs/mediathumbnailjob.cpp
+++ b/jobs/mediathumbnailjob.cpp
@@ -20,6 +20,13 @@
using namespace QMatrixClient;
+QUrl MediaThumbnailJob::makeRequestUrl(QUrl baseUrl,
+ const QUrl& mxcUri, QSize requestedSize)
+{
+ return makeRequestUrl(baseUrl, mxcUri.authority(), mxcUri.path().mid(1),
+ requestedSize.width(), requestedSize.height());
+}
+
MediaThumbnailJob::MediaThumbnailJob(const QString& serverName,
const QString& mediaId, QSize requestedSize)
: GetContentThumbnailJob(serverName, mediaId,
diff --git a/jobs/mediathumbnailjob.h b/jobs/mediathumbnailjob.h
index ef834cd7..6e0b94f3 100644
--- a/jobs/mediathumbnailjob.h
+++ b/jobs/mediathumbnailjob.h
@@ -27,6 +27,10 @@ namespace QMatrixClient
class MediaThumbnailJob: public GetContentThumbnailJob
{
public:
+ using GetContentThumbnailJob::makeRequestUrl;
+ static QUrl makeRequestUrl(QUrl baseUrl,
+ const QUrl& mxcUri, QSize requestedSize);
+
MediaThumbnailJob(const QString& serverName, const QString& mediaId,
QSize requestedSize);
MediaThumbnailJob(const QUrl& mxcUri, QSize requestedSize);
diff --git a/room.cpp b/room.cpp
index 51da747e..73591c98 100644
--- a/room.cpp
+++ b/room.cpp
@@ -33,6 +33,7 @@
#include "events/redactionevent.h"
#include "jobs/sendeventjob.h"
#include "jobs/roommessagesjob.h"
+#include "jobs/mediathumbnailjob.h"
#include "jobs/downloadfilejob.h"
#include "avatar.h"
#include "connection.h"
@@ -137,6 +138,8 @@ class Room::Private
// used for both download and upload operations
QHash<QString, FileTransferPrivateInfo> fileTransfers;
+ const RoomMessageEvent* getEventWithFile(const QString& eventId) const;
+
// Convenience methods to work with the membersMap and usersLeft.
// addMember() and removeMember() emit respective Room:: signals
// after a succesful operation.
@@ -546,22 +549,57 @@ void Room::resetHighlightCount()
emit highlightCountChanged(this);
}
-QString Room::fileNameToDownload(const QString& eventId)
+const RoomMessageEvent*
+Room::Private::getEventWithFile(const QString& eventId) const
{
- auto evtIt = findInTimeline(eventId);
- if (evtIt != timelineEdge() &&
+ auto evtIt = q->findInTimeline(eventId);
+ if (evtIt != timeline.rend() &&
evtIt->event()->type() == EventType::RoomMessage)
{
auto* event = static_cast<const RoomMessageEvent*>(evtIt->event());
if (event->hasFileContent())
+ return event;
+ }
+ qWarning() << "No files to download in event" << eventId;
+ return nullptr;
+}
+
+QUrl Room::urlToThumbnail(const QString& eventId)
+{
+ if (auto* event = d->getEventWithFile(eventId))
+ if (event->hasThumbnail())
{
- auto* fileInfo = event->content()->fileInfo();
- return !fileInfo->originalName.isEmpty() ? fileInfo->originalName :
- !event->plainBody().isEmpty() ? event->plainBody() :
- QString();
+ auto* thumbnail = event->content()->thumbnailInfo();
+ Q_ASSERT(thumbnail != nullptr);
+ return MediaThumbnailJob::makeRequestUrl(connection()->homeserver(),
+ thumbnail->url, thumbnail->imageSize);
}
+ qDebug() << "Event" << eventId << "has no thumbnail";
+ return {};
+}
+
+QUrl Room::urlToDownload(const QString& eventId)
+{
+ if (auto* event = d->getEventWithFile(eventId))
+ {
+ auto* fileInfo = event->content()->fileInfo();
+ Q_ASSERT(fileInfo != nullptr);
+ return DownloadFileJob::makeRequestUrl(connection()->homeserver(),
+ fileInfo->url);
+ }
+ return {};
+}
+
+QString Room::fileNameToDownload(const QString& eventId)
+{
+ if (auto* event = d->getEventWithFile(eventId))
+ {
+ auto* fileInfo = event->content()->fileInfo();
+ Q_ASSERT(fileInfo != nullptr);
+ return !fileInfo->originalName.isEmpty() ? fileInfo->originalName :
+ !event->plainBody().isEmpty() ? event->plainBody() :
+ QString();
}
- qWarning() << "No files to download in event" << eventId;
return {};
}
diff --git a/room.h b/room.h
index a8d58f83..a0dad8b3 100644
--- a/room.h
+++ b/room.h
@@ -215,6 +215,8 @@ namespace QMatrixClient
Q_INVOKABLE int highlightCount() const;
Q_INVOKABLE void resetHighlightCount();
+ Q_INVOKABLE QUrl urlToThumbnail(const QString& eventId);
+ Q_INVOKABLE QUrl urlToDownload(const QString& eventId);
Q_INVOKABLE QString fileNameToDownload(const QString& eventId);
Q_INVOKABLE FileTransferInfo fileTransferInfo(const QString& id) const;