tdlight/td/telegram/BotInfoManager.h

111 lines
3.7 KiB
C
Raw Normal View History

2023-04-16 22:12:28 +02:00
//
2024-01-01 01:07:21 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
2023-04-16 22:12:28 +02:00
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/UserId.h"
2023-04-16 22:12:28 +02:00
#include "td/actor/actor.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
2023-04-16 22:12:28 +02:00
namespace td {
class Td;
class BotInfoManager final : public Actor {
public:
BotInfoManager(Td *td, ActorShared<> parent);
void set_default_group_administrator_rights(AdministratorRights administrator_rights, Promise<Unit> &&promise);
void set_default_channel_administrator_rights(AdministratorRights administrator_rights, Promise<Unit> &&promise);
2023-08-25 16:23:04 +02:00
void can_bot_send_messages(UserId bot_user_id, Promise<Unit> &&promise);
2023-08-25 17:06:56 +02:00
void allow_bot_to_send_messages(UserId bot_user_id, Promise<Unit> &&promise);
FileSourceId get_bot_media_preview_file_source_id(UserId bot_user_id);
2024-07-18 16:54:41 +02:00
void get_bot_media_previews(UserId bot_user_id, Promise<td_api::object_ptr<td_api::botMediaPreviews>> &&promise);
void reload_bot_media_previews(UserId bot_user_id, Promise<Unit> &&promise);
void set_bot_name(UserId bot_user_id, const string &language_code, const string &name, Promise<Unit> &&promise);
void get_bot_name(UserId bot_user_id, const string &language_code, Promise<string> &&promise);
void set_bot_info_description(UserId bot_user_id, const string &language_code, const string &description,
Promise<Unit> &&promise);
void get_bot_info_description(UserId bot_user_id, const string &language_code, Promise<string> &&promise);
void set_bot_info_about(UserId bot_user_id, const string &language_code, const string &about,
Promise<Unit> &&promise);
void get_bot_info_about(UserId bot_user_id, const string &language_code, Promise<string> &&promise);
2023-04-16 22:12:28 +02:00
private:
2023-04-17 11:23:21 +02:00
static constexpr double MAX_QUERY_DELAY = 0.01;
2023-04-17 12:28:26 +02:00
struct PendingSetBotInfoQuery {
UserId bot_user_id_;
string language_code_;
int type_ = 0;
string value_;
Promise<Unit> promise_;
PendingSetBotInfoQuery(UserId bot_user_id, const string &language_code, int type, const string &value,
Promise<Unit> &&promise)
: bot_user_id_(bot_user_id)
, language_code_(language_code)
, type_(type)
, value_(value)
, promise_(std::move(promise)) {
}
};
2023-04-17 11:23:21 +02:00
struct PendingGetBotInfoQuery {
UserId bot_user_id_;
string language_code_;
int type_ = 0;
Promise<string> promise_;
PendingGetBotInfoQuery(UserId bot_user_id, const string &language_code, int type, Promise<string> &&promise)
: bot_user_id_(bot_user_id), language_code_(language_code), type_(type), promise_(std::move(promise)) {
}
};
2023-04-16 22:12:28 +02:00
void tear_down() final;
2023-04-17 11:23:21 +02:00
void hangup() final;
void timeout_expired() final;
2024-07-18 16:54:41 +02:00
Result<telegram_api::object_ptr<telegram_api::InputUser>> get_media_preview_bot_input_user(
UserId user_id, bool can_be_edited = false);
2023-04-17 12:28:26 +02:00
void add_pending_set_query(UserId bot_user_id, const string &language_code, int type, const string &value,
Promise<Unit> &&promise);
2023-04-17 11:23:21 +02:00
void add_pending_get_query(UserId bot_user_id, const string &language_code, int type, Promise<string> &&promise);
2023-04-17 12:28:26 +02:00
vector<PendingSetBotInfoQuery> pending_set_bot_info_queries_;
2023-04-17 11:23:21 +02:00
vector<PendingGetBotInfoQuery> pending_get_bot_info_queries_;
FlatHashMap<UserId, FileSourceId, UserIdHash> bot_media_preview_file_source_ids_;
2023-04-16 22:12:28 +02:00
Td *td_;
ActorShared<> parent_;
};
} // namespace td