tdesktop/Telegram/SourceFiles/data/business/data_business_chatbots.h

71 lines
1.5 KiB
C
Raw Normal View History

2024-02-20 12:02:02 +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
#include "data/business/data_business_common.h"
class UserData;
namespace Data {
class Session;
struct ChatbotsSettings {
UserData *bot = nullptr;
BusinessRecipients recipients;
2024-02-20 12:02:02 +00:00
bool repliesAllowed = false;
friend inline bool operator==(
const ChatbotsSettings &,
const ChatbotsSettings &) = default;
2024-02-20 12:02:02 +00:00
};
class Chatbots final {
public:
explicit Chatbots(not_null<Session*> owner);
2024-02-20 12:02:02 +00:00
~Chatbots();
void preload();
[[nodiscard]] bool loaded() const;
2024-02-20 12:02:02 +00:00
[[nodiscard]] const ChatbotsSettings &current() const;
[[nodiscard]] rpl::producer<ChatbotsSettings> changes() const;
[[nodiscard]] rpl::producer<ChatbotsSettings> value() const;
void save(
ChatbotsSettings settings,
Fn<void()> done,
Fn<void(QString)> fail);
2024-02-20 12:02:02 +00:00
2024-03-18 11:02:12 +00:00
void togglePaused(not_null<PeerData*> peer, bool paused);
void removeFrom(not_null<PeerData*> peer);
2024-02-20 12:02:02 +00:00
private:
2024-03-18 11:02:12 +00:00
enum class SentRequestType {
Pause,
Unpause,
Remove,
};
struct SentRequest {
SentRequestType type = SentRequestType::Pause;
mtpRequestId requestId = 0;
};
void reload();
const not_null<Session*> _owner;
2024-02-20 12:02:02 +00:00
rpl::variable<ChatbotsSettings> _settings;
mtpRequestId _requestId = 0;
bool _loaded = false;
2024-02-20 12:02:02 +00:00
2024-03-18 11:02:12 +00:00
base::flat_map<not_null<PeerData*>, SentRequest> _sentRequests;
2024-02-20 12:02:02 +00:00
};
} // namespace Data