2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Slightly improved appearing of usernames list.

This commit is contained in:
23rd
2022-10-12 21:16:04 +03:00
committed by John Preston
parent d55ff7aa4a
commit 17623640b3
5 changed files with 52 additions and 2 deletions

View File

@@ -199,5 +199,28 @@ Data::Usernames Usernames::FromTL(const MTPVector<MTPUsername> &usernames) {
) | ranges::views::transform(UsernameFromTL) | ranges::to_vector;
}
void Usernames::requestToCache(not_null<PeerData*> peer) {
_tinyCache = {};
if (const auto user = peer->asUser()) {
if (user->usernames().empty()) {
return;
}
} else if (const auto channel = peer->asChannel()) {
if (channel->usernames().empty()) {
return;
}
}
const auto lifetime = std::make_shared<rpl::lifetime>();
*lifetime = loadUsernames(
peer
) | rpl::start_with_next([=, id = peer->id](Data::Usernames usernames) {
_tinyCache = std::make_pair(id, std::move(usernames));
lifetime->destroy();
});
}
Data::Usernames Usernames::cacheFor(PeerId id) {
return (_tinyCache.first == id) ? _tinyCache.second : Data::Usernames();
}
} // namespace Api

View File

@@ -33,6 +33,9 @@ public:
not_null<PeerData*> peer,
const std::vector<QString> &usernames);
void requestToCache(not_null<PeerData*> peer);
[[nodiscard]] Data::Usernames cacheFor(PeerId id);
static Data::Usernames FromTL(const MTPVector<MTPUsername> &usernames);
private:
@@ -47,6 +50,8 @@ private:
};
base::flat_map<Key, Entry> _toggleRequests;
base::flat_map<Key, mtpRequestId> _reorderRequests;
// Used for a seamless display of usernames list.
std::pair<Key, Data::Usernames> _tinyCache;
};