Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2576132
D216.1750611385.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D216.1750611385.diff
View Options
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
--- a/src/client/CMakeLists.txt
+++ b/src/client/CMakeLists.txt
@@ -24,6 +24,8 @@
push-rules-desc.cpp
notification-handler.cpp
power-levels-desc.cpp
+
+ get-content-job-v1.cpp
)
add_library(kazvclient ${kazvclient_SRCS})
diff --git a/src/client/actions/auth.cpp b/src/client/actions/auth.cpp
--- a/src/client/actions/auth.cpp
+++ b/src/client/actions/auth.cpp
@@ -158,6 +158,7 @@
ClientResult processResponse(ClientModel m, GetVersionsResponse r)
{
+ m.versions = r.versions();
return {
std::move(m),
[r](auto &&ctx) {
diff --git a/src/client/client-model.hpp b/src/client/client-model.hpp
--- a/src/client/client-model.hpp
+++ b/src/client/client-model.hpp
@@ -88,6 +88,8 @@
DeviceListTracker deviceLists;
DeviceTrustLevel trustLevelNeededToSendKeys{DeviceTrustLevel::Unseen};
+ immer::array<std::string /* version */> versions;
+
immer::flex_vector<std::string /* deviceId */> devicesToSendKeys(std::string userId) const;
/// rotate sessions for a room if there is a user in the room with
diff --git a/src/client/client.hpp b/src/client/client.hpp
--- a/src/client/client.hpp
+++ b/src/client/client.hpp
@@ -17,6 +17,7 @@
#include "client/client-model.hpp"
#include "client/actions/content.hpp"
#include "sdk-model-cursor-tag.hpp"
+#include "get-content-job-v1.hpp"
#include "room/room.hpp"
#include "notification-handler.hpp"
@@ -372,6 +373,24 @@
.make(serverName, mediaId).url();
}
+ /**
+ * Convert a MXC URI to an HTTP(s) URI that needs Authorization.
+ *
+ * The converted URI will be using the homeserver of
+ * this Client.
+ *
+ * @param mxcUri The MXC URI to convert.
+ * @return The HTTP(s) URI that has the content indicated
+ * by `mxcUri`.
+ */
+ inline std::string mxcUriToHttpV1(std::string mxcUri) const {
+ using namespace CursorOp;
+ auto [serverName, mediaId] = mxcUriToMediaDesc(mxcUri);
+ return (+clientCursor())
+ .template job<GetContentJobV1>()
+ .make(serverName, mediaId).url();
+ }
+
/**
* Download content from the content repository
*
@@ -553,6 +572,24 @@
ar << sdkCursor().get();
}
+ /**
+ * Get all supported versions.
+ *
+ * @param homeserver The base url of the homeserver. E.g. `https://tusooa.xyz`.
+ * @return A Promise that resolves when the versions has been set,
+ * or when there is an error.
+ */
+ PromiseT getVersions(std::string homeserver) const;
+
+ /**
+ * Check whether the specified version is supported.
+ *
+ * @param version A version string.
+ *
+ * See https://spec.matrix.org/v1.14/#specification-versions
+ */
+ bool supportVersion(std::string version) const;
+
private:
void syncForever(std::optional<int> retryTime = std::nullopt) const;
diff --git a/src/client/client.cpp b/src/client/client.cpp
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -449,4 +449,15 @@
{
return NotificationHandler(clientCursor());
}
+
+ auto Client::getVersions(std::string homeserver) const -> PromiseT
+ {
+ return m_ctx.dispatch(GetVersionsAction{homeserver});
+ }
+
+ bool Client::supportVersion(std::string version) const
+ {
+ auto versions = clientCursor().get().versions;
+ return std::find(versions.begin(), versions.end(), version) != versions.end();
+ }
}
diff --git a/src/client/get-content-job-v1.hpp b/src/client/get-content-job-v1.hpp
new file mode 100644
--- /dev/null
+++ b/src/client/get-content-job-v1.hpp
@@ -0,0 +1,28 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2025 nannanko <nannanko@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include "basejob.hpp"
+#include "file-desc.hpp"
+
+#include <string>
+#include <optional>
+
+namespace Kazv {
+ class GetContentJobV1 : public Kazv::BaseJob
+ {
+ public:
+ explicit GetContentJobV1(std::string serverUrl, std::string token,
+ std::string serverName, std::string mediaId,
+ bool allowRemote = true,
+ std::optional<FileDesc> downloadTo = std::nullopt);
+
+ static BaseJob::Query buildQuery(bool allowRemote);
+ static constexpr auto needsAuth()
+ {
+ return true;
+ }
+ };
+}
diff --git a/src/client/get-content-job-v1.cpp b/src/client/get-content-job-v1.cpp
new file mode 100644
--- /dev/null
+++ b/src/client/get-content-job-v1.cpp
@@ -0,0 +1,32 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2025 nannanko <nannanko@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include "get-content-job-v1.hpp"
+#include "basejob.hpp"
+
+#include <string>
+#include <utility>
+
+using namespace std::literals::string_literals;
+
+namespace Kazv
+{
+ GetContentJobV1::GetContentJobV1(std::string serverUrl, std::string token,
+ std::string serverName, std::string mediaId, bool allowRemote,
+ std::optional<FileDesc> downloadTo)
+ : BaseJob(std::move(serverUrl),
+ "/_matrix/client/v1/media/download/"s + serverName + "/" + mediaId,
+ GET, "GetContent"s, token, ReturnType::File, BaseJob::EmptyBody{},
+ buildQuery(allowRemote), {}, downloadTo)
+ {}
+
+ BaseJob::Query GetContentJobV1::buildQuery(bool allowRemote)
+ {
+ BaseJob::Query query;
+ addToQueryIfNeeded(query, "allow_remotes"s, allowRemote);
+ return query;
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jun 22, 9:56 AM (8 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
233162
Default Alt Text
D216.1750611385.diff (5 KB)
Attached To
Mode
D216: Add GetContentJobV1 for the new download endpoint that needs authorization
Attached
Detach File
Event Timeline
Log In to Comment