From 2804cc2d1e9ad4fffe6a24c972edf63e1a46aad0 Mon Sep 17 00:00:00 2001 From: AlexeyZavar Date: Wed, 15 Jan 2025 11:51:45 +0300 Subject: [PATCH] feat: improve stickerpack author Co-authored-by: kotecat --- Telegram/SourceFiles/ayu/ayu_url_handlers.cpp | 1 - .../ayu/ui/context_menu/context_menu.cpp | 4 ++-- .../ayu/ui/context_menu/menu_item_subtext.cpp | 9 +++++--- .../ayu/utils/telegram_helpers.cpp | 21 ++++++++++++------- .../SourceFiles/ayu/utils/telegram_helpers.h | 2 ++ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/ayu/ayu_url_handlers.cpp b/Telegram/SourceFiles/ayu/ayu_url_handlers.cpp index ff0a6cb5c..446b5a323 100644 --- a/Telegram/SourceFiles/ayu/ayu_url_handlers.cpp +++ b/Telegram/SourceFiles/ayu/ayu_url_handlers.cpp @@ -45,7 +45,6 @@ bool ResolveUser( searchById(userId, &controller->session(), - false, [=](const QString &title, UserData *data) { if (data) { diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp index 87bbe1b9e..d6b7c3623 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp +++ b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp @@ -391,7 +391,7 @@ void AddMessageDetailsAction(not_null menu, HistoryItem *item) { } if (isSticker) { - const auto authorId = media->document()->sticker()->set.id >> 32; + const auto authorId = getUserIdFromPackId(media->document()->sticker()->set.id); if (authorId != 0) { menu2->addAction(Ui::ContextActionStickerAuthor( @@ -404,7 +404,7 @@ void AddMessageDetailsAction(not_null menu, HistoryItem *item) { } if (containsSingleCustomEmojiPack) { - const auto authorId = emojiPacks.front().id >> 32; + const auto authorId = getUserIdFromPackId(emojiPacks.front().id); if (authorId != 0) { menu2->addAction(Ui::ContextActionStickerAuthor( diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/menu_item_subtext.cpp b/Telegram/SourceFiles/ayu/ui/context_menu/menu_item_subtext.cpp index d2cc1bbb1..797ec5ed6 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/menu_item_subtext.cpp +++ b/Telegram/SourceFiles/ayu/ui/context_menu/menu_item_subtext.cpp @@ -232,9 +232,12 @@ void ActionStickerPackAuthor::searchAuthor(ID authorId) { setClickedCallback( [=] { - const auto text = - QString("int32: %1\nint64: %2").arg(authorId).arg(0x100000000L + authorId); - QGuiApplication::clipboard()->setText(text); + QGuiApplication::clipboard()->setText(QString::number(authorId)); + if (const auto window = _session->tryResolveWindow()) { + if (const auto mainWidget = window->widget()->sessionController()) { + mainWidget->showToast(tr::ayu_IDCopiedToast(tr::now)); + } + } }); crl::on_main( diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp index a107a9d8f..07ddf4719 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp @@ -718,7 +718,7 @@ void searchUser(long long userId, Main::Session *session, bool searchUserFlag, c }).handleAllErrors().send(); } -void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback) { +void searchById(ID userId, Main::Session *session, const Callback &callback) { if (userId == 0 || !session) { callback(QString(), nullptr); return; @@ -737,15 +737,20 @@ void searchById(ID userId, Main::Session *session, bool retry, const Callback &c if (data && data->accessHash()) { callback(title, data); } else { - if (retry) { - searchById(0x100000000 + userId, session, false, callback); - } else { - callback(QString(), nullptr); - } + callback(QString(), nullptr); } }); } -void searchById(ID userId, Main::Session *session, const Callback &callback) { - searchById(userId, session, true, callback); +ID getUserIdFromPackId(uint64 id) { + // https://github.com/TDesktop-x64/tdesktop/pull/218/commits/844e5f0ab116e7639cfc79633a68afe8fdcbc463 + auto ownerId = id >> 32; + if ((id >> 16 & 0xff) == 0x3f) { + ownerId |= 0x80000000; + } + if (id >> 24 & 0xff) { + ownerId += 0x100000000; + } + + return ownerId; } diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.h b/Telegram/SourceFiles/ayu/utils/telegram_helpers.h index 47691c4fc..e057ade78 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.h +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.h @@ -47,3 +47,5 @@ int getScheduleTime(int64 sumSize); void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback); void searchById(ID userId, Main::Session *session, const Callback &callback); + +ID getUserIdFromPackId(uint64 id);