From 98d9b6856061e6c1951b03ca6b197d581e357189 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 26 Sep 2020 22:21:55 +0200 Subject: matrix: send start/stop typing --- src/plugins/Matrix.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index a38c063..71e451d 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -993,4 +993,49 @@ namespace QuickMedia { this->homeserver = "https://" + homeserver; return PluginResult::OK; } + + PluginResult Matrix::on_start_typing(const std::string &room_id) { + Json::Value request_data(Json::objectValue); + request_data["typing"] = true; + request_data["timeout"] = 30000; // 30 sec timeout + + Json::StreamWriterBuilder builder; + builder["commentStyle"] = "None"; + builder["indentation"] = ""; + + std::vector additional_args = { + { "-X", "PUT" }, + { "-H", "content-type: application/json" }, + { "--data-binary", Json::writeString(builder, std::move(request_data)) }, + { "-H", "Authorization: Bearer " + access_token } + }; + + std::string server_response; + if(download_to_string(homeserver + "/_matrix/client/r0/rooms/" + room_id + "/typing/" + url_param_encode(user_id) , server_response, std::move(additional_args), use_tor, true) != DownloadResult::OK) + return PluginResult::NET_ERR; + + return PluginResult::OK; + } + + PluginResult Matrix::on_stop_typing(const std::string &room_id) { + Json::Value request_data(Json::objectValue); + request_data["typing"] = false; + + Json::StreamWriterBuilder builder; + builder["commentStyle"] = "None"; + builder["indentation"] = ""; + + std::vector additional_args = { + { "-X", "PUT" }, + { "-H", "content-type: application/json" }, + { "--data-binary", Json::writeString(builder, std::move(request_data)) }, + { "-H", "Authorization: Bearer " + access_token } + }; + + std::string server_response; + if(download_to_string(homeserver + "/_matrix/client/r0/rooms/" + room_id + "/typing/" + url_param_encode(user_id), server_response, std::move(additional_args), use_tor, true) != DownloadResult::OK) + return PluginResult::NET_ERR; + + return PluginResult::OK; + } } \ No newline at end of file -- cgit v1.2.3