Add expect_join_request parameter.

This commit is contained in:
levlam 2024-08-10 22:20:15 +03:00
parent 67a418a330
commit c06ca5f287
6 changed files with 26 additions and 26 deletions

View File

@ -6054,7 +6054,7 @@ void ChatManager::on_update_chat_full_invite_link(ChatFull *chat_full,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link) { tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link) {
CHECK(chat_full != nullptr); CHECK(chat_full != nullptr);
if (update_permanent_invite_link(chat_full->invite_link, if (update_permanent_invite_link(chat_full->invite_link,
DialogInviteLink(std::move(invite_link), false, "ChatFull"))) { DialogInviteLink(std::move(invite_link), false, false, "ChatFull"))) {
chat_full->is_changed = true; chat_full->is_changed = true;
} }
} }
@ -6063,7 +6063,7 @@ void ChatManager::on_update_channel_full_invite_link(ChannelFull *channel_full,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link) { tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link) {
CHECK(channel_full != nullptr); CHECK(channel_full != nullptr);
if (update_permanent_invite_link(channel_full->invite_link, if (update_permanent_invite_link(channel_full->invite_link,
DialogInviteLink(std::move(invite_link), false, "ChannelFull"))) { DialogInviteLink(std::move(invite_link), false, false, "ChannelFull"))) {
channel_full->is_changed = true; channel_full->is_changed = true;
} }
} }

View File

