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;
|
|
|
|
|
2022-09-02 16:07:53 +00:00
|
|
|
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);
|
|
|
|
|
2021-11-09 17:04:42 +00:00
|
|
|
bool shouldChoose(not_null<PeerData*> peer);
|
2021-11-29 05:24:38 +00:00
|
|
|
void refresh(not_null<PeerData*> peer, bool force = false);
|
2022-09-02 16:07:53 +00:00
|
|
|
[[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;
|
2021-11-28 12:26:34 +00:00
|
|
|
|
|
|
|
// 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,
|
2022-09-02 16:07:53 +00:00
|
|
|
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;
|
2022-09-02 16:07:53 +00:00
|
|
|
const std::vector<SendAsPeer> _onlyMe;
|
2021-11-09 12:10:51 +00:00
|
|
|
|
2022-09-02 16:07:53 +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;
|
|
|
|
|
2021-11-28 12:26:34 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2021-11-09 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Main
|