2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01: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/logevent/SecretChatEvent.h"
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/telegram/secret_api.h"
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/telegram/SecretChatActor.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/SecretChatId.h"
|
2020-06-30 11:11:22 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/telegram/UserId.h"
|
2020-06-30 11:11:22 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2020-08-14 21:51:10 +02:00
|
|
|
#include "td/utils/common.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Time.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace td {
|
2019-01-06 20:11:02 +01:00
|
|
|
|
|
|
|
struct BinlogEvent;
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class SecretChatsManager final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2023-03-13 18:35:19 +01:00
|
|
|
SecretChatsManager(ActorShared<> parent, bool use_secret_chats);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-07-20 12:40:14 +02:00
|
|
|
// proxy query to corresponding SecretChatActor
|
2018-12-31 20:04:05 +01:00
|
|
|
void on_update_chat(tl_object_ptr<telegram_api::updateEncryption> update);
|
2020-08-02 21:07:22 +02:00
|
|
|
void on_new_message(tl_object_ptr<telegram_api::EncryptedMessage> &&message_ptr, Promise<Unit> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-03-29 10:57:26 +02:00
|
|
|
void create_chat(UserId user_id, int64 user_access_hash, Promise<SecretChatId> promise);
|
2021-01-18 13:04:31 +01:00
|
|
|
void cancel_chat(SecretChatId secret_chat_id, bool delete_history, Promise<> promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
void send_message(SecretChatId secret_chat_id, tl_object_ptr<secret_api::decryptedMessage> message,
|
|
|
|
tl_object_ptr<telegram_api::InputEncryptedFile> file, Promise<> promise);
|
|
|
|
void send_message_action(SecretChatId secret_chat_id, tl_object_ptr<secret_api::SendMessageAction> action);
|
|
|
|
void send_read_history(SecretChatId secret_chat_id, int32 date, Promise<> promise);
|
|
|
|
void send_open_message(SecretChatId secret_chat_id, int64 random_id, Promise<> promise);
|
|
|
|
void delete_messages(SecretChatId secret_chat_id, vector<int64> random_ids, Promise<> promise);
|
|
|
|
void delete_all_messages(SecretChatId secret_chat_id, Promise<> promise);
|
|
|
|
void notify_screenshot_taken(SecretChatId secret_chat_id, Promise<> promise);
|
|
|
|
void send_set_ttl_message(SecretChatId secret_chat_id, int32 ttl, int64 random_id, Promise<> promise);
|
|
|
|
|
2021-06-02 14:43:56 +02:00
|
|
|
// binlog replay
|
2018-12-31 20:04:05 +01:00
|
|
|
void replay_binlog_event(BinlogEvent &&binlog_event);
|
|
|
|
void binlog_replay_finish();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool binlog_replay_finish_flag_ = false;
|
2023-03-13 18:35:19 +01:00
|
|
|
bool use_secret_chats_ = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
bool close_flag_ = false;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
std::map<int32, ActorOwn<SecretChatActor>> id_to_actor_;
|
|
|
|
|
|
|
|
bool is_online_{false};
|
|
|
|
|
|
|
|
std::vector<std::pair<Timestamp, telegram_api::object_ptr<telegram_api::updateEncryption>>> pending_chat_updates_;
|
|
|
|
void flush_pending_chat_updates();
|
|
|
|
void do_update_chat(tl_object_ptr<telegram_api::updateEncryption> update);
|
|
|
|
|
2020-09-22 01:15:09 +02:00
|
|
|
void replay_inbound_message(unique_ptr<log_event::InboundSecretMessage> message);
|
|
|
|
void add_inbound_message(unique_ptr<log_event::InboundSecretMessage> message);
|
|
|
|
void replay_outbound_message(unique_ptr<log_event::OutboundSecretMessage> message);
|
|
|
|
void replay_close_chat(unique_ptr<log_event::CloseSecretChat> message);
|
|
|
|
void replay_create_chat(unique_ptr<log_event::CreateSecretChat> message);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-09-27 03:19:03 +02:00
|
|
|
unique_ptr<SecretChatActor::Context> make_secret_chat_context(int32 id);
|
2018-12-31 20:04:05 +01:00
|
|
|
ActorId<SecretChatActor> get_chat_actor(int32 id);
|
|
|
|
ActorId<SecretChatActor> create_chat_actor(int32 id);
|
|
|
|
ActorId<SecretChatActor> create_chat_actor_impl(int32 id, bool can_be_empty);
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final;
|
|
|
|
void hangup() final;
|
|
|
|
void hangup_shared() final;
|
|
|
|
void timeout_expired() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void on_online(bool is_online);
|
|
|
|
};
|
|
|
|
} // namespace td
|