tdesktop/Telegram/SourceFiles/main/session/send_as_peers.h

63 lines
1.7 KiB
C
Raw Normal View History

2021-11-09 12:10:51 +00:00
/*
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
class PeerData;
namespace Main {
class Session;
struct SendAsPeer {
not_null<PeerData*> peer;
bool premiumRequired = false;
friend inline auto operator<=>(SendAsPeer, SendAsPeer) = default;
};
2021-11-09 12:10:51 +00:00
class SendAsPeers final {
public:
explicit SendAsPeers(not_null<Session*> session);
bool shouldChoose(not_null<PeerData*> peer);
void refresh(not_null<PeerData*> peer, bool force = false);
[[nodiscard]] const std::vector<SendAsPeer> &list(
2021-11-09 13:50:33 +00:00
not_null<PeerData*> peer) const;
2021-11-09 12:10:51 +00:00
[[nodiscard]] rpl::producer<not_null<PeerData*>> updated() const;
2021-11-09 13:50:33 +00:00
void saveChosen(not_null<PeerData*> peer, not_null<PeerData*> chosen);
void setChosen(not_null<PeerData*> peer, PeerId chosenId);
[[nodiscard]] PeerId chosen(not_null<PeerData*> peer) const;
// If !list(peer).empty() then the result will be from that list.
2021-11-09 13:50:33 +00:00
[[nodiscard]] not_null<PeerData*> resolveChosen(
not_null<PeerData*> peer) const;
[[nodiscard]] static not_null<PeerData*> ResolveChosen(
not_null<PeerData*> peer,
const std::vector<SendAsPeer> &list,
2021-11-09 13:50:33 +00:00
PeerId chosen);
2021-11-09 12:10:51 +00:00
private:
void request(not_null<PeerData*> peer);
const not_null<Session*> _session;
const std::vector<SendAsPeer> _onlyMe;
2021-11-09 12:10:51 +00:00
base::flat_map<not_null<PeerData*>, std::vector<SendAsPeer>> _lists;
2021-11-09 12:10:51 +00:00
base::flat_map<not_null<PeerData*>, crl::time> _lastRequestTime;
2021-11-09 13:50:33 +00:00
base::flat_map<not_null<PeerData*>, PeerId> _chosen;
2021-11-09 12:10:51 +00:00
rpl::event_stream<not_null<PeerData*>> _updates;
rpl::lifetime _lifetime;
2021-11-09 12:10:51 +00:00
};
} // namespace Main