Files
tdesktop/Telegram/SourceFiles/api/api_user_names.h
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
init
2026-02-16 15:50:16 +03:00

65 lines
1.4 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "data/data_user_names.h"
#include "mtproto/sender.h"
class ApiWrap;
class PeerData;
namespace Main {
class Session;
} // namespace Main
namespace Api {
class Usernames final {
public:
enum class Error {
TooMuch,
Flood,
Unknown,
};
explicit Usernames(not_null<ApiWrap*> api);
[[nodiscard]] rpl::producer<Data::Usernames> loadUsernames(
not_null<PeerData*> peer) const;
[[nodiscard]] rpl::producer<rpl::no_value, Error> toggle(
not_null<PeerData*> peer,
const QString &username,
bool active);
[[nodiscard]] rpl::producer<> reorder(
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:
const not_null<Main::Session*> _session;
MTP::Sender _api;
using Key = PeerId;
struct Entry final {
rpl::event_stream<rpl::no_value, Error> done;
std::vector<QString> usernames;
};
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;
};
} // namespace Api