Skip to content
Snippets Groups Projects
Commit 6ec38454 authored by Konstantinos Sideris's avatar Konstantinos Sideris
Browse files

Add endpoint to upload filters

fixes #14
parent 0b28322a
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ ExternalProject_Add(
MatrixStructs
GIT_REPOSITORY https://github.com/mujx/matrix-structs
GIT_TAG baf455a6fee01be8235815c60e1231a8183ef1a3
GIT_TAG 4debe73fc653664e54667dba98aeac80939e3432
BUILD_IN_SOURCE 1
SOURCE_DIR ${MATRIX_STRUCTS_ROOT}
......
......@@ -485,3 +485,12 @@ Client::messages(const mtx::identifiers::Room &room_id,
callback(res, err);
});
}
void
Client::upload_filter(const nlohmann::json &j,
std::function<void(const mtx::responses::FilterId, RequestErr err)> callback)
{
const auto api_path = "/client/r0/user/" + user_id_.toString() + "/filter";
post<nlohmann::json, mtx::responses::FilterId>(api_path, j, callback);
}
......@@ -117,6 +117,10 @@ public:
//! Get the supported versions from the server.
void versions(std::function<void(const mtx::responses::Versions &res, RequestErr err)>);
//! Upload a filter
void upload_filter(const nlohmann::json &j,
std::function<void(const mtx::responses::FilterId, RequestErr err)>);
//! Upload data to the content repository.
void upload(const std::string &data,
const std::string &content_type,
......@@ -369,7 +373,6 @@ mtx::client::Client::create_session(
this](RequestID,
const boost::beast::http::response<boost::beast::http::string_body> &response,
const boost::system::error_code &err_code) {
ios_.post([callback, response, err_code]() {
Response response_data;
mtx::client::errors::ClientError client_error;
......
......@@ -143,7 +143,6 @@ TEST(ClientAPI, EmptyUserAvatar)
ASSERT_TRUE(res.avatar_url.size() == 0);
});
});
});
alice->close();
......@@ -184,7 +183,6 @@ TEST(ClientAPI, RealUserAvatar)
ASSERT_TRUE(res.avatar_url == avatar_url);
});
});
});
alice->close();
......@@ -285,7 +283,6 @@ TEST(ClientAPI, LogoutSuccess)
ASSERT_TRUE(err);
EXPECT_EQ(mtx::errors::to_string(err->matrix_error.errcode), "M_MISSING_TOKEN");
EXPECT_EQ(err->status_code, boost::beast::http::status::forbidden);
});
mtx_client->close();
......@@ -538,7 +535,6 @@ TEST(ClientAPI, InvalidInvite)
EXPECT_EQ(
mtx::errors::to_string(err->matrix_error.errcode),
"M_FORBIDDEN");
});
});
......@@ -858,3 +854,27 @@ TEST(ClientAPI, Pagination)
alice->close();
}
TEST(ClientAPI, UploadFilter)
{
auto alice = std::make_shared<Client>("localhost");
alice->login("alice", "secret", [alice](const mtx::responses::Login &, ErrType err) {
check_error(err);
});
while (alice->access_token().empty())
std::this_thread::sleep_for(std::chrono::milliseconds(100));
nlohmann::json j = {
{"room", {{"include_leave", true}, {"account_data", {{"not_types", {"*"}}}}}},
{"account_data", {{"not_types", {"*"}}}},
{"presence", {{"not_types", {"*"}}}}};
alice->upload_filter(j, [](const mtx::responses::FilterId &res, ErrType err) {
check_error(err);
ASSERT_TRUE(res.filter_id.size() > 0);
});
alice->close();
}
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