From b99305ca826cc06c4a6e1e58a99f50f72cf107ac Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sat, 26 Oct 2019 18:25:02 +0200 Subject: [PATCH] add sending typing notifs --- include/matrixclient.h | 1 + source/matrixclient.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/matrixclient.h b/include/matrixclient.h index e690738..db93dec 100644 --- a/include/matrixclient.h +++ b/include/matrixclient.h @@ -84,6 +84,7 @@ public: std::string getRoomAvatar(std::string roomId); std::string getCanonicalAlias(std::string roomId); void sendReadReceipt(std::string roomId, std::string eventId); + void setTyping(std::string roomId, bool typing, u32 timeout = 30000); std::string sendEmote(std::string roomId, std::string text); std::string sendNotice(std::string roomId, std::string text); std::string sendText(std::string roomId, std::string text); diff --git a/source/matrixclient.cpp b/source/matrixclient.cpp index fcdb22d..799c3f5 100644 --- a/source/matrixclient.cpp +++ b/source/matrixclient.cpp @@ -281,6 +281,7 @@ std::string Client::getCanonicalAlias(std::string roomId) { } void Client::sendReadReceipt(std::string roomId, std::string eventId) { + roomId = resolveRoom(roomId); std::string path = "/_matrix/client/r0/rooms/" + urlencode(roomId) + "/receipt/m.read/" + urlencode(eventId); json_t* ret = doRequest("POST", path); if (ret) { @@ -288,6 +289,18 @@ void Client::sendReadReceipt(std::string roomId, std::string eventId) { } } +void Client::setTyping(std::string roomId, bool typing, u32 timeout) { + roomId = resolveRoom(roomId); + std::string userId = getUserId(); + std::string path = "/_matrix/client/r0/rooms/" + urlencode(roomId) + "/typing/" + urlencode(userId); + json_t* request = json_object(); + json_object_set_new(request, "typing", json_boolean(typing)); + json_object_set_new(request, "timeout", json_integer(timeout)); + json_t* ret = doRequest("PUT", path, request); + json_decref(request); + json_decref(ret); +} + std::string Client::sendEmote(std::string roomId, std::string text) { json_t* request = json_object(); json_object_set_new(request, "msgtype", json_string("m.emote"));