From ffa8a9418057de66b8e889a4ca74c475ca6c0549 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 9 Oct 2022 14:25:47 +0300 Subject: [PATCH] Added usernames info to UserData. --- Telegram/SourceFiles/data/data_session.cpp | 10 ++++++++++ Telegram/SourceFiles/data/data_user.cpp | 15 +++++++++++++++ Telegram/SourceFiles/data/data_user.h | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 1b4979ea1c..1d362c09d1 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "api/api_bot.h" #include "api/api_text_entities.h" +#include "api/api_user_names.h" #include "core/application.h" #include "core/core_settings.h" #include "core/mime_type.h" // Core::IsMimeSticker @@ -583,6 +584,15 @@ not_null Session::processUser(const MTPUser &data) { result->setAccessHash(accessHash->v); } status = data.vstatus(); + { + const auto newUsername = uname; + const auto newUsernames = data.vusernames() + ? Api::Usernames::FromTL(*data.vusernames()) + : !newUsername.isEmpty() + ? Data::Usernames{{ newUsername, true, true }} + : Data::Usernames(); + result->setUsernames(newUsernames); + } } if (const auto &status = data.vemoji_status()) { result->setEmojiStatus(*status); diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index d3a0d6a1db..e8515a8284 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_changes.h" #include "data/data_peer_bot_command.h" #include "data/data_emoji_statuses.h" +#include "data/data_user_names.h" #include "data/notify/data_notify_settings.h" #include "ui/text/text_options.h" #include "lang/lang_keys.h" @@ -119,6 +120,16 @@ void UserData::setName(const QString &newFirstName, const QString &newLastName, updateNameDelayed(newFullName, newPhoneName, newUsername); } +void UserData::setUsernames(const Data::Usernames &usernames) { + _usernames = ranges::views::all( + usernames + ) | ranges::views::filter([&](const Data::Username &username) { + return username.active; + }) | ranges::views::transform([&](const Data::Username &username) { + return username.username; + }) | ranges::to_vector; +} + void UserData::setUsername(const QString &username) { if (_username != username) { _username = username; @@ -291,6 +302,10 @@ const QString &UserData::username() const { return _username; } +const std::vector &UserData::usernames() const { + return _usernames; +} + const QString &UserData::phone() const { return _phone; } diff --git a/Telegram/SourceFiles/data/data_user.h b/Telegram/SourceFiles/data/data_user.h index c078f6061f..1e7afce001 100644 --- a/Telegram/SourceFiles/data/data_user.h +++ b/Telegram/SourceFiles/data/data_user.h @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Data { struct BotCommand; +struct Username; } // namespace Data struct BotInfo { @@ -73,6 +74,7 @@ public: const QString &newLastName, const QString &newPhoneName, const QString &newUsername); + void setUsernames(const std::vector &usernames); void setEmojiStatus(DocumentId emojiStatusId, TimeId until = 0); [[nodiscard]] DocumentId emojiStatusId() const; @@ -129,6 +131,7 @@ public: QString lastName; [[nodiscard]] const QString &phone() const; [[nodiscard]] const QString &username() const; + [[nodiscard]] const std::vector &usernames() const; QString nameOrPhone; TimeId onlineTill = 0; @@ -172,6 +175,8 @@ private: CallsStatus _callsStatus = CallsStatus::Unknown; int _commonChatsCount = 0; + std::vector _usernames; + uint64 _accessHash = 0; static constexpr auto kInaccessibleAccessHashOld = 0xFFFFFFFFFFFFFFFFULL;