diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 806084ada..154b4a02c 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -96,6 +96,8 @@ nice_target_sources(Telegram ${src_loc} PRIVATE ${style_files} + ayu/ayu_url_handlers.cpp + ayu/ayu_url_handlers.h ayu/ayu_state.cpp ayu/ayu_state.h ayu/ayu_settings.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 576546ccd..97b30588e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4752,6 +4752,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_ViewFiltersMenuText" = "View Filters"; "ayu_PeekOnlineSuccess" = "Peeked via"; "ayu_OneViewTTL" = "one view"; +"ayu_OnePlayTTL" = "one play"; "ayu_UserMessagesMenuText" = "User Messages"; "ayu_ReadUntilMenuText" = "Read Message"; "ayu_DeleteKeepLocally" = "Keep locally"; @@ -4781,6 +4782,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_AyuForwardStatusLoadingMedia" = "Loading media…"; "ayu_AyuForwardForwardingDescription" = "Please keep this window open while AyuGram is forwarding your messages."; "ayu_AyuForwardLoadingMediaDescription" = "Please keep this window open while AyuGram is downloading media from your messages."; +"ayu_UserNotFoundMessage" = "User not found."; "ayu_DeleteDateMenuText" = "Delete Date"; "ayu_ReadDateMenuText" = "Read Date"; "ayu_ContentsReadDateMenuText" = "Contents Read Date"; diff --git a/Telegram/SourceFiles/ayu/ayu_url_handlers.cpp b/Telegram/SourceFiles/ayu/ayu_url_handlers.cpp new file mode 100644 index 000000000..5f079f5e8 --- /dev/null +++ b/Telegram/SourceFiles/ayu/ayu_url_handlers.cpp @@ -0,0 +1,57 @@ +// This is the source code of AyuGram for Desktop. +// +// We do not and cannot prevent the use of our code, +// but be respectful and credit the original author. +// +// Copyright @Radolyn, 2023 +#include "ayu/ayu_url_handlers.h" + +#include "base/qthelp_url.h" + +#include "lang_auto.h" +#include "ui/boxes/confirm_box.h" +#include "ayu/utils/telegram_helpers.h" +#include "boxes/abstract_box.h" +#include "core/application.h" +#include "data/data_session.h" +#include "data/data_user.h" + +namespace AyuUrlHandlers +{ + +bool ResolveUser( + Window::SessionController *controller, + const Match &match, + const QVariant &context) +{ + if (!controller) { + return false; + } + const auto params = url_parse_params( + match->captured(1), + qthelp::UrlParamNameTransform::ToLower); + const auto userId = params.value(qsl("id")).toLongLong(); + if (!userId) { + return false; + } + const auto peer = controller->session().data().peerLoaded(static_cast(userId)); + if (peer != nullptr) { + controller->showPeerInfo(peer); + return true; + } + + searchById(userId, &controller->session(), false, [=](const QString &title, UserData *data) + { + if (data) { + controller->showPeerInfo(data); + return; + } + + Core::App().hideMediaView(); + Ui::show(Ui::MakeInformBox(tr::ayu_UserNotFoundMessage())); + }); + + return true; +} + +} \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/ayu_url_handlers.h b/Telegram/SourceFiles/ayu/ayu_url_handlers.h new file mode 100644 index 000000000..6c025573a --- /dev/null +++ b/Telegram/SourceFiles/ayu/ayu_url_handlers.h @@ -0,0 +1,22 @@ +// This is the source code of AyuGram for Desktop. +// +// We do not and cannot prevent the use of our code, +// but be respectful and credit the original author. +// +// Copyright @Radolyn, 2023 +#pragma once + +#include "window/window_session_controller.h" +#include "base/qthelp_regex.h" + +namespace AyuUrlHandlers +{ + +using Match = qthelp::RegularExpressionMatch; + +bool ResolveUser( + Window::SessionController *controller, + const Match &match, + const QVariant &context); + +} \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.h b/Telegram/SourceFiles/ayu/utils/telegram_helpers.h index a2f05bd9c..92432ba53 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.h +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.h @@ -44,4 +44,5 @@ QString getMediaName(not_null message); QString getMediaResolution(not_null message); QString getMediaDC(not_null message); +void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback); void searchById(ID userId, Main::Session *session, const Callback& callback); diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 44a216842..26d9cb5aa 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -549,7 +549,7 @@ void StickerSetBox::updateButtons() { searchById(_inner->setId() >> 32, _session, [=](const QString &username, UserData *user) { if (!user) { - showToast(tr::ayu_MessageDetailsPackOwnerNotFoundPC(tr::now)); + showToast(tr::ayu_UserNotFoundMessage(tr::now)); return; } diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 68844669d..64c86668a 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -58,6 +58,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include +// AyuGram includes +#include "ayu/ayu_url_handlers.h" + + namespace Core { namespace { @@ -995,6 +999,10 @@ const std::vector &LocalUrlHandlers() { u"^boost/?\\?(.+)(#|$)"_q, ResolveBoost, }, + { + u"^user\\?(.+)(#|$)"_q, + AyuUrlHandlers::ResolveUser + }, { u"^([^\\?]+)(\\?|#|$)"_q, HandleUnknown