diff options
author | kukin-konstantin <kukin.konstantin@gmail.com> | 2016-12-30 16:01:00 +0300 |
---|---|---|
committer | kukin-konstantin <kukin.konstantin@gmail.com> | 2016-12-30 16:01:00 +0300 |
commit | 156bac1c6b2d8ce28f1a13b11bca3e8da285aa3d (patch) | |
tree | 054e845990df8a60c68b8f4940932a2d5d5079e7 /src | |
parent | 728e758eee9b22328abc6e75f6cef7e7197be0f0 (diff) |
Add Chat functions
Diffstat (limited to 'src')
-rw-r--r-- | src/Api.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index 451a8c0..4b08f98 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -410,7 +410,36 @@ UserProfilePhotos::Ptr Api::getUserProfilePhotos(int32_t userId, int32_t offset, return TgTypeParser::getInstance().parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); } -vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeout) const { +Chat::Ptr Api::getChat(int32_t chatId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + return TgTypeParser::getInstance().parseJsonAndGetChat(sendRequest("getChat", args)); +} + +std::vector<ChatMember::Ptr> Api::getChatAdministrators(int32_t chatId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + return TgTypeParser::getInstance().parseJsonAndGetArray<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); +} + +int32_t Api::getChatMembersCount(int32_t chatId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + return sendRequest("getChatMembersCount", args).get<int32_t>("", 0); +} + +ChatMember::Ptr Api::getChatMember(int32_t chatId, int32_t userId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + return TgTypeParser::getInstance().parseJsonAndGetChatMember(sendRequest("getChatMember", args)); +} + +vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeout, const StringArrayPtr &allowedUpdates) const { vector<HttpReqArg> args; if (offset) { args.push_back(HttpReqArg("offset", offset)); @@ -420,6 +449,13 @@ vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo if (timeout) { args.push_back(HttpReqArg("timeout", timeout)); } + if (allowedUpdates!=nullptr) { + string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<std::string>( + [](const std::string &s)->std::string { + return s; + }, *allowedUpdates); + args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson)); + } return TgTypeParser::getInstance().parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); } |