From 71f80c5fa672f90ef9efa83602a76637a4114f00 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris <sideris.konstantin@gmail.com> Date: Tue, 5 Jun 2018 22:08:51 +0300 Subject: [PATCH] Add the redact_event method --- include/mtxclient/http/client.hpp | 5 +++++ lib/http/client.cpp | 12 +++++++++++ tests/client_api.cpp | 36 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/include/mtxclient/http/client.hpp b/include/mtxclient/http/client.hpp index 57e49b420..eed8f2416 100644 --- a/include/mtxclient/http/client.hpp +++ b/include/mtxclient/http/client.hpp @@ -166,6 +166,11 @@ public: //! Mark an event as read. void read_event(const std::string &room_id, const std::string &event_id, ErrCallback cb); + //! Redact an event from a room. + void redact_event(const std::string &room_id, + const std::string &event_id, + Callback<mtx::responses::EventId> cb); + //! Upload a filter void upload_filter(const nlohmann::json &j, Callback<mtx::responses::FilterId> cb); diff --git a/lib/http/client.cpp b/lib/http/client.cpp index e218ef0e9..c5e72d14d 100644 --- a/lib/http/client.cpp +++ b/lib/http/client.cpp @@ -333,6 +333,18 @@ Client::read_event(const std::string &room_id, const std::string &event_id, ErrC }); } +void +Client::redact_event(const std::string &room_id, + const std::string &event_id, + Callback<mtx::responses::EventId> callback) +{ + const auto api_path = "/client/r0/rooms/" + room_id + "/redact/" + event_id + "/" + + mtx::client::utils::random_token(); + + json body = json::object(); + put<nlohmann::json, mtx::responses::EventId>(api_path, body, callback); +} + void Client::registration(const std::string &user, const std::string &pass, diff --git a/tests/client_api.cpp b/tests/client_api.cpp index 907aadfa6..df23622a6 100644 --- a/tests/client_api.cpp +++ b/tests/client_api.cpp @@ -751,6 +751,42 @@ TEST(ClientAPI, SendMessages) bob->close(); } +TEST(ClientAPI, RedactEvent) +{ + auto alice = std::make_shared<Client>("localhost"); + alice->login("alice", "secret", check_login); + + while (alice->access_token().empty()) + sleep(); + + mtx::requests::CreateRoom req; + alice->create_room(req, [alice](const mtx::responses::CreateRoom &res, RequestErr err) { + check_error(err); + auto room_id = res.room_id.to_string(); + + mtx::events::msg::Text text; + text.body = "hello alice!"; + + alice + ->send_room_message<mtx::events::msg::Text, mtx::events::EventType::RoomMessage>( + room_id, + text, + [room_id, alice](const mtx::responses::EventId &res, RequestErr err) { + check_error(err); + + alice->redact_event( + room_id, + res.event_id.to_string(), + [](const mtx::responses::EventId &res, RequestErr err) { + check_error(err); + ASSERT_FALSE(res.event_id.to_string().empty()); + }); + }); + }); + + alice->close(); +} + TEST(ClientAPI, SendStateEvents) { auto alice = std::make_shared<Client>("localhost"); -- GitLab