Added usernames info to UserData.

This commit is contained in:
23rd 2022-10-09 14:25:47 +03:00 committed by John Preston
parent 51cead1445
commit ffa8a94180
3 changed files with 30 additions and 0 deletions

View File

@ -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<UserData*> 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);

View File

@ -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<QString> &UserData::usernames() const {
return _usernames;
}
const QString &UserData::phone() const {
return _phone;
}

View File

@ -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<Data::Username> &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<QString> &usernames() const;
QString nameOrPhone;
TimeId onlineTill = 0;
@ -172,6 +175,8 @@ private:
CallsStatus _callsStatus = CallsStatus::Unknown;
int _commonChatsCount = 0;
std::vector<QString> _usernames;
uint64 _accessHash = 0;
static constexpr auto kInaccessibleAccessHashOld
= 0xFFFFFFFFFFFFFFFFULL;