diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 8ec3ec67f..b382de02c 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1972,7 +1972,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), "ExportChatInviteQuery"); + DialogInviteLink invite_link(std::move(ptr), false, "ExportChatInviteQuery"); if (!invite_link.is_valid()) { return on_error(Status::Error(500, "Receive invalid invite link")); } @@ -2034,7 +2034,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_), "EditChatInviteLinkQuery"); + DialogInviteLink invite_link(std::move(invite->invite_), false, "EditChatInviteLinkQuery"); if (!invite_link.is_valid()) { return on_error(Status::Error(500, "Receive invalid invite link")); } @@ -2083,7 +2083,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_), "GetExportedChatInviteQuery"); + DialogInviteLink invite_link(std::move(result->invite_), false, "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")); @@ -2145,7 +2145,7 @@ class GetExportedChatInvitesQuery final : public Td::ResultHandler { } vector> invite_links; for (auto &invite : result->invites_) { - DialogInviteLink invite_link(std::move(invite), "GetExportedChatInvitesQuery"); + DialogInviteLink invite_link(std::move(invite), false, "GetExportedChatInvitesQuery"); if (!invite_link.is_valid()) { LOG(ERROR) << "Receive invalid invite link in " << dialog_id_; total_count--; @@ -2486,7 +2486,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_), "RevokeChatInviteLinkQuery"); + DialogInviteLink invite_link(std::move(invite->invite_), false, "RevokeChatInviteLinkQuery"); if (!invite_link.is_valid()) { return on_error(Status::Error(500, "Receive invalid invite link")); } @@ -2498,8 +2498,9 @@ 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_), "RevokeChatInviteLinkQuery replaced"); - DialogInviteLink new_invite_link(std::move(invite->new_invite_), "RevokeChatInviteLinkQuery new replaced"); + DialogInviteLink invite_link(std::move(invite->invite_), false, "RevokeChatInviteLinkQuery replaced"); + DialogInviteLink new_invite_link(std::move(invite->new_invite_), false, + "RevokeChatInviteLinkQuery new replaced"); if (!invite_link.is_valid() || !new_invite_link.is_valid()) { return on_error(Status::Error(500, "Receive invalid invite link")); } @@ -14304,7 +14305,8 @@ 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), "ChatFull"))) { + if (update_permanent_invite_link(chat_full->invite_link, + DialogInviteLink(std::move(invite_link), false, "ChatFull"))) { chat_full->is_changed = true; } } @@ -14313,7 +14315,7 @@ 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), "ChannelFull"))) { + DialogInviteLink(std::move(invite_link), false, "ChannelFull"))) { channel_full->is_changed = true; } } diff --git a/td/telegram/DialogEventLog.cpp b/td/telegram/DialogEventLog.cpp index 87fb649c6..bd153c4d4 100644 --- a/td/telegram/DialogEventLog.cpp +++ b/td/telegram/DialogEventLog.cpp @@ -41,7 +41,8 @@ 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_), "channelAdminLogEventActionParticipantJoinByInvite"); + DialogInviteLink invite_link(std::move(action->invite_), true, + "channelAdminLogEventActionParticipantJoinByInvite"); if (!invite_link.is_valid()) { LOG(ERROR) << "Wrong invite link: " << invite_link; return nullptr; @@ -51,7 +52,8 @@ 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_), "channelAdminLogEventActionParticipantJoinByRequest"); + DialogInviteLink invite_link(std::move(action->invite_), true, + "channelAdminLogEventActionParticipantJoinByRequest"); UserId approver_user_id(action->approved_by_); if (!approver_user_id.is_valid()) { return nullptr; @@ -259,8 +261,10 @@ 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_), "channelAdminLogEventActionExportedInviteEdit"); - DialogInviteLink new_invite_link(std::move(action->new_invite_), "channelAdminLogEventActionExportedInviteEdit"); + DialogInviteLink old_invite_link(std::move(action->prev_invite_), true, + "channelAdminLogEventActionExportedInviteEdit"); + DialogInviteLink new_invite_link(std::move(action->new_invite_), true, + "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; @@ -271,7 +275,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_), "channelAdminLogEventActionExportedInviteRevoke"); + DialogInviteLink invite_link(std::move(action->invite_), true, "channelAdminLogEventActionExportedInviteRevoke"); if (!invite_link.is_valid()) { LOG(ERROR) << "Wrong revoked invite link: " << invite_link; return nullptr; @@ -281,7 +285,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_), "channelAdminLogEventActionExportedInviteDelete"); + DialogInviteLink invite_link(std::move(action->invite_), true, "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 8ab2957d3..8ff77699c 100644 --- a/td/telegram/DialogInviteLink.cpp +++ b/td/telegram/DialogInviteLink.cpp @@ -15,7 +15,7 @@ namespace td { DialogInviteLink::DialogInviteLink(tl_object_ptr exported_invite_ptr, - const char *source) { + bool allow_truncated, const char *source) { if (exported_invite_ptr == nullptr) { return; } @@ -44,7 +44,7 @@ DialogInviteLink::DialogInviteLink(tl_object_ptrpermanent_; string full_source = PSTRING() << "invite link " << invite_link_ << " from " << source; - LOG_IF(ERROR, !is_valid_invite_link(invite_link_)) << "Unsupported " << full_source; + LOG_IF(ERROR, !is_valid_invite_link(invite_link_, allow_truncated)) << "Unsupported " << full_source; if (!creator_user_id_.is_valid()) { LOG(ERROR) << "Receive invalid " << creator_user_id_ << " as creator of " << full_source; creator_user_id_ = UserId(); @@ -90,7 +90,10 @@ DialogInviteLink::DialogInviteLink(tl_object_ptr exported_invite_ptr, const char *source); + DialogInviteLink(tl_object_ptr exported_invite_ptr, bool allow_truncated, + const char *source); - static bool is_valid_invite_link(Slice invite_link); + static bool is_valid_invite_link(Slice invite_link, bool allow_truncated = false); td_api::object_ptr get_chat_invite_link_object(const ContactsManager *contacts_manager) const; diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 9fd06732a..4dd0c3c38 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -1824,7 +1824,7 @@ Result LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp return "tg://settings/change_number"; case td_api::internalLinkTypeChatInvite::ID: { auto link = static_cast(type_ptr); - auto invite_hash = url_encode(get_dialog_invite_link_hash(link->invite_link_)); + auto invite_hash = get_dialog_invite_link_hash(link->invite_link_); if (invite_hash.empty()) { return Status::Error(400, "Invalid invite link specified"); } diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 7736cd1ed..0771aea2e 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -2639,8 +2639,8 @@ void UpdatesManager::process_qts_update(tl_object_ptr &&up 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_), "updateChatParticipant"), std::move(update->prev_participant_), - std::move(update->new_participant_)); + DialogInviteLink(std::move(update->invite_), true, "updateChatParticipant"), + std::move(update->prev_participant_), std::move(update->new_participant_)); add_qts(qts).set_value(Unit()); break; } @@ -2648,7 +2648,7 @@ void UpdatesManager::process_qts_update(tl_object_ptr &&up 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_), "updateChannelParticipant"), + DialogInviteLink(std::move(update->invite_), true, "updateChannelParticipant"), std::move(update->prev_participant_), std::move(update->new_participant_)); add_qts(qts).set_value(Unit()); break; @@ -2657,7 +2657,7 @@ void UpdatesManager::process_qts_update(tl_object_ptr &&up 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_), "updateBotChatInviteRequester")); + DialogInviteLink(std::move(update->invite_), true, "updateBotChatInviteRequester")); add_qts(qts).set_value(Unit()); break; }