From 156bac1c6b2d8ce28f1a13b11bca3e8da285aa3d Mon Sep 17 00:00:00 2001 From: kukin-konstantin Date: Fri, 30 Dec 2016 16:01:00 +0300 Subject: Add Chat functions --- src/Api.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src') 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 Api::getUpdates(int32_t offset, int32_t limit, int32_t timeout) const { +Chat::Ptr Api::getChat(int32_t chatId) const +{ + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + return TgTypeParser::getInstance().parseJsonAndGetChat(sendRequest("getChat", args)); +} + +std::vector Api::getChatAdministrators(int32_t chatId) const +{ + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + return TgTypeParser::getInstance().parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); +} + +int32_t Api::getChatMembersCount(int32_t chatId) const +{ + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + return sendRequest("getChatMembersCount", args).get("", 0); +} + +ChatMember::Ptr Api::getChatMember(int32_t chatId, int32_t userId) const +{ + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + return TgTypeParser::getInstance().parseJsonAndGetChatMember(sendRequest("getChatMember", args)); +} + +vector Api::getUpdates(int32_t offset, int32_t limit, int32_t timeout, const StringArrayPtr &allowedUpdates) const { vector args; if (offset) { args.push_back(HttpReqArg("offset", offset)); @@ -420,6 +449,13 @@ vector 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( + [](const std::string &s)->std::string { + return s; + }, *allowedUpdates); + args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson)); + } return TgTypeParser::getInstance().parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); } -- cgit v1.2.3