tdlight/td/telegram/AttachMenuManager.h

159 lines
4.6 KiB
C
Raw Normal View History

2022-03-25 12:17:09 +01:00
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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
2022-03-31 14:05:08 +02:00
#include "td/telegram/DialogId.h"
2022-03-25 14:00:06 +01:00
#include "td/telegram/files/FileId.h"
2022-03-31 14:05:08 +02:00
#include "td/telegram/MessageId.h"
2022-03-25 12:17:09 +01:00
#include "td/telegram/td_api.h"
2022-03-25 14:00:06 +01:00
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
2022-03-25 12:17:09 +01:00
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
2022-03-31 23:00:50 +02:00
#include "td/actor/Timeout.h"
2022-03-25 12:17:09 +01:00
#include "td/utils/common.h"
2022-04-07 19:38:22 +02:00
#include "td/utils/FlatHashMap.h"
2022-03-25 14:00:06 +01:00
#include "td/utils/Status.h"
2022-03-25 12:17:09 +01:00
namespace td {
class Td;
class AttachMenuManager final : public Actor {
public:
AttachMenuManager(Td *td, ActorShared<> parent);
2022-03-25 14:00:06 +01:00
void init();
2022-03-31 14:05:08 +02:00
void request_web_view(DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id, string &&url,
2022-04-07 17:29:59 +02:00
td_api::object_ptr<td_api::themeParameters> &&theme,
2022-03-31 15:42:59 +02:00
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise);
2022-03-31 14:05:08 +02:00
void open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id,
DialogId as_dialog_id);
2022-03-31 20:45:35 +02:00
void close_web_view(int64 query_id, Promise<Unit> &&promise);
void reload_attach_menu_bots(Promise<Unit> &&promise);
2022-03-25 14:00:06 +01:00
2022-04-14 21:56:27 +02:00
void get_attach_menu_bot(UserId user_id, Promise<td_api::object_ptr<td_api::attachmentMenuBot>> &&promise);
2022-03-29 14:00:00 +02:00
void toggle_bot_is_added_to_attach_menu(UserId user_id, bool is_added, Promise<Unit> &&promise);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
2022-03-25 14:00:06 +01:00
2022-03-25 12:17:09 +01:00
private:
2022-03-31 23:00:50 +02:00
static const int32 PING_WEB_VIEW_TIMEOUT = 60;
2022-03-25 14:00:06 +01:00
void start_up() final;
2022-03-25 12:17:09 +01:00
2022-03-25 16:10:25 +01:00
void timeout_expired() final;
2022-03-25 12:17:09 +01:00
void tear_down() final;
2022-03-31 11:07:19 +02:00
struct AttachMenuBotColor {
int32 light_color_ = -1;
int32 dark_color_ = -1;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
friend bool operator==(const AttachMenuBotColor &lhs, const AttachMenuBotColor &rhs);
friend bool operator!=(const AttachMenuBotColor &lhs, const AttachMenuBotColor &rhs);
2022-03-25 14:00:06 +01:00
struct AttachMenuBot {
bool is_added_ = false;
2022-03-25 14:00:06 +01:00
UserId user_id_;
2022-04-26 17:59:08 +02:00
bool supports_self_dialog_ = false;
bool supports_user_dialogs_ = false;
bool supports_bot_dialogs_ = false;
bool supports_group_dialogs_ = false;
bool supports_broadcast_dialogs_ = false;
2022-05-31 16:57:57 +02:00
bool supports_settings_ = false;
2022-03-25 14:00:06 +01:00
string name_;
2022-03-31 11:07:19 +02:00
AttachMenuBotColor name_color_;
2022-03-25 14:00:06 +01:00
FileId default_icon_file_id_;
FileId ios_static_icon_file_id_;
FileId ios_animated_icon_file_id_;
FileId android_icon_file_id_;
FileId macos_icon_file_id_;
2022-03-31 11:07:19 +02:00
AttachMenuBotColor icon_color_;
FileId placeholder_file_id_;
static constexpr uint32 CACHE_VERSION = 1;
uint32 cache_version_ = 0;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
2022-03-25 14:00:06 +01:00
};
class AttachMenuBotsLogEvent;
2022-03-25 14:00:06 +01:00
friend bool operator==(const AttachMenuBot &lhs, const AttachMenuBot &rhs);
friend bool operator!=(const AttachMenuBot &lhs, const AttachMenuBot &rhs);
2022-03-31 23:00:50 +02:00
bool is_active() const;
void on_online(bool is_online);
static void ping_web_view_static(void *td_void);
void ping_web_view();
void schedule_ping_web_view();
Result<AttachMenuBot> get_attach_menu_bot(tl_object_ptr<telegram_api::attachMenuBot> &&bot) const;
2022-04-14 21:56:27 +02:00
td_api::object_ptr<td_api::attachmentMenuBot> get_attachment_menu_bot_object(const AttachMenuBot &bot) const;
2022-03-29 13:03:06 +02:00
2022-04-14 21:56:27 +02:00
td_api::object_ptr<td_api::updateAttachmentMenuBots> get_update_attachment_menu_bots_object() const;
2022-03-25 14:00:06 +01:00
void remove_bot_from_attach_menu(UserId user_id);
2022-03-25 14:00:06 +01:00
void send_update_attach_menu_bots() const;
static string get_attach_menu_bots_database_key();
void save_attach_menu_bots();
void on_reload_attach_menu_bots(Result<telegram_api::object_ptr<telegram_api::AttachMenuBots>> &&result,
Promise<Unit> &&promise);
2022-03-29 14:00:00 +02:00
void on_get_attach_menu_bot(UserId user_id,
Result<telegram_api::object_ptr<telegram_api::attachMenuBotsBot>> &&result,
2022-04-14 21:56:27 +02:00
Promise<td_api::object_ptr<td_api::attachmentMenuBot>> &&promise);
2022-03-29 14:00:00 +02:00
2022-03-25 12:17:09 +01:00
Td *td_;
ActorShared<> parent_;
2022-03-25 14:00:06 +01:00
bool is_inited_ = false;
int64 hash_ = 0;
vector<AttachMenuBot> attach_menu_bots_;
2022-03-31 20:45:35 +02:00
struct OpenedWebView {
DialogId dialog_id_;
UserId bot_user_id_;
MessageId reply_to_message_id_;
DialogId as_dialog_id_;
2022-03-31 20:45:35 +02:00
};
FlatHashMap<int64, OpenedWebView> opened_web_views_;
2022-03-31 23:00:50 +02:00
Timeout ping_web_view_timeout_;
2022-03-25 12:17:09 +01:00
};
} // namespace td