From 75bcd2b24b13ad123000418158bc31eafd7d30aa Mon Sep 17 00:00:00 2001 From: AlexeyZavar <sltkval1@gmail.com> Date: Mon, 1 Jul 2024 04:58:39 +0300 Subject: [PATCH] feat: show DC for users --- .../ayu/utils/telegram_helpers.cpp | 44 +++++++++++++++++++ .../SourceFiles/ayu/utils/telegram_helpers.h | 2 + .../info/profile/info_profile_actions.cpp | 6 ++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp index 8a6969367..62eb2787b 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp @@ -517,6 +517,50 @@ QString getMediaDC(not_null<HistoryItem*> message) { return {}; } +QString getUserDC(not_null<UserData*> user) { + if (user->hasUserpic()) { + const auto dc = v::match( + user->userpicLocation().file().data, + [&](const StorageFileLocation &data) + { + return data.dcId(); + }, + [&](const WebFileLocation &) + { + // should't happen, but still + // all webpages are on DC4 + return 4; + }, + [&](const GeoPointLocation &) + { + // shouldn't happen naturally + return 0; + }, + [&](const AudioAlbumThumbLocation &) + { + // shouldn't happen naturally + return 0; + }, + [&](const PlainUrlLocation &) + { + // should't happen, but still + // all webpages are on DC4 + return 4; + }, + [&](const InMemoryLocation &) + { + // shouldn't happen naturally + return 0; + }); + + if (dc > 0) { + return getDCName(dc); + } + } + + return {}; +} + int getScheduleTime(int64 sumSize) { auto time = 12; time += (int) std::ceil(std::max(6.0, std::ceil(sumSize / 1024.0 / 1024.0 * 0.7))) + 1; diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.h b/Telegram/SourceFiles/ayu/utils/telegram_helpers.h index f530dcb6d..f026f3542 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.h +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.h @@ -43,6 +43,8 @@ QString getMediaName(not_null<HistoryItem*> message); QString getMediaResolution(not_null<HistoryItem*> message); QString getMediaDC(not_null<HistoryItem*> message); +QString getUserDC(not_null<UserData*> user); + int getScheduleTime(int64 sumSize); void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index f2d044e49..ea1b66983 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -79,6 +79,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ayu_settings.h" #include "ayu/ui/utils/ayu_profile_values.h" +#include "ayu/utils/telegram_helpers.h" #include "ui/text/text_entity.h" @@ -1155,6 +1156,9 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() { } if (settings->showPeerId != 0) { + const auto dataCenter = getUserDC(user); + const auto idLabel = dataCenter.isEmpty() ? QString("ID") : dataCenter; + auto idDrawableText = IDValue( user ) | rpl::map([](TextWithEntities &&text) @@ -1162,7 +1166,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() { return Ui::Text::Code(text.text); }); auto idInfo = addInfoOneLine( - rpl::single(QString("ID")), + rpl::single(idLabel), std::move(idDrawableText), tr::ayu_ContextCopyID(tr::now) );