summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-09-04 20:59:46 +0200
committerllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-09-04 20:59:46 +0200
commit5a72b4b1fc89d9b6033f929d9bf4f6e30d7f9698 (patch)
tree33fba0566f2bb1f378ca2d3de57fe63170312cca /src
parent5492d26d21d09dc9cc3551f32a8eab7a2e783e3c (diff)
Update to API 5.4
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp50
-rw-r--r--src/TgTypeParser.cpp34
2 files changed, 78 insertions, 6 deletions
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<HttpReqArg> 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<HttpReqArg> 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<HttpReqArg> args;
+ args.reserve(2);
+
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
+
+ return sendRequest("approveChatJoinRequest", args).get<bool>("", false);
+}
+
+bool Api::declineChatJoinRequest(std::int64_t chatId,
+ std::int64_t userId) const {
+ vector<HttpReqArg> args;
+ args.reserve(2);
+
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
+
+ return sendRequest("declineChatJoinRequest", args).get<bool>("", false);
+}
+
bool Api::setChatPhoto(std::int64_t chatId, const InputFile::Ptr photo) const {
vector<HttpReqArg> 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<PollAnswer>(&TgTypeParser::parseJsonAndGetPollAnswer, data, "poll_answer");
result->myChatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "my_chat_member");
result->chatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "chat_member");
+ result->chatJoinRequest = tryParseJson<ChatJoinRequest>(&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<ChatJoinRequest>());
+ result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat");
+ result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
+ result->date = data.get<std::int32_t>("date", 0);
+ result->bio = data.get<std::string>("bio", "");
+ result->inviteLink = tryParseJson<ChatInviteLink>(&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<ChatPhoto>());
result->smallFileId = data.get<std::string>("small_file_id", "");
@@ -1626,10 +1654,13 @@ ChatInviteLink::Ptr TgTypeParser::parseJsonAndGetChatInviteLink(const boost::pro
auto result(std::make_shared<ChatInviteLink>());
result->inviteLink = data.get<std::string>("invite_link", "");
result->creator = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "creator");
+ result->createsJoinRequest = data.get<bool>("creates_join_request", false);
result->isPrimary = data.get<bool>("is_primary", false);
result->isRevoked = data.get<bool>("is_revoked", false);
+ result->name = data.get<std::string>("name", "");
result->expireDate = data.get<std::int32_t>("expire_date", 0);
result->memberLimit = data.get<std::int32_t>("member_limit", 0);
+ result->pendingJoinRequestCount = data.get<std::int32_t>("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;