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:
@@ -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
|
||||
|
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user