From 373a17e39e02baecf10838b512d1c7ece64e8244 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 29 Apr 2024 15:51:42 +0300 Subject: [PATCH] Add updateChatMember.via_join_request. --- td/generate/scheme/td_api.tl | 3 ++- td/telegram/DialogParticipantManager.cpp | 21 +++++++++++---------- td/telegram/DialogParticipantManager.h | 7 ++++--- td/telegram/UpdatesManager.cpp | 10 +++++++--- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index bbf311ab7..f34d72fa9 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7352,10 +7352,11 @@ updatePollAnswer poll_id:int64 voter_id:MessageSender option_ids:vector = //@actor_user_id Identifier of the user, changing the rights //@date Point in time (Unix timestamp) when the user rights were changed //@invite_link If user has joined the chat using an invite link, the invite link; may be null +//@via_join_request True, if the user has joined the chat after sending a join request and being approved by an administrator //@via_chat_folder_invite_link True, if the user has joined the chat using an invite link for a chat folder //@old_chat_member Previous chat member //@new_chat_member New chat member -updateChatMember chat_id:int53 actor_user_id:int53 date:int32 invite_link:chatInviteLink via_chat_folder_invite_link:Bool old_chat_member:chatMember new_chat_member:chatMember = Update; +updateChatMember chat_id:int53 actor_user_id:int53 date:int32 invite_link:chatInviteLink via_join_request:Bool via_chat_folder_invite_link:Bool old_chat_member:chatMember new_chat_member:chatMember = Update; //@description A user sent a join request to a chat; for bots only //@chat_id Chat identifier diff --git a/td/telegram/DialogParticipantManager.cpp b/td/telegram/DialogParticipantManager.cpp index abb45523f..52679e144 100644 --- a/td/telegram/DialogParticipantManager.cpp +++ b/td/telegram/DialogParticipantManager.cpp @@ -1348,7 +1348,7 @@ void DialogParticipantManager::on_reload_dialog_administrators( } void DialogParticipantManager::send_update_chat_member(DialogId dialog_id, UserId agent_user_id, int32 date, - const DialogInviteLink &invite_link, + const DialogInviteLink &invite_link, bool via_join_request, bool via_dialog_filter_invite_link, const DialogParticipant &old_dialog_participant, const DialogParticipant &new_dialog_participant) { @@ -1358,7 +1358,8 @@ void DialogParticipantManager::send_update_chat_member(DialogId dialog_id, UserI td_api::make_object( td_->dialog_manager_->get_chat_id_object(dialog_id, "updateChatMember"), td_->user_manager_->get_user_id_object(agent_user_id, "updateChatMember"), date, - invite_link.get_chat_invite_link_object(td_->user_manager_.get()), via_dialog_filter_invite_link, + invite_link.get_chat_invite_link_object(td_->user_manager_.get()), via_join_request, + via_dialog_filter_invite_link, td_->chat_manager_->get_chat_member_object(old_dialog_participant, "updateChatMember old"), td_->chat_manager_->get_chat_member_object(new_dialog_participant, "updateChatMember new"))); } @@ -1386,12 +1387,12 @@ void DialogParticipantManager::on_update_bot_stopped(UserId user_id, int32 date, std::swap(old_dialog_participant.status_, new_dialog_participant.status_); } - send_update_chat_member(DialogId(user_id), user_id, date, DialogInviteLink(), false, old_dialog_participant, + send_update_chat_member(DialogId(user_id), user_id, date, DialogInviteLink(), false, false, old_dialog_participant, new_dialog_participant); } void DialogParticipantManager::on_update_chat_participant( - ChatId chat_id, UserId user_id, int32 date, DialogInviteLink invite_link, + ChatId chat_id, UserId user_id, int32 date, DialogInviteLink invite_link, bool via_join_request, telegram_api::object_ptr old_participant, telegram_api::object_ptr new_participant) { CHECK(td_->auth_manager_->is_bot()); @@ -1434,13 +1435,13 @@ void DialogParticipantManager::on_update_chat_participant( << user_id << " at " << date << " from " << old_dialog_participant << " to " << new_dialog_participant; } - send_update_chat_member(DialogId(chat_id), user_id, date, invite_link, false, old_dialog_participant, - new_dialog_participant); + send_update_chat_member(DialogId(chat_id), user_id, date, invite_link, via_join_request, false, + old_dialog_participant, new_dialog_participant); } void DialogParticipantManager::on_update_channel_participant( - ChannelId channel_id, UserId user_id, int32 date, DialogInviteLink invite_link, bool via_dialog_filter_invite_link, - telegram_api::object_ptr old_participant, + ChannelId channel_id, UserId user_id, int32 date, DialogInviteLink invite_link, bool via_join_request, + bool via_dialog_filter_invite_link, telegram_api::object_ptr old_participant, telegram_api::object_ptr new_participant) { CHECK(td_->auth_manager_->is_bot()); if (!channel_id.is_valid() || !user_id.is_valid() || date <= 0 || @@ -1496,8 +1497,8 @@ void DialogParticipantManager::on_update_channel_participant( << new_dialog_participant; } - send_update_chat_member(DialogId(channel_id), user_id, date, invite_link, via_dialog_filter_invite_link, - old_dialog_participant, new_dialog_participant); + send_update_chat_member(DialogId(channel_id), user_id, date, invite_link, via_join_request, + via_dialog_filter_invite_link, old_dialog_participant, new_dialog_participant); } void DialogParticipantManager::on_update_chat_invite_requester(DialogId dialog_id, UserId user_id, string about, diff --git a/td/telegram/DialogParticipantManager.h b/td/telegram/DialogParticipantManager.h index 1b8e1e3cc..f38161caa 100644 --- a/td/telegram/DialogParticipantManager.h +++ b/td/telegram/DialogParticipantManager.h @@ -85,11 +85,12 @@ class DialogParticipantManager final : public Actor { void on_update_bot_stopped(UserId user_id, int32 date, bool is_stopped, bool force = false); void on_update_chat_participant(ChatId chat_id, UserId user_id, int32 date, DialogInviteLink invite_link, + bool via_join_request, telegram_api::object_ptr old_participant, telegram_api::object_ptr new_participant); void on_update_channel_participant(ChannelId channel_id, UserId user_id, int32 date, DialogInviteLink invite_link, - bool via_dialog_filter_invite_link, + bool via_join_request, bool via_dialog_filter_invite_link, telegram_api::object_ptr old_participant, telegram_api::object_ptr new_participant); @@ -190,8 +191,8 @@ class DialogParticipantManager final : public Actor { Promise> &&promise); void send_update_chat_member(DialogId dialog_id, UserId agent_user_id, int32 date, - const DialogInviteLink &invite_link, bool via_dialog_filter_invite_link, - const DialogParticipant &old_dialog_participant, + const DialogInviteLink &invite_link, bool via_join_request, + bool via_dialog_filter_invite_link, const DialogParticipant &old_dialog_participant, const DialogParticipant &new_dialog_participant); void do_get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id, diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index fe2f74bed..118610cdf 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -2992,18 +2992,22 @@ void UpdatesManager::process_qts_update(tl_object_ptr &&up } case telegram_api::updateChatParticipant::ID: { auto update = move_tl_object_as(update_ptr); + bool via_join_request = + update->invite_ != nullptr && update->invite_->get_id() == telegram_api::chatInvitePublicJoinRequests::ID; td_->dialog_participant_manager_->on_update_chat_participant( ChatId(update->chat_id_), UserId(update->actor_id_), update->date_, - DialogInviteLink(std::move(update->invite_), true, "updateChatParticipant"), + DialogInviteLink(std::move(update->invite_), true, "updateChatParticipant"), via_join_request, std::move(update->prev_participant_), std::move(update->new_participant_)); break; } case telegram_api::updateChannelParticipant::ID: { auto update = move_tl_object_as(update_ptr); + bool via_join_request = + update->invite_ != nullptr && update->invite_->get_id() == telegram_api::chatInvitePublicJoinRequests::ID; td_->dialog_participant_manager_->on_update_channel_participant( ChannelId(update->channel_id_), UserId(update->actor_id_), update->date_, - DialogInviteLink(std::move(update->invite_), true, "updateChannelParticipant"), update->via_chatlist_, - std::move(update->prev_participant_), std::move(update->new_participant_)); + DialogInviteLink(std::move(update->invite_), true, "updateChannelParticipant"), via_join_request, + update->via_chatlist_, std::move(update->prev_participant_), std::move(update->new_participant_)); break; } case telegram_api::updateBotChatInviteRequester::ID: {