aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2021-02-25 21:29:30 +0300
committerlevlam <levlam@telegram.org>2021-02-25 21:29:30 +0300
commit685e6bf87df06d472708ed80cf2ec41bab8fe01f (patch)
treecbbdb0d98b64929636b4805f780ee679c35029e9
parentae56eee88fce553cbd4958fabc801a841fa530fc (diff)
Update TDLib to 1.7.2. Add createChatInviteLink method.
m---------td0
-rw-r--r--telegram-bot-api/Client.cpp74
-rw-r--r--telegram-bot-api/Client.h5
3 files changed, 71 insertions, 8 deletions
diff --git a/td b/td
-Subproject 3a657d9072b324aad1143c6abe20a802f3b92cd
+Subproject 3b3801abbec641ac66a050760d198dfc7bca92b
diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp
index 79d9697..da533cf 100644
--- a/telegram-bot-api/Client.cpp
+++ b/telegram-bot-api/Client.cpp
@@ -212,6 +212,7 @@ bool Client::init_methods() {
methods_.emplace("answershippingquery", &Client::process_answer_shipping_query_query);
methods_.emplace("answerprecheckoutquery", &Client::process_answer_pre_checkout_query_query);
methods_.emplace("exportchatinvitelink", &Client::process_export_chat_invite_link_query);
+ methods_.emplace("createchatinvitelink", &Client::process_create_chat_invite_link_query);
methods_.emplace("getchat", &Client::process_get_chat_query);
methods_.emplace("setchatphoto", &Client::process_set_chat_photo_query);
methods_.emplace("deletechatphoto", &Client::process_delete_chat_photo_query);
@@ -525,6 +526,30 @@ class Client::JsonChatLocation : public Jsonable {
const td_api::chatLocation *chat_location_;
};
+class Client::JsonChatInviteLink : public Jsonable {
+ public:
+ JsonChatInviteLink(const td_api::chatInviteLink *chat_invite_link, const Client *client)
+ : chat_invite_link_(chat_invite_link), client_(client) {
+ }
+ void store(JsonValueScope *scope) const {
+ auto object = scope->enter_object();
+ object("invite_link", chat_invite_link_->invite_link_);
+ object("creator", JsonUser(chat_invite_link_->creator_user_id_, client_));
+ if (chat_invite_link_->expire_date_ != 0) {
+ object("expire_date", chat_invite_link_->expire_date_);
+ }
+ if (chat_invite_link_->member_limit_ != 0) {
+ object("member_limit", chat_invite_link_->member_limit_);
+ }
+ object("is_primary", td::JsonBool(chat_invite_link_->is_primary_));
+ object("is_revoked", td::JsonBool(chat_invite_link_->is_revoked_));
+ }
+
+ private:
+ const td_api::chatInviteLink *chat_invite_link_;
+ const Client *client_;
+};
+
class Client::JsonMessage : public Jsonable {
public:
JsonMessage(const MessageInfo *message, bool need_reply, const td::string &source, const Client *client)
@@ -3150,9 +3175,9 @@ class Client::TdOnGetSupergroupMembersCountCallback : public TdQueryCallback {
PromisedQueryPtr query_;
};
-class Client::TdOnReplacePermanentChatInviteLinkCallback : public TdQueryCallback {
+class Client::TdOnReplacePrimaryChatInviteLinkCallback : public TdQueryCallback {
public:
- explicit TdOnReplacePermanentChatInviteLinkCallback(PromisedQueryPtr query) : query_(std::move(query)) {
+ explicit TdOnReplacePrimaryChatInviteLinkCallback(PromisedQueryPtr query) : query_(std::move(query)) {
}
void on_result(object_ptr<td_api::Object> result) override {
@@ -3169,6 +3194,27 @@ class Client::TdOnReplacePermanentChatInviteLinkCallback : public TdQueryCallbac
PromisedQueryPtr query_;
};
+class Client::TdOnGetChatInviteLinkCallback : public TdQueryCallback {
+ public:
+ TdOnGetChatInviteLinkCallback(const Client *client, PromisedQueryPtr query)
+ : client_(client), query_(std::move(query)) {
+ }
+
+ void on_result(object_ptr<td_api::Object> result) override {
+ if (result->get_id() == td_api::error::ID) {
+ return fail_query_with_error(std::move(query_), move_object_as<td_api::error>(result));
+ }
+
+ CHECK(result->get_id() == td_api::chatInviteLink::ID);
+ auto invite_link = move_object_as<td_api::chatInviteLink>(result);
+ return answer_query(JsonChatInviteLink(invite_link.get(), client_), std::move(query_));
+ }
+
+ private:
+ const Client *client_;
+ PromisedQueryPtr query_;
+};
+
class Client::TdOnGetGameHighScoresCallback : public TdQueryCallback {
public:
TdOnGetGameHighScoresCallback(const Client *client, PromisedQueryPtr query)
@@ -6747,12 +6793,25 @@ td::Status Client::process_export_chat_invite_link_query(PromisedQueryPtr &query
auto chat_id = query->arg("chat_id");
check_chat(chat_id, AccessRights::Write, std::move(query), [this](int64 chat_id, PromisedQueryPtr query) {
- send_request(make_object<td_api::replacePermanentChatInviteLink>(chat_id),
- std::make_unique<TdOnReplacePermanentChatInviteLinkCallback>(std::move(query)));
+ send_request(make_object<td_api::replacePrimaryChatInviteLink>(chat_id),
+ std::make_unique<TdOnReplacePrimaryChatInviteLinkCallback>(std::move(query)));
});
return Status::OK();
}
+td::Status Client::process_create_chat_invite_link_query(PromisedQueryPtr &query) {
+ auto chat_id = query->arg("chat_id");
+ auto expire_date = get_integer_arg(query.get(), "expire_date", 0, 0);
+ auto member_limit = get_integer_arg(query.get(), "member_limit", 0, 0, 100000);
+
+ check_chat(chat_id, AccessRights::Write, std::move(query),
+ [this, expire_date, member_limit](int64 chat_id, PromisedQueryPtr query) {
+ send_request(make_object<td_api::createChatInviteLink>(chat_id, expire_date, member_limit),
+ std::make_unique<TdOnGetChatInviteLinkCallback>(this, std::move(query)));
+ });
+ return Status::OK();
+}
+
td::Status Client::process_get_chat_query(PromisedQueryPtr &query) {
auto chat_id = query->arg("chat_id");
@@ -7019,8 +7078,9 @@ td::Status Client::process_promote_chat_member_query(PromisedQueryPtr &query) {
auto can_manage_voice_chats = to_bool(query->arg("can_manage_voice_chats"));
auto is_anonymous = to_bool(query->arg("is_anonymous"));
auto status = make_object<td_api::chatMemberStatusAdministrator>(
- td::string(), true, can_change_info, can_post_messages, can_edit_messages, can_delete_messages, can_invite_users,
- can_restrict_members, can_pin_messages, can_promote_members, can_manage_voice_chats, is_anonymous);
+ td::string(), true, false, can_change_info, can_post_messages, can_edit_messages, can_delete_messages,
+ can_invite_users, can_restrict_members, can_pin_messages, can_promote_members, can_manage_voice_chats,
+ is_anonymous);
check_chat(chat_id, AccessRights::Write, std::move(query),
[this, user_id, status = std::move(status)](int64 chat_id, PromisedQueryPtr query) mutable {
auto chat_info = get_chat(chat_id);
@@ -8444,7 +8504,7 @@ bool Client::need_skip_update_message(int64 chat_id, const object_ptr<td_api::me
}
}
- if (message->ttl_ > 0) {
+ if (message->ttl_ > 0 && message->ttl_expires_in_ == 0) {
return true;
}
diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h
index 6198f09..a722179 100644
--- a/telegram-bot-api/Client.h
+++ b/telegram-bot-api/Client.h
@@ -91,6 +91,7 @@ class Client : public WebhookActor::Callback {
class JsonChatPermissions;
class JsonChatPhotoInfo;
class JsonChatLocation;
+ class JsonChatInviteLink;
class JsonChat;
class JsonMessageSender;
class JsonAnimation;
@@ -175,7 +176,8 @@ class Client : public WebhookActor::Callback {
class TdOnGetGroupMembersCallback;
class TdOnGetSupergroupMembersCallback;
class TdOnGetSupergroupMembersCountCallback;
- class TdOnReplacePermanentChatInviteLinkCallback;
+ class TdOnReplacePrimaryChatInviteLinkCallback;
+ class TdOnGetChatInviteLinkCallback;
class TdOnGetGameHighScoresCallback;
class TdOnReturnFileCallback;
class TdOnReturnStickerSetCallback;
@@ -443,6 +445,7 @@ class Client : public WebhookActor::Callback {
Status process_answer_shipping_query_query(PromisedQueryPtr &query);
Status process_answer_pre_checkout_query_query(PromisedQueryPtr &query);
Status process_export_chat_invite_link_query(PromisedQueryPtr &query);
+ Status process_create_chat_invite_link_query(PromisedQueryPtr &query);
Status process_get_chat_query(PromisedQueryPtr &query);
Status process_set_chat_photo_query(PromisedQueryPtr &query);
Status process_delete_chat_photo_query(PromisedQueryPtr &query);