Skip to content
Snippets Groups Projects
Commit feeba11e authored by kamathmanu's avatar kamathmanu
Browse files

Run make lint

parent 0768a6e8
No related branches found
No related tags found
No related merge requests found
Pipeline #326 passed
......@@ -11,7 +11,8 @@
#include <vector>
/// @file
/// @brief Common types used by the crypto related endpoints. Common types used by room directory endpoints.
/// @brief Common types used by the crypto related endpoints. Common types used by room directory
/// endpoints.
namespace mtx {
namespace crypto {
......@@ -120,9 +121,9 @@ to_json(nlohmann::json &obj, const EncryptedFile &res);
} // namespace crypto
//
//
namespace common {
//! Whether or not the room will be visible by non members.
//! Whether or not the room will be visible by non members.
enum class RoomVisibility
{
//! A private visibility will hide the room from the published room list.
......@@ -131,8 +132,8 @@ enum class RoomVisibility
Public,
};
inline
std::string visibilityToString(RoomVisibility visibility)
inline std::string
visibilityToString(RoomVisibility visibility)
{
if (visibility == RoomVisibility::Private) {
return "private";
......@@ -141,12 +142,13 @@ std::string visibilityToString(RoomVisibility visibility)
return "public";
}
inline
RoomVisibility stringToVisibility(const std::string &s) {
if (s == "private") {
return RoomVisibility::Private;
}
return RoomVisibility::Public;
inline RoomVisibility
stringToVisibility(const std::string &s)
{
if (s == "private") {
return RoomVisibility::Private;
}
return RoomVisibility::Public;
}
} // namespace common
} // namespace mtx
......@@ -14,7 +14,7 @@
#include <nlohmann/json.hpp>
#endif
using json = nlohmann::json;
using json = nlohmann::json;
namespace common = mtx::common;
namespace mtx {
......@@ -135,7 +135,8 @@ to_json(json &obj, const TypingNotification &request);
//! Request payload for the `PUT /_matrix/client/r0/directory/list/room/{roomId}` endpoint
struct PublicRoomVisibility
{
//! The new visibility setting for the room. Defaults to 'public'. One of: ["private", "public"]
//! The new visibility setting for the room. Defaults to 'public'. One of: ["private",
//! "public"]
common::RoomVisibility visibility;
};
......
......@@ -17,9 +17,10 @@ namespace common = mtx::common;
namespace mtx {
namespace responses {
//! Response from the `GET /_matrix/client/r0/directory/list/room/{roomId}`endpoint.
struct PublicRoomVisibility {
//! The visibility of the room in the directory. One of: ["private", "public"]
common::RoomVisibility visibility;
struct PublicRoomVisibility
{
//! The visibility of the room in the directory. One of: ["private", "public"]
common::RoomVisibility visibility;
};
void
......
......@@ -963,13 +963,15 @@ Client::send_to_device(const std::string &event_type,
}
void
Client::get_room_visibility(const std::string &room_id, Callback<mtx::responses::PublicRoomVisibility> cb)
Client::get_room_visibility(const std::string &room_id,
Callback<mtx::responses::PublicRoomVisibility> cb)
{
const auto api_path =
"/client/r0/directory/list/room/" + mtx::client::utils::url_encode(room_id);
get<mtx::responses::PublicRoomVisibility>(
api_path, [cb](const mtx::responses::PublicRoomVisibility &res, HeaderFields, RequestErr err) {
api_path,
[cb](const mtx::responses::PublicRoomVisibility &res, HeaderFields, RequestErr err) {
cb(res, err);
});
}
......
#include <nlohmann/json.hpp>
#include "mtx/common.hpp"
#include "mtx/identifiers.hpp"
#include "mtx/responses/public_rooms.hpp"
#include "mtx/common.hpp"
namespace mtx {
namespace responses {
......
......@@ -1630,10 +1630,11 @@ TEST(ClientAPI, PublicRooms)
alice->get_room_visibility(
room_id.to_string(),
[alice, bob, room_id](
const mtx::responses::PublicRoomVisibility &res, RequestErr err) {
[alice, bob, room_id](const mtx::responses::PublicRoomVisibility &res,
RequestErr err) {
check_error(err);
EXPECT_EQ(mtx::common::visibilityToString(res.visibility), "public");
EXPECT_EQ(mtx::common::visibilityToString(res.visibility),
"public");
// TEST 2: endpoints to add and list the public rooms on the
// server
......@@ -1653,37 +1654,59 @@ TEST(ClientAPI, PublicRooms)
RequestErr err) {
check_error(err);
std::cout << "GETting the listing pt 1\n";
EXPECT_EQ(res.chunk[0].name,
"Public Room");
EXPECT_EQ(res.chunk[0].topic,
"Test");
EXPECT_EQ(res.chunk[0].num_joined_members,
1);
// Have bob join the room and verify there are 2 members
std::atomic<bool> joined = false;
bob->join_room(room_id.to_string(), [alice, bob, room_id, &joined](const mtx::responses::RoomId &, RequestErr err){
check_error(err);
std::cout << "bob joined the room\n";
joined = true;
});
while (!joined)
sleep();
alice->get_public_rooms(
[alice, bob, room_id](
const mtx::responses::PublicRooms &res, RequestErr err) {
check_error(err);
std::cout << "testing for joined members\n";
EXPECT_EQ(res.chunk[0].num_joined_members, 2);
// Teardown: remove the room from the room directory (maintain future tests)
mtx::requests::PublicRoomVisibility r;
r.visibility = mtx::common::RoomVisibility::Private;
alice->put_room_visibility(
room_id.to_string(), r, [alice, bob, room_id](RequestErr err) {
check_error(err);
std::cout << "removed from room directory\n";
});
}, "localhost", 1);
EXPECT_EQ(res.chunk[0].name,
"Public Room");
EXPECT_EQ(res.chunk[0].topic, "Test");
EXPECT_EQ(res.chunk[0].num_joined_members,
1);
// Have bob join the room and verify there
// are 2 members
std::atomic<bool> joined = false;
bob->join_room(
room_id.to_string(),
[alice, bob, room_id, &joined](
const mtx::responses::RoomId &,
RequestErr err) {
check_error(err);
std::cout
<< "bob joined the room\n";
joined = true;
});
while (!joined)
sleep();
alice->get_public_rooms(
[alice, bob, room_id](
const mtx::responses::PublicRooms
&res,
RequestErr err) {
check_error(err);
std::cout << "testing for "
"joined members\n";
EXPECT_EQ(res.chunk[0]
.num_joined_members,
2);
// Teardown: remove the room
// from the room directory
// (maintain future tests)
mtx::requests::
PublicRoomVisibility r;
r.visibility = mtx::common::
RoomVisibility::Private;
alice->put_room_visibility(
room_id.to_string(),
r,
[alice, bob, room_id](
RequestErr err) {
check_error(err);
std::cout
<< "removed from "
"room "
"directory\n";
});
},
"localhost",
1);
},
"localhost",
1);
......
......@@ -1107,7 +1107,7 @@ TEST(Responses, TurnServer)
TEST(Responses, PublicRoomVisibility)
{
json data = {{"visibility", "public"}};
json data = {{"visibility", "public"}};
mtx::responses::PublicRoomVisibility roomVisibility = data;
EXPECT_EQ(roomVisibility.visibility, mtx::common::RoomVisibility::Public);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment