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

Implement endpoints for typing notifications

parent 3f82edb5
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 0659554443a98bd018691337c8cfc11bfe909007
GIT_TAG 42c2279914fd6806d74e8490e692a3b4c4a975c0
BUILD_IN_SOURCE 1
SOURCE_DIR ${MATRIX_STRUCTS_ROOT}
......
......@@ -389,3 +389,30 @@ Client::download(const std::string &server,
callback(res, content_type, original_filename, err);
});
}
void
Client::start_typing(const mtx::identifiers::Room &room_id,
uint64_t timeout,
std::function<void(RequestErr)> callback)
{
const auto api_path =
"/client/r0/rooms/" + room_id.toString() + "/typing/" + user_id_.toString();
mtx::requests::TypingNotification req;
req.typing = true;
req.timeout = timeout;
put<mtx::requests::TypingNotification>(api_path, req, callback);
}
void
Client::stop_typing(const mtx::identifiers::Room &room_id, std::function<void(RequestErr)> callback)
{
const auto api_path =
"/client/r0/rooms/" + room_id.toString() + "/typing/" + user_id_.toString();
mtx::requests::TypingNotification req;
req.typing = false;
put<mtx::requests::TypingNotification>(api_path, req, callback);
}
......@@ -97,6 +97,13 @@ public:
const std::string &content_type,
const std::string &original_filename,
RequestErr err)> cb);
//! Send typing notifications to the room.
void start_typing(const mtx::identifiers::Room &room_id,
uint64_t timeout,
std::function<void(RequestErr err)> cb);
//! Remove typing notifications from the room.
void stop_typing(const mtx::identifiers::Room &room_id,
std::function<void(RequestErr err)> cb);
/* void download_room_avatar(); */
/* void download_user_avatar(); */
/* void download_media(); */
......
#include <atomic>
#include <chrono>
#include <iostream>
#include <thread>
......@@ -517,3 +518,62 @@ TEST(ClientAPI, Versions)
mtx_client->close();
}
TEST(ClientAPI, Typing)
{
auto alice = std::make_shared<Client>("localhost");
alice->login(
"alice", "secret", [](const mtx::responses::Login &, ErrType err) { ASSERT_FALSE(err); });
while (alice->access_token().empty())
std::this_thread::sleep_for(std::chrono::milliseconds(100));
mtx::requests::CreateRoom req;
alice->create_room(req, [alice](const mtx::responses::CreateRoom &res, ErrType err) {
ASSERT_FALSE(err);
alice->start_typing(res.room_id, 10000, [alice, res](ErrType err) {
ASSERT_FALSE(err);
const auto room_id = res.room_id.toString();
atomic_bool can_continue = false;
alice->sync(
"",
"",
false,
0,
[room_id, &can_continue](const mtx::responses::Sync &res, ErrType err) {
ASSERT_FALSE(err);
can_continue = true;
auto room = res.rooms.join.at(room_id);
EXPECT_EQ(room.ephemeral.typing.size(), 1);
EXPECT_EQ(room.ephemeral.typing.front(), "@alice:localhost");
});
while (!can_continue)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
alice->stop_typing(res.room_id, [alice, room_id](ErrType err) {
ASSERT_FALSE(err);
alice->sync(
"",
"",
false,
0,
[room_id](const mtx::responses::Sync &res, ErrType err) {
ASSERT_FALSE(err);
auto room = res.rooms.join.at(room_id);
EXPECT_EQ(room.ephemeral.typing.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