@ -48,7 +48,7 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
return td_api::make_object<td_api::chatEventMemberJoined>(); return td_api::make_object<td_api::chatEventMemberJoined>();
case telegram_api::channelAdminLogEventActionParticipantJoinByInvite::ID: { case telegram_api::channelAdminLogEventActionParticipantJoinByInvite::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantJoinByInvite>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantJoinByInvite>(action_ptr);
DialogInviteLink invite_link(std::move(action->invite_), true, DialogInviteLink invite_link(std::move(action->invite_), true, false,
"channelAdminLogEventActionParticipantJoinByInvite"); "channelAdminLogEventActionParticipantJoinByInvite");
if (!invite_link.is_valid()) { if (!invite_link.is_valid()) {
LOG(ERROR) << "Wrong invite link: " << invite_link; LOG(ERROR) << "Wrong invite link: " << invite_link;
@ -59,7 +59,7 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
} }
case telegram_api::channelAdminLogEventActionParticipantJoinByRequest::ID: { case telegram_api::channelAdminLogEventActionParticipantJoinByRequest::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantJoinByRequest>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantJoinByRequest>(action_ptr);
DialogInviteLink invite_link(std::move(action->invite_), true, DialogInviteLink invite_link(std::move(action->invite_), true, true,
"channelAdminLogEventActionParticipantJoinByRequest"); "channelAdminLogEventActionParticipantJoinByRequest");
UserId approver_user_id(action->approved_by_); UserId approver_user_id(action->approved_by_);
if (!approver_user_id.is_valid()) { if (!approver_user_id.is_valid()) {
@ -272,9 +272,9 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
} }
case telegram_api::channelAdminLogEventActionExportedInviteEdit::ID: { case telegram_api::channelAdminLogEventActionExportedInviteEdit::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteEdit>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteEdit>(action_ptr);
DialogInviteLink old_invite_link(std::move(action->prev_invite_), true, DialogInviteLink old_invite_link(std::move(action->prev_invite_), true, false,
"channelAdminLogEventActionExportedInviteEdit"); "channelAdminLogEventActionExportedInviteEdit");
DialogInviteLink new_invite_link(std::move(action->new_invite_), true, DialogInviteLink new_invite_link(std::move(action->new_invite_), true, false,
"channelAdminLogEventActionExportedInviteEdit"); "channelAdminLogEventActionExportedInviteEdit");
if (!old_invite_link.is_valid() || !new_invite_link.is_valid()) { if (!old_invite_link.is_valid() || !new_invite_link.is_valid()) {
LOG(ERROR) << "Wrong edited invite link: " << old_invite_link << " -> " << new_invite_link; LOG(ERROR) << "Wrong edited invite link: " << old_invite_link << " -> " << new_invite_link;
@ -286,7 +286,8 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
} }
case telegram_api::channelAdminLogEventActionExportedInviteRevoke::ID: { case telegram_api::channelAdminLogEventActionExportedInviteRevoke::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteRevoke>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteRevoke>(action_ptr);
DialogInviteLink invite_link(std::move(action->invite_), true, "channelAdminLogEventActionExportedInviteRevoke"); DialogInviteLink invite_link(std::move(action->invite_), true, false,
"channelAdminLogEventActionExportedInviteRevoke");
if (!invite_link.is_valid()) { if (!invite_link.is_valid()) {
LOG(ERROR) << "Wrong revoked invite link: " << invite_link; LOG(ERROR) << "Wrong revoked invite link: " << invite_link;
return nullptr; return nullptr;
@ -296,7 +297,8 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
} }
case telegram_api::channelAdminLogEventActionExportedInviteDelete::ID: { case telegram_api::channelAdminLogEventActionExportedInviteDelete::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteDelete>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionExportedInviteDelete>(action_ptr);
DialogInviteLink invite_link(std::move(action->invite_), true, "channelAdminLogEventActionExportedInviteDelete"); DialogInviteLink invite_link(std::move(action->invite_), true, false,
"channelAdminLogEventActionExportedInviteDelete");
if (!invite_link.is_valid()) { if (!invite_link.is_valid()) {
LOG(ERROR) << "Wrong deleted invite link: " << invite_link; LOG(ERROR) << "Wrong deleted invite link: " << invite_link;
return nullptr; return nullptr;

View File

@ -15,22 +15,20 @@
namespace td { namespace td {
DialogInviteLink::DialogInviteLink(tl_object_ptr<telegram_api::ExportedChatInvite> exported_invite_ptr, DialogInviteLink::DialogInviteLink(telegram_api::object_ptr<telegram_api::ExportedChatInvite> exported_invite_ptr,
bool allow_truncated, const char *source) { bool allow_truncated, bool expect_join_request, const char *source) {
if (exported_invite_ptr == nullptr) { if (exported_invite_ptr == nullptr) {
return; return;
} }
if (exported_invite_ptr->get_id() != telegram_api::chatInviteExported::ID) { if (exported_invite_ptr->get_id() != telegram_api::chatInviteExported::ID) {
CHECK(exported_invite_ptr->get_id() == telegram_api::chatInvitePublicJoinRequests::ID); CHECK(exported_invite_ptr->get_id() == telegram_api::chatInvitePublicJoinRequests::ID);
Slice slice(source); if (!expect_join_request) {
if (slice != "channelAdminLogEventActionParticipantJoinByRequest" && slice != "updateChatParticipant" &&
slice != "updateChannelParticipant" && slice != "updateBotChatInviteRequester") {
LOG(ERROR) << "Receive from " << source << ' ' << to_string(exported_invite_ptr); LOG(ERROR) << "Receive from " << source << ' ' << to_string(exported_invite_ptr);
} }
return; return;
} }
auto exported_invite = move_tl_object_as<telegram_api::chatInviteExported>(exported_invite_ptr); auto exported_invite = telegram_api::move_object_as<telegram_api::chatInviteExported>(exported_invite_ptr);
invite_link_ = std::move(exported_invite->link_); invite_link_ = std::move(exported_invite->link_);
title_ = std::move(exported_invite->title_); title_ = std::move(exported_invite->title_);
creator_user_id_ = UserId(exported_invite->admin_id_); creator_user_id_ = UserId(exported_invite->admin_id_);

View File

@ -39,8 +39,8 @@ class DialogInviteLink {
public: public:
DialogInviteLink() = default; DialogInviteLink() = default;
DialogInviteLink(tl_object_ptr<telegram_api::ExportedChatInvite> exported_invite_ptr, bool allow_truncated, DialogInviteLink(telegram_api::object_ptr<telegram_api::ExportedChatInvite> exported_invite_ptr, bool allow_truncated,
const char *source); bool expect_join_request, const char *source);
static bool is_valid_invite_link(Slice invite_link, bool allow_truncated = false); static bool is_valid_invite_link(Slice invite_link, bool allow_truncated = false);

View File

@ -146,7 +146,7 @@ class ExportChatInviteQuery final : public Td::ResultHandler {
auto ptr = result_ptr.move_as_ok(); auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for ExportChatInviteQuery: " << to_string(ptr); LOG(INFO) << "Receive result for ExportChatInviteQuery: " << to_string(ptr);
DialogInviteLink invite_link(std::move(ptr), false, "ExportChatInviteQuery"); DialogInviteLink invite_link(std::move(ptr), false, false, "ExportChatInviteQuery");
if (!invite_link.is_valid()) { if (!invite_link.is_valid()) {
return on_error(Status::Error(500, "Receive invalid invite link")); return on_error(Status::Error(500, "Receive invalid invite link"));
} }
@ -206,7 +206,7 @@ class EditChatInviteLinkQuery final : public Td::ResultHandler {
td_->user_manager_->on_get_users(std::move(invite->users_), "EditChatInviteLinkQuery"); td_->user_manager_->on_get_users(std::move(invite->users_), "EditChatInviteLinkQuery");
DialogInviteLink invite_link(std::move(invite->invite_), false, "EditChatInviteLinkQuery"); DialogInviteLink invite_link(std::move(invite->invite_), false, false, "EditChatInviteLinkQuery");
if (!invite_link.is_valid()) { if (!invite_link.is_valid()) {
return on_error(Status::Error(500, "Receive invalid invite link")); return on_error(Status::Error(500, "Receive invalid invite link"));
} }
@ -253,7 +253,7 @@ class GetExportedChatInviteQuery final : public Td::ResultHandler {
td_->user_manager_->on_get_users(std::move(result->users_), "GetExportedChatInviteQuery"); td_->user_manager_->on_get_users(std::move(result->users_), "GetExportedChatInviteQuery");
DialogInviteLink invite_link(std::move(result->invite_), false, "GetExportedChatInviteQuery"); DialogInviteLink invite_link(std::move(result->invite_), false, false, "GetExportedChatInviteQuery");
if (!invite_link.is_valid()) { if (!invite_link.is_valid()) {
LOG(ERROR) << "Receive invalid invite link in " << dialog_id_; LOG(ERROR) << "Receive invalid invite link in " << dialog_id_;
return on_error(Status::Error(500, "Receive invalid invite link")); return on_error(Status::Error(500, "Receive invalid invite link"));
@ -313,7 +313,7 @@ class GetExportedChatInvitesQuery final : public Td::ResultHandler {
} }
vector<td_api::object_ptr<td_api::chatInviteLink>> invite_links; vector<td_api::object_ptr<td_api::chatInviteLink>> invite_links;
for (auto &invite : result->invites_) { for (auto &invite : result->invites_) {
DialogInviteLink invite_link(std::move(invite), false, "GetExportedChatInvitesQuery"); DialogInviteLink invite_link(std::move(invite), false, false, "GetExportedChatInvitesQuery");
if (!invite_link.is_valid()) { if (!invite_link.is_valid()) {
LOG(ERROR) << "Receive invalid invite link in " << dialog_id_; LOG(ERROR) << "Receive invalid invite link in " << dialog_id_;
total_count--; total_count--;
@ -477,7 +477,7 @@ class RevokeChatInviteLinkQuery final : public Td::ResultHandler {
td_->user_manager_->on_get_users(std::move(invite->users_), "RevokeChatInviteLinkQuery"); td_->user_manager_->on_get_users(std::move(invite->users_), "RevokeChatInviteLinkQuery");
DialogInviteLink invite_link(std::move(invite->invite_), false, "RevokeChatInviteLinkQuery"); DialogInviteLink invite_link(std::move(invite->invite_), false, false, "RevokeChatInviteLinkQuery");
if (!invite_link.is_valid()) { if (!invite_link.is_valid()) {
return on_error(Status::Error(500, "Receive invalid invite link")); return on_error(Status::Error(500, "Receive invalid invite link"));
} }
@ -489,8 +489,8 @@ class RevokeChatInviteLinkQuery final : public Td::ResultHandler {
td_->user_manager_->on_get_users(std::move(invite->users_), "RevokeChatInviteLinkQuery replaced"); td_->user_manager_->on_get_users(std::move(invite->users_), "RevokeChatInviteLinkQuery replaced");
DialogInviteLink invite_link(std::move(invite->invite_), false, "RevokeChatInviteLinkQuery replaced"); DialogInviteLink invite_link(std::move(invite->invite_), false, false, "RevokeChatInviteLinkQuery replaced");
DialogInviteLink new_invite_link(std::move(invite->new_invite_), false, DialogInviteLink new_invite_link(std::move(invite->new_invite_), false, false,
"RevokeChatInviteLinkQuery new replaced"); "RevokeChatInviteLinkQuery new replaced");
if (!invite_link.is_valid() || !new_invite_link.is_valid()) { if (!invite_link.is_valid() || !new_invite_link.is_valid()) {
return on_error(Status::Error(500, "Receive invalid invite link")); return on_error(Status::Error(500, "Receive invalid invite link"));

View File

@ -3012,7 +3012,7 @@ void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&up
update->invite_ != nullptr && update->invite_->get_id() == telegram_api::chatInvitePublicJoinRequests::ID; update->invite_ != nullptr && update->invite_->get_id() == telegram_api::chatInvitePublicJoinRequests::ID;
td_->dialog_participant_manager_->on_update_chat_participant( td_->dialog_participant_manager_->on_update_chat_participant(
ChatId(update->chat_id_), UserId(update->actor_id_), update->date_, ChatId(update->chat_id_), UserId(update->actor_id_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateChatParticipant"), via_join_request, DialogInviteLink(std::move(update->invite_), true, true, "updateChatParticipant"), via_join_request,
std::move(update->prev_participant_), std::move(update->new_participant_)); std::move(update->prev_participant_), std::move(update->new_participant_));
break; break;
} }
@ -3022,7 +3022,7 @@ void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&up
update->invite_ != nullptr && update->invite_->get_id() == telegram_api::chatInvitePublicJoinRequests::ID; update->invite_ != nullptr && update->invite_->get_id() == telegram_api::chatInvitePublicJoinRequests::ID;
td_->dialog_participant_manager_->on_update_channel_participant( td_->dialog_participant_manager_->on_update_channel_participant(
ChannelId(update->channel_id_), UserId(update->actor_id_), update->date_, ChannelId(update->channel_id_), UserId(update->actor_id_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateChannelParticipant"), via_join_request, DialogInviteLink(std::move(update->invite_), true, true, "updateChannelParticipant"), via_join_request,
update->via_chatlist_, std::move(update->prev_participant_), std::move(update->new_participant_)); update->via_chatlist_, std::move(update->prev_participant_), std::move(update->new_participant_));
break; break;
} }
@ -3030,7 +3030,7 @@ void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&up
auto update = move_tl_object_as<telegram_api::updateBotChatInviteRequester>(update_ptr); auto update = move_tl_object_as<telegram_api::updateBotChatInviteRequester>(update_ptr);
td_->dialog_participant_manager_->on_update_chat_invite_requester( td_->dialog_participant_manager_->on_update_chat_invite_requester(
DialogId(update->peer_), UserId(update->user_id_), std::move(update->about_), update->date_, DialogId(update->peer_), UserId(update->user_id_), std::move(update->about_), update->date_,
DialogInviteLink(std::move(update->invite_), true, "updateBotChatInviteRequester")); DialogInviteLink(std::move(update->invite_), true, true, "updateBotChatInviteRequester"));
break; break;
} }
case telegram_api::updateBotChatBoost::ID: { case telegram_api::updateBotChatBoost::ID: {