From 59e926350e9db24b3b1775098e14ccc5be04345e Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 25 May 2022 16:31:17 +0300 Subject: [PATCH] Add source to DialogInviteLink constructor. --- td/telegram/ContactsManager.cpp | 19 ++++++++++--------- td/telegram/DialogEventLog.cpp | 12 ++++++------ td/telegram/DialogInviteLink.cpp | 26 ++++++++++++++------------ td/telegram/DialogInviteLink.h | 2 +- td/telegram/UpdatesManager.cpp | 22 +++++++++++----------- 5 files changed, 42 insertions(+), 39 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 7bd4bdc01..43d978f27 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1420,7 +1420,7 @@ class ExportChatInviteQuery final : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for ExportChatInviteQuery: " << to_string(ptr); - DialogInviteLink invite_link(std::move(ptr)); + DialogInviteLink invite_link(std::move(ptr), "ExportChatInviteQuery"); if (!invite_link.is_valid()) { return on_error(Status::Error(500, "Receive invalid invite link")); } @@ -1482,7 +1482,7 @@ class EditChatInviteLinkQuery final : public Td::ResultHandler { td_->contacts_manager_->on_get_users(std::move(invite->users_), "EditChatInviteLinkQuery"); - DialogInviteLink invite_link(std::move(invite->invite_)); + DialogInviteLink invite_link(std::move(invite->invite_), "EditChatInviteLinkQuery"); if (!invite_link.is_valid()) { return on_error(Status::Error(500, "Receive invalid invite link")); } @@ -1531,7 +1531,7 @@ class GetExportedChatInviteQuery final : public Td::ResultHandler { td_->contacts_manager_->on_get_users(std::move(result->users_), "GetExportedChatInviteQuery"); - DialogInviteLink invite_link(std::move(result->invite_)); + DialogInviteLink invite_link(std::move(result->invite_), "GetExportedChatInviteQuery"); if (!invite_link.is_valid()) { LOG(ERROR) << "Receive invalid invite link in " << dialog_id_; return on_error(Status::Error(500, "Receive invalid invite link")); @@ -1593,7 +1593,7 @@ class GetExportedChatInvitesQuery final : public Td::ResultHandler { } vector> invite_links; for (auto &invite : result->invites_) { - DialogInviteLink invite_link(std::move(invite)); + DialogInviteLink invite_link(std::move(invite), "GetExportedChatInvitesQuery"); if (!invite_link.is_valid()) { LOG(ERROR) << "Receive invalid invite link in " << dialog_id_; total_count--; @@ -1934,7 +1934,7 @@ class RevokeChatInviteLinkQuery final : public Td::ResultHandler { td_->contacts_manager_->on_get_users(std::move(invite->users_), "RevokeChatInviteLinkQuery"); - DialogInviteLink invite_link(std::move(invite->invite_)); + DialogInviteLink invite_link(std::move(invite->invite_), "RevokeChatInviteLinkQuery"); if (!invite_link.is_valid()) { return on_error(Status::Error(500, "Receive invalid invite link")); } @@ -1946,8 +1946,8 @@ class RevokeChatInviteLinkQuery final : public Td::ResultHandler { td_->contacts_manager_->on_get_users(std::move(invite->users_), "RevokeChatInviteLinkQuery replaced"); - DialogInviteLink invite_link(std::move(invite->invite_)); - DialogInviteLink new_invite_link(std::move(invite->new_invite_)); + DialogInviteLink invite_link(std::move(invite->invite_), "RevokeChatInviteLinkQuery replaced"); + DialogInviteLink new_invite_link(std::move(invite->new_invite_), "RevokeChatInviteLinkQuery new replaced"); if (!invite_link.is_valid() || !new_invite_link.is_valid()) { return on_error(Status::Error(500, "Receive invalid invite link")); } @@ -12945,7 +12945,7 @@ void ContactsManager::on_get_permanent_dialog_invite_link(DialogId dialog_id, co void ContactsManager::on_update_chat_full_invite_link(ChatFull *chat_full, tl_object_ptr &&invite_link) { CHECK(chat_full != nullptr); - if (update_permanent_invite_link(chat_full->invite_link, DialogInviteLink(std::move(invite_link)))) { + if (update_permanent_invite_link(chat_full->invite_link, DialogInviteLink(std::move(invite_link), "ChatFull"))) { chat_full->is_changed = true; } } @@ -12953,7 +12953,8 @@ void ContactsManager::on_update_chat_full_invite_link(ChatFull *chat_full, void ContactsManager::on_update_channel_full_invite_link( ChannelFull *channel_full, tl_object_ptr &&invite_link) { CHECK(channel_full != nullptr); - if (update_permanent_invite_link(channel_full->invite_link, DialogInviteLink(std::move(invite_link)))) { + if (update_permanent_invite_link(channel_full->invite_link, + DialogInviteLink(std::move(invite_link), "ChannelFull"))) { channel_full->is_changed = true; } } diff --git a/td/telegram/DialogEventLog.cpp b/td/telegram/DialogEventLog.cpp index 67bfa00d8..dada32466 100644 --- a/td/telegram/DialogEventLog.cpp +++ b/td/telegram/DialogEventLog.cpp @@ -39,7 +39,7 @@ static td_api::object_ptr get_chat_event_action_object( return td_api::make_object(); case telegram_api::channelAdminLogEventActionParticipantJoinByInvite::ID: { auto action = move_tl_object_as(action_ptr); - DialogInviteLink invite_link(std::move(action->invite_)); + DialogInviteLink invite_link(std::move(action->invite_), "channelAdminLogEventActionParticipantJoinByInvite"); if (!invite_link.is_valid()) { LOG(ERROR) << "Wrong invite link: " << invite_link; return nullptr; @@ -49,7 +49,7 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionParticipantJoinByRequest::ID: { auto action = move_tl_object_as(action_ptr); - DialogInviteLink invite_link(std::move(action->invite_)); + DialogInviteLink invite_link(std::move(action->invite_), "channelAdminLogEventActionParticipantJoinByRequest"); if (!invite_link.is_valid()) { LOG(ERROR) << "Wrong invite link: " << invite_link; return nullptr; @@ -257,8 +257,8 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionExportedInviteEdit::ID: { auto action = move_tl_object_as(action_ptr); - DialogInviteLink old_invite_link(std::move(action->prev_invite_)); - DialogInviteLink new_invite_link(std::move(action->new_invite_)); + DialogInviteLink old_invite_link(std::move(action->prev_invite_), "channelAdminLogEventActionExportedInviteEdit"); + DialogInviteLink new_invite_link(std::move(action->new_invite_), "channelAdminLogEventActionExportedInviteEdit"); if (!old_invite_link.is_valid() || !new_invite_link.is_valid()) { LOG(ERROR) << "Wrong edited invite link: " << old_invite_link << " -> " << new_invite_link; return nullptr; @@ -269,7 +269,7 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionExportedInviteRevoke::ID: { auto action = move_tl_object_as(action_ptr); - DialogInviteLink invite_link(std::move(action->invite_)); + DialogInviteLink invite_link(std::move(action->invite_), "channelAdminLogEventActionExportedInviteRevoke"); if (!invite_link.is_valid()) { LOG(ERROR) << "Wrong revoked invite link: " << invite_link; return nullptr; @@ -279,7 +279,7 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionExportedInviteDelete::ID: { auto action = move_tl_object_as(action_ptr); - DialogInviteLink invite_link(std::move(action->invite_)); + DialogInviteLink invite_link(std::move(action->invite_), "channelAdminLogEventActionExportedInviteDelete"); if (!invite_link.is_valid()) { LOG(ERROR) << "Wrong deleted invite link: " << invite_link; return nullptr; diff --git a/td/telegram/DialogInviteLink.cpp b/td/telegram/DialogInviteLink.cpp index 0f24de00a..b5dbc9f71 100644 --- a/td/telegram/DialogInviteLink.cpp +++ b/td/telegram/DialogInviteLink.cpp @@ -13,12 +13,13 @@ namespace td { -DialogInviteLink::DialogInviteLink(tl_object_ptr exported_invite_ptr) { +DialogInviteLink::DialogInviteLink(tl_object_ptr exported_invite_ptr, + const char *source) { if (exported_invite_ptr == nullptr) { return; } if (exported_invite_ptr->get_id() != telegram_api::chatInviteExported::ID) { - LOG(ERROR) << "Receive " << to_string(exported_invite_ptr); + LOG(ERROR) << "Receive from " << source << ' ' << to_string(exported_invite_ptr); return; } @@ -36,39 +37,40 @@ DialogInviteLink::DialogInviteLink(tl_object_ptrrevoked_; is_permanent_ = exported_invite->permanent_; - LOG_IF(ERROR, !is_valid_invite_link(invite_link_)) << "Unsupported invite link " << invite_link_; + string full_source = PSTRING() << "invite link " << invite_link_ << " from " << source; + LOG_IF(ERROR, !is_valid_invite_link(invite_link_)) << "Unsupported " << full_source; if (!creator_user_id_.is_valid()) { - LOG(ERROR) << "Receive invalid " << creator_user_id_ << " as creator of a link " << invite_link_; + LOG(ERROR) << "Receive invalid " << creator_user_id_ << " as creator of " << full_source; creator_user_id_ = UserId(); } if (date_ != 0 && date_ < 1000000000) { - LOG(ERROR) << "Receive wrong date " << date_ << " as a creation date of a link " << invite_link_; + LOG(ERROR) << "Receive wrong date " << date_ << " as a creation date of " << full_source; date_ = 0; } if (expire_date_ != 0 && expire_date_ < 1000000000) { - LOG(ERROR) << "Receive wrong date " << expire_date_ << " as an expire date of a link " << invite_link_; + LOG(ERROR) << "Receive wrong date " << expire_date_ << " as an expire date of " << full_source; expire_date_ = 0; } if (usage_limit_ < 0) { - LOG(ERROR) << "Receive wrong usage limit " << usage_limit_ << " for a link " << invite_link_; + LOG(ERROR) << "Receive wrong usage limit " << usage_limit_ << " for " << full_source; usage_limit_ = 0; } if (usage_count_ < 0) { - LOG(ERROR) << "Receive wrong usage count " << usage_count_ << " for a link " << invite_link_; + LOG(ERROR) << "Receive wrong usage count " << usage_count_ << " for " << full_source; usage_count_ = 0; } if (edit_date_ != 0 && edit_date_ < 1000000000) { - LOG(ERROR) << "Receive wrong date " << edit_date_ << " as an edit date of a link " << invite_link_; + LOG(ERROR) << "Receive wrong date " << edit_date_ << " as an edit date of " << full_source; edit_date_ = 0; } if (request_count_ < 0) { - LOG(ERROR) << "Receive wrong pending join request count " << request_count_ << " for a link " << invite_link_; + LOG(ERROR) << "Receive wrong pending join request count " << request_count_ << " for " << full_source; request_count_ = 0; } if (is_permanent_ && (!title_.empty() || expire_date_ > 0 || usage_limit_ > 0 || edit_date_ > 0 || request_count_ > 0 || creates_join_request_)) { - LOG(ERROR) << "Receive wrong permanent " << *this; + LOG(ERROR) << "Receive wrong permanent " << full_source << ' ' << *this; title_.clear(); expire_date_ = 0; usage_limit_ = 0; @@ -77,7 +79,7 @@ DialogInviteLink::DialogInviteLink(tl_object_ptr 0) { - LOG(ERROR) << "Receive wrong permanent " << *this; + LOG(ERROR) << "Receive wrong permanent " << full_source << ' ' << *this; usage_limit_ = 0; } } diff --git a/td/telegram/DialogInviteLink.h b/td/telegram/DialogInviteLink.h index fff6f92cd..813717f64 100644 --- a/td/telegram/DialogInviteLink.h +++ b/td/telegram/DialogInviteLink.h @@ -40,7 +40,7 @@ class DialogInviteLink { public: DialogInviteLink() = default; - explicit DialogInviteLink(tl_object_ptr exported_invite_ptr); + DialogInviteLink(tl_object_ptr exported_invite_ptr, const char *source); static bool is_valid_invite_link(Slice invite_link); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 1f789cd1c..9c8c1e898 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -2282,27 +2282,27 @@ void UpdatesManager::process_qts_update(tl_object_ptr &&up } case telegram_api::updateChatParticipant::ID: { auto update = move_tl_object_as(update_ptr); - td_->contacts_manager_->on_update_chat_participant(ChatId(update->chat_id_), UserId(update->actor_id_), - update->date_, DialogInviteLink(std::move(update->invite_)), - std::move(update->prev_participant_), - std::move(update->new_participant_)); + td_->contacts_manager_->on_update_chat_participant( + ChatId(update->chat_id_), UserId(update->actor_id_), update->date_, + DialogInviteLink(std::move(update->invite_), "updateChatParticipant"), std::move(update->prev_participant_), + std::move(update->new_participant_)); add_qts(qts).set_value(Unit()); break; } case telegram_api::updateChannelParticipant::ID: { auto update = move_tl_object_as(update_ptr); - td_->contacts_manager_->on_update_channel_participant(ChannelId(update->channel_id_), UserId(update->actor_id_), - update->date_, DialogInviteLink(std::move(update->invite_)), - std::move(update->prev_participant_), - std::move(update->new_participant_)); + td_->contacts_manager_->on_update_channel_participant( + ChannelId(update->channel_id_), UserId(update->actor_id_), update->date_, + DialogInviteLink(std::move(update->invite_), "updateChannelParticipant"), + std::move(update->prev_participant_), std::move(update->new_participant_)); add_qts(qts).set_value(Unit()); break; } case telegram_api::updateBotChatInviteRequester::ID: { auto update = move_tl_object_as(update_ptr); - td_->contacts_manager_->on_update_chat_invite_requester(DialogId(update->peer_), UserId(update->user_id_), - std::move(update->about_), update->date_, - DialogInviteLink(std::move(update->invite_))); + td_->contacts_manager_->on_update_chat_invite_requester( + DialogId(update->peer_), UserId(update->user_id_), std::move(update->about_), update->date_, + DialogInviteLink(std::move(update->invite_), "updateBotChatInviteRequester")); add_qts(qts).set_value(Unit()); break; }