From 5a72b4b1fc89d9b6033f929d9bf4f6e30d7f9698 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sun, 4 Sep 2022 20:59:46 +0200 Subject: Update to API 5.4 --- src/Api.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++------ src/TgTypeParser.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index 9fdf290..ad9f544 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1058,36 +1058,52 @@ string Api::exportChatInviteLink(std::int64_t chatId) const { ChatInviteLink::Ptr Api::createChatInviteLink(std::int64_t chatId, std::int32_t expireDate, - std::int32_t memberLimit) const { + std::int32_t memberLimit, + const std::string& name, + bool createsJoinRequest) const { vector args; - args.reserve(3); + args.reserve(5); args.emplace_back("chat_id", chatId); + if (!name.empty()) { + args.emplace_back("name", name); + } if (expireDate != 0) { args.emplace_back("expire_date", expireDate); } if (memberLimit != 0) { args.emplace_back("member_limit", memberLimit); } + if (createsJoinRequest) { + args.emplace_back("createsJoinRequest", createsJoinRequest); + } return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("createChatInviteLink", args)); } ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId, - std::string inviteLink, - std::int32_t expireDate, - std::int32_t memberLimit) const { + std::string inviteLink, + std::int32_t expireDate, + std::int32_t memberLimit, + const std::string& name, + bool createsJoinRequest) const { vector args; - args.reserve(4); + args.reserve(6); args.emplace_back("chat_id", chatId); args.emplace_back("invite_link", inviteLink); + if (!name.empty()) { + args.emplace_back("name", name); + } if (expireDate != 0) { args.emplace_back("expire_date", expireDate); } if (memberLimit != 0) { args.emplace_back("member_limit", memberLimit); } + if (createsJoinRequest) { + args.emplace_back("createsJoinRequest", createsJoinRequest); + } return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("editChatInviteLink", args)); } @@ -1103,6 +1119,28 @@ ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("revokeChatInviteLink", args)); } +bool Api::approveChatJoinRequest(std::int64_t chatId, + std::int64_t userId) const { + vector args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + + return sendRequest("approveChatJoinRequest", args).get("", false); +} + +bool Api::declineChatJoinRequest(std::int64_t chatId, + std::int64_t userId) const { + vector args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + + return sendRequest("declineChatJoinRequest", args).get("", false); +} + bool Api::setChatPhoto(std::int64_t chatId, const InputFile::Ptr photo) const { vector args; args.reserve(2); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 330278a..ed75e21 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -997,6 +997,7 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptre result->pollAnswer = tryParseJson(&TgTypeParser::parseJsonAndGetPollAnswer, data, "poll_answer"); result->myChatMember = tryParseJson(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "my_chat_member"); result->chatMember = tryParseJson(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "chat_member"); + result->chatJoinRequest = tryParseJson(&TgTypeParser::parseJsonAndGetChatJoinRequest, data, "chat_join_request"); return result; } @@ -1020,6 +1021,7 @@ std::string TgTypeParser::parseUpdate(const Update::Ptr& object) const { appendToJson(result, "poll_answer", parsePollAnswer(object->pollAnswer)); appendToJson(result, "my_chat_member", parseChatMemberUpdated(object->myChatMember)); appendToJson(result, "chat_member", parseChatMemberUpdated(object->chatMember)); + appendToJson(result, "chat_join_request", parseChatJoinRequest(object->chatJoinRequest)); removeLastComma(result); result += '}'; return result; @@ -1598,6 +1600,32 @@ std::string TgTypeParser::parseChatMemberUpdated(const ChatMemberUpdated::Ptr& o return result; } +ChatJoinRequest::Ptr TgTypeParser::parseJsonAndGetChatJoinRequest(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->chat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->date = data.get("date", 0); + result->bio = data.get("bio", ""); + result->inviteLink = tryParseJson(&TgTypeParser::parseJsonAndGetChatInviteLink, data, "invite_link"); + return result; +} + +std::string TgTypeParser::parseChatJoinRequest(const ChatJoinRequest::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "from", parseUser(object->from)); + appendToJson(result, "date", object->date); + appendToJson(result, "bio", object->bio); + appendToJson(result, "invite_link", parseChatInviteLink(object->inviteLink)); + removeLastComma(result); + result += '}'; + return result; +} + ChatPhoto::Ptr TgTypeParser::parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->smallFileId = data.get("small_file_id", ""); @@ -1626,10 +1654,13 @@ ChatInviteLink::Ptr TgTypeParser::parseJsonAndGetChatInviteLink(const boost::pro auto result(std::make_shared()); result->inviteLink = data.get("invite_link", ""); result->creator = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "creator"); + result->createsJoinRequest = data.get("creates_join_request", false); result->isPrimary = data.get("is_primary", false); result->isRevoked = data.get("is_revoked", false); + result->name = data.get("name", ""); result->expireDate = data.get("expire_date", 0); result->memberLimit = data.get("member_limit", 0); + result->pendingJoinRequestCount = data.get("pending_join_request_count", 0); return result; } @@ -1641,10 +1672,13 @@ std::string TgTypeParser::parseChatInviteLink(const ChatInviteLink::Ptr& object) result += '{'; appendToJson(result, "invite_link", object->inviteLink); appendToJson(result, "creator", parseUser(object->creator)); + appendToJson(result, "creates_join_request", object->createsJoinRequest); appendToJson(result, "is_primary", object->isPrimary); appendToJson(result, "is_revoked", object->isRevoked); + appendToJson(result, "name", object->name); appendToJson(result, "expire_date", object->expireDate); appendToJson(result, "member_limit", object->memberLimit); + appendToJson(result, "pending_join_request_count", object->pendingJoinRequestCount); removeLastComma(result); result += '}'; return result; -- cgit v1.2.3