diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index d3ecde73e..9a4e03793 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -25,6 +25,7 @@ #include "td/telegram/GroupCallManager.h" #include "td/telegram/InlineQueriesManager.h" #include "td/telegram/InputGroupCallId.h" +#include "td/telegram/LinkManager.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/logevent/LogEventHelper.h" #include "td/telegram/MessagesManager.h" @@ -2139,7 +2140,7 @@ class CheckChatInviteQuery : public Td::ResultHandler { void send(const string &invite_link) { invite_link_ = invite_link; send_query(G()->net_query_creator().create( - telegram_api::messages_checkChatInvite(DialogInviteLink::get_dialog_invite_link_hash(invite_link_).str()))); + telegram_api::messages_checkChatInvite(LinkManager::get_dialog_invite_link_hash(invite_link_)))); } void on_result(uint64 id, BufferSlice packet) override { @@ -2171,7 +2172,7 @@ class ImportChatInviteQuery : public Td::ResultHandler { void send(const string &invite_link) { invite_link_ = invite_link; send_query(G()->net_query_creator().create( - telegram_api::messages_importChatInvite(DialogInviteLink::get_dialog_invite_link_hash(invite_link).str()))); + telegram_api::messages_importChatInvite(LinkManager::get_dialog_invite_link_hash(invite_link_)))); } void on_result(uint64 id, BufferSlice packet) override { diff --git a/td/telegram/DialogInviteLink.cpp b/td/telegram/DialogInviteLink.cpp index 565425b72..d64e4d975 100644 --- a/td/telegram/DialogInviteLink.cpp +++ b/td/telegram/DialogInviteLink.cpp @@ -7,18 +7,13 @@ #include "td/telegram/DialogInviteLink.h" #include "td/telegram/ContactsManager.h" +#include "td/telegram/LinkManager.h" #include "td/utils/logging.h" #include "td/utils/misc.h" namespace td { -const CSlice DialogInviteLink::INVITE_LINK_URLS[12] = { - "t.me/joinchat/", "telegram.me/joinchat/", "telegram.dog/joinchat/", - "t.me/+", "telegram.me/+", "telegram.dog/+", - "t.me/ ", "telegram.me/ ", "telegram.dog/ ", - "t.me/%20", "telegram.me/%20", "telegram.dog/%20"}; - DialogInviteLink::DialogInviteLink(tl_object_ptr exported_invite) { if (exported_invite == nullptr) { return; @@ -76,29 +71,7 @@ DialogInviteLink::DialogInviteLink(tl_object_ptr DialogInviteLink::get_chat_invite_link_object( diff --git a/td/telegram/DialogInviteLink.h b/td/telegram/DialogInviteLink.h index b09fedb75..1baedb5c8 100644 --- a/td/telegram/DialogInviteLink.h +++ b/td/telegram/DialogInviteLink.h @@ -34,8 +34,6 @@ class DialogInviteLink { friend StringBuilder &operator<<(StringBuilder &string_builder, const DialogInviteLink &invite_link); - static const CSlice INVITE_LINK_URLS[12]; - public: DialogInviteLink() = default; @@ -43,8 +41,6 @@ class DialogInviteLink { static bool is_valid_invite_link(Slice invite_link); - static Slice get_dialog_invite_link_hash(Slice invite_link); - td_api::object_ptr get_chat_invite_link_object(const ContactsManager *contacts_manager) const; bool is_valid() const { diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 3ac4b098c..12e6788af 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -591,4 +591,30 @@ void LinkManager::get_link_login_url(const string &url, bool allow_write_access, ->send(url, DialogId(), MessageId(), 0, allow_write_access); } +string LinkManager::get_dialog_invite_link_hash(Slice invite_link) { + auto link_info = LinkManager::get_link_info(invite_link); + if (!link_info.is_internal_) { + return string(); + } + const auto url_query = parse_url_query(link_info.query_); + const auto &path = url_query.path_; + + if (link_info.is_tg_) { + if (path.size() == 1 && path[0] == "join" && !url_query.get_arg("invite").empty()) { + // join?invite=abcdef + return url_query.get_arg("invite").str(); + } + } else { + if (path.size() >= 2 && path[0] == "joinchat" && !path[1].empty()) { + // /joinchat/ + return path[1]; + } + if (path.size() >= 1 && path[0].size() >= 2 && (path[0][0] == ' ' || path[0][0] == '+')) { + // /+ + return path[0].substr(1); + } + } + return string(); +} + } // namespace td diff --git a/td/telegram/LinkManager.h b/td/telegram/LinkManager.h index 8af5857b5..9e9d1b149 100644 --- a/td/telegram/LinkManager.h +++ b/td/telegram/LinkManager.h @@ -82,6 +82,8 @@ class LinkManager : public Actor { void get_link_login_url(const string &url, bool allow_write_access, Promise> &&promise); + static string get_dialog_invite_link_hash(Slice invite_link); + private: void tear_down() override; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 398eee2d7..59d398679 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -17383,6 +17383,7 @@ Result MessagesManager::get_message_link_info( if (!link_info.is_internal_) { return Status::Error("Invalid message link URL"); } + url = link_info.query_; Slice username; Slice channel_id_slice; @@ -17443,6 +17444,10 @@ Result MessagesManager::get_message_link_info( } else { // /c/123456789/12345 // /username/12345?single + + CHECK(!url.empty() && url[0] == '/'); + url.remove_prefix(1); + auto username_end_pos = url.find('/'); if (username_end_pos == Slice::npos) { return Status::Error("Wrong message link URL");