From b729f89033dca0cd2b9606060e735abfaf41c1f4 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Mon, 29 Aug 2022 18:46:44 +0200 Subject: Update to API 4.5 --- src/Api.cpp | 13 ++++++-- src/TgTypeParser.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 86 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index ff39805..b1a2f69 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -45,7 +45,7 @@ Message::Ptr Api::sendMessage(std::int64_t chatId, const string& text, bool disa } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); } - + Message::Ptr Api::sendMessage(const std::string &chatId, const string& text, bool disableWebPagePreview, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; args.reserve(7); @@ -67,7 +67,7 @@ Message::Ptr Api::sendMessage(const std::string &chatId, const string& text, boo args.emplace_back("parse_mode", parseMode); } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); -} +} Message::Ptr Api::forwardMessage(std::int64_t chatId, std::int64_t fromChatId, std::int32_t messageId, bool disableNotification) const { vector args; @@ -1032,6 +1032,15 @@ bool Api::promoteChatMember(std::int64_t chatId, std::int64_t userId, bool canCh return sendRequest("promoteChatMember", args).get("", false); } +bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const { + vector args; + args.reserve(3); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + args.emplace_back("custom_title", customTitle); + return sendRequest("setChatAdministratorCustomTitle", args).get("", false); +} + bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const{ vector args; args.reserve(2); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 13ae5d4..db2e750 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -30,6 +30,8 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { result->description = data.get("description", ""); result->inviteLink = data.get("invite_link", ""); result->pinnedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); + result->permissions = tryParseJson(&TgTypeParser::parseJsonAndGetChatPermissions, data, "permissions"); + result->slowModeDelay = data.get("slow_mode_delay"); result->stickerSetName = data.get("sticker_set_name", ""); result->canSetStickerSet = data.get("can_set_sticker_set", false); @@ -56,6 +58,15 @@ string TgTypeParser::parseChat(const Chat::Ptr& object) const { appendToJson(result, "username", object->username); appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); + appendToJson(result, "all_members_are_administrators", object->allMembersAreAdministrators); + appendToJson(result, "photo", parseChatPhoto(object->photo)); + appendToJson(result, "description", object->description); + appendToJson(result, "invite_link", object->inviteLink); + appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage)); + appendToJson(result, "permissions", parseChatPermissions(object->permissions)); + appendToJson(result, "slow_mode_delay", object->slowModeDelay); + appendToJson(result, "sticker_set_name", object->stickerSetName); + appendToJson(result, "can_set_sticker_set", object->canSetStickerSet); removeLastComma(result); result += '}'; return result; @@ -220,6 +231,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const { PhotoSize::Ptr TgTypeParser::parseJsonAndGetPhotoSize(const ptree& data) const { auto result(make_shared()); result->fileId = data.get("file_id"); + result->fileUniqueId = data.get("file_unique_id"); result->width = data.get("width"); result->height = data.get("height"); result->fileSize = data.get("file_size", 0); @@ -233,6 +245,7 @@ string TgTypeParser::parsePhotoSize(const PhotoSize::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "file_size", object->fileSize); @@ -244,6 +257,7 @@ string TgTypeParser::parsePhotoSize(const PhotoSize::Ptr& object) const { Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const ptree& data) const { auto result(make_shared