From cfba58ccdd651668d84073bf1f5895da3b4c3d42 Mon Sep 17 00:00:00 2001
From: kamathmanu <manuriddle@gmail.com>
Date: Fri, 11 Dec 2020 14:24:25 -0500
Subject: [PATCH] Client API for viewing public room directory

---
 include/mtxclient/http/client.hpp |  8 ++++++++
 lib/http/client.cpp               | 19 +++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/mtxclient/http/client.hpp b/include/mtxclient/http/client.hpp
index b82e7c0df..7b960e43d 100644
--- a/include/mtxclient/http/client.hpp
+++ b/include/mtxclient/http/client.hpp
@@ -43,6 +43,7 @@ struct Login;
 struct QueryKeys;
 struct ClaimKeys;
 struct UploadKeys;
+struct PublicRooms;
 }
 namespace responses {
 struct AvatarUrl;
@@ -69,6 +70,7 @@ struct TurnServer;
 struct UploadKeys;
 struct Versions;
 struct WellKnown;
+struct PublicRooms;
 namespace backup {
 struct SessionBackup;
 struct RoomKeysBackup;
@@ -446,6 +448,12 @@ public:
           const std::map<mtx::identifiers::User, std::map<std::string, EventContent>> &messages,
           ErrCallback callback);
 
+        //! POST a new room listing to the public rooms directory.
+        void post_public_rooms(const std::string &server, const nhlomann::json &j, 
+                                Callback<mtx::responses::PublicRooms> cb); 
+        //! GET the public rooms directory listing.
+        void get_public_rooms(int limit, const std::string &since, const std::string &server,
+                                Callback<mtx::responses::PublicRooms> cb);
         //
         // Group related endpoints.
         //
diff --git a/lib/http/client.cpp b/lib/http/client.cpp
index d3f29975a..0ead74939 100644
--- a/lib/http/client.cpp
+++ b/lib/http/client.cpp
@@ -962,6 +962,25 @@ Client::send_to_device(const std::string &event_type,
         put<nlohmann::json>(api_path, body, callback);
 }
 
+void
+Client::post_public_rooms(const std::string &server, const nhlomann::json &j, 
+                                Callback<mtx::responses::PublicRooms> cb)
+{
+        const auto api_path = "/client/r0/publicRooms" + " " + server;
+        post<mtx::requests::PublicRooms, mtx::responses::PublicRooms>(
+        api_path, j, cb);    
+}
+
+void
+Client::get_public_rooms(int limit, const std::string &since, const std::string &server,
+                                Callback<mtx::responses::PublicRooms> cb) 
+{
+        const auto api_path = 
+        "/client/r0/publicRooms" + " " + std::to_string(limit) + " " + since + " " + server;
+        get<mtx::requests::PublicRooms, mtx::responses::PublicRooms>(api_path, cb);
+}
+
+
 //
 // Group related endpoints.
 //
-- 
GitLab