feat: resolve user by tg://user?id=

Just found another use of `searchById`, so why not.

Co-authored-by: c0re100 <corehusky@gmail.com>
This commit is contained in:
ZavaruKitsu 2024-01-03 20:36:32 +03:00
parent fba53e1ec8
commit 7426d285b4
7 changed files with 93 additions and 1 deletions

View file

@ -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

View file

@ -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";

View file

@ -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<PeerId>(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;
}
}

View file

@ -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);
}

View file

@ -44,4 +44,5 @@ QString getMediaName(not_null<HistoryItem *> message);
QString getMediaResolution(not_null<HistoryItem *> message);
QString getMediaDC(not_null<HistoryItem *> message);
void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback);
void searchById(ID userId, Main::Session *session, const Callback& callback);

View file

@ -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;
}

View file

@ -58,6 +58,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QGuiApplication>
// AyuGram includes
#include "ayu/ayu_url_handlers.h"
namespace Core {
namespace {
@ -995,6 +999,10 @@ const std::vector<LocalUrlHandler> &LocalUrlHandlers() {
u"^boost/?\\?(.+)(#|$)"_q,
ResolveBoost,
},
{
u"^user\\?(.+)(#|$)"_q,
AyuUrlHandlers::ResolveUser
},
{
u"^([^\\?]+)(\\?|#|$)"_q,
HandleUnknown