2024-01-02 14:22:25 +01:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
#include "td/telegram/AccentColorId.h"
|
|
|
|
#include "td/telegram/AccessRights.h"
|
2024-01-07 21:45:33 +01:00
|
|
|
#include "td/telegram/ChannelId.h"
|
2024-01-03 21:07:50 +01:00
|
|
|
#include "td/telegram/CustomEmojiId.h"
|
|
|
|
#include "td/telegram/DialogId.h"
|
2024-02-19 22:43:04 +01:00
|
|
|
#include "td/telegram/DialogLocation.h"
|
2024-01-03 21:07:50 +01:00
|
|
|
#include "td/telegram/DialogParticipant.h"
|
|
|
|
#include "td/telegram/EmojiStatus.h"
|
2024-01-04 18:44:12 +01:00
|
|
|
#include "td/telegram/files/FileId.h"
|
2024-01-04 14:20:15 +01:00
|
|
|
#include "td/telegram/InputDialogId.h"
|
2024-01-04 20:46:13 +01:00
|
|
|
#include "td/telegram/MessageId.h"
|
2024-01-03 21:07:50 +01:00
|
|
|
#include "td/telegram/NotificationSettingsScope.h"
|
|
|
|
#include "td/telegram/Photo.h"
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
2024-01-02 14:22:25 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2024-01-04 18:44:12 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2024-01-08 13:42:21 +01:00
|
|
|
#include "td/utils/FlatHashSet.h"
|
2024-01-03 21:07:50 +01:00
|
|
|
#include "td/utils/Promise.h"
|
|
|
|
#include "td/utils/Status.h"
|
2024-01-07 21:45:33 +01:00
|
|
|
#include "td/utils/WaitFreeHashMap.h"
|
2024-01-02 14:22:25 +01:00
|
|
|
|
2024-01-06 20:45:27 +01:00
|
|
|
#include <memory>
|
2024-01-04 14:46:53 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2024-01-02 14:22:25 +01:00
|
|
|
namespace td {
|
|
|
|
|
2024-01-04 20:46:13 +01:00
|
|
|
class ReportReason;
|
2024-01-02 14:22:25 +01:00
|
|
|
class Td;
|
2024-01-07 21:45:33 +01:00
|
|
|
class Usernames;
|
2024-01-02 14:22:25 +01:00
|
|
|
|
|
|
|
class DialogManager final : public Actor {
|
|
|
|
public:
|
|
|
|
DialogManager(Td *td, ActorShared<> parent);
|
2024-01-07 21:45:33 +01:00
|
|
|
DialogManager(const DialogManager &) = delete;
|
|
|
|
DialogManager &operator=(const DialogManager &) = delete;
|
|
|
|
DialogManager(DialogManager &&) = delete;
|
|
|
|
DialogManager &operator=(DialogManager &&) = delete;
|
|
|
|
~DialogManager() final;
|
2024-01-02 14:22:25 +01:00
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
DialogId get_my_dialog_id() const;
|
|
|
|
|
2024-01-04 14:20:15 +01:00
|
|
|
InputDialogId get_input_dialog_id(DialogId dialog_id) const;
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
tl_object_ptr<telegram_api::InputPeer> get_input_peer(DialogId dialog_id, AccessRights access_rights) const;
|
|
|
|
|
|
|
|
static tl_object_ptr<telegram_api::InputPeer> get_input_peer_force(DialogId dialog_id);
|
|
|
|
|
|
|
|
vector<tl_object_ptr<telegram_api::InputPeer>> get_input_peers(const vector<DialogId> &dialog_ids,
|
|
|
|
AccessRights access_rights) const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputDialogPeer> get_input_dialog_peer(DialogId dialog_id,
|
|
|
|
AccessRights access_rights) const;
|
|
|
|
|
|
|
|
vector<tl_object_ptr<telegram_api::InputDialogPeer>> get_input_dialog_peers(const vector<DialogId> &dialog_ids,
|
|
|
|
AccessRights access_rights) const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::inputEncryptedChat> get_input_encrypted_chat(DialogId dialog_id,
|
|
|
|
AccessRights access_rights) const;
|
|
|
|
|
|
|
|
bool have_input_peer(DialogId dialog_id, AccessRights access_rights) const;
|
|
|
|
|
|
|
|
bool have_dialog_force(DialogId dialog_id, const char *source) const;
|
|
|
|
|
2024-01-04 13:38:01 +01:00
|
|
|
void force_create_dialog(DialogId dialog_id, const char *source, bool expect_no_access = false,
|
|
|
|
bool force_update_dialog_pos = false);
|
|
|
|
|
2024-01-04 14:24:19 +01:00
|
|
|
vector<DialogId> get_peers_dialog_ids(vector<telegram_api::object_ptr<telegram_api::Peer>> &&peers,
|
|
|
|
bool expect_no_access = false);
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
bool have_dialog_info(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
bool have_dialog_info_force(DialogId dialog_id, const char *source) const;
|
|
|
|
|
2024-01-08 17:20:22 +01:00
|
|
|
void reload_dialog_info(DialogId dialog_id, Promise<Unit> &&promise);
|
|
|
|
|
2024-03-05 10:47:42 +01:00
|
|
|
bool is_dialog_info_received_from_server(DialogId dialog_id) const;
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
void get_dialog_info_full(DialogId dialog_id, Promise<Unit> &&promise, const char *source);
|
|
|
|
|
|
|
|
void reload_dialog_info_full(DialogId dialog_id, const char *source);
|
|
|
|
|
2024-01-04 17:52:31 +01:00
|
|
|
void on_dialog_info_full_invalidated(DialogId dialog_id);
|
|
|
|
|
2024-01-04 14:13:20 +01:00
|
|
|
int64 get_chat_id_object(DialogId dialog_id, const char *source) const;
|
|
|
|
|
|
|
|
vector<int64> get_chat_ids_object(const vector<DialogId> &dialog_ids, const char *source) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::chats> get_chats_object(int32 total_count, const vector<DialogId> &dialog_ids,
|
|
|
|
const char *source) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::chats> get_chats_object(const std::pair<int32, vector<DialogId>> &dialog_ids,
|
|
|
|
const char *source) const;
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
td_api::object_ptr<td_api::ChatType> get_chat_type_object(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
NotificationSettingsScope get_dialog_notification_setting_scope(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
bool is_anonymous_administrator(DialogId dialog_id, string *author_signature) const;
|
|
|
|
|
|
|
|
bool is_group_dialog(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
bool is_forum_channel(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
bool is_broadcast_channel(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
bool on_get_dialog_error(DialogId dialog_id, const Status &status, const char *source);
|
|
|
|
|
2024-01-07 23:27:49 +01:00
|
|
|
void delete_dialog(DialogId dialog_id, Promise<Unit> &&promise);
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
string get_dialog_title(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
const DialogPhoto *get_dialog_photo(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
int32 get_dialog_accent_color_id_object(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
CustomEmojiId get_dialog_background_custom_emoji_id(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
int32 get_dialog_profile_accent_color_id_object(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
CustomEmojiId get_dialog_profile_background_custom_emoji_id(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
RestrictedRights get_dialog_default_permissions(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::emojiStatus> get_dialog_emoji_status_object(DialogId dialog_id) const;
|
|
|
|
|
2024-02-18 23:10:57 +01:00
|
|
|
string get_dialog_about(DialogId dialog_id);
|
|
|
|
|
2024-02-24 21:47:30 +01:00
|
|
|
string get_dialog_search_text(DialogId dialog_id) const;
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
bool get_dialog_has_protected_content(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
bool is_dialog_action_unneeded(DialogId dialog_id) const;
|
|
|
|
|
2024-01-04 18:15:29 +01:00
|
|
|
void set_dialog_title(DialogId dialog_id, const string &title, Promise<Unit> &&promise);
|
|
|
|
|
2024-01-04 18:44:12 +01:00
|
|
|
void set_dialog_photo(DialogId dialog_id, const td_api::object_ptr<td_api::InputChatPhoto> &input_photo,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
void set_dialog_accent_color(DialogId dialog_id, AccentColorId accent_color_id,
|
|
|
|
CustomEmojiId background_custom_emoji_id, Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void set_dialog_profile_accent_color(DialogId dialog_id, AccentColorId profile_accent_color_id,
|
|
|
|
CustomEmojiId profile_background_custom_emoji_id, Promise<Unit> &&promise);
|
|
|
|
|
2024-01-04 18:20:18 +01:00
|
|
|
void set_dialog_permissions(DialogId dialog_id, const td_api::object_ptr<td_api::chatPermissions> &permissions,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
void set_dialog_emoji_status(DialogId dialog_id, const EmojiStatus &emoji_status, Promise<Unit> &&promise);
|
|
|
|
|
2024-01-04 18:25:41 +01:00
|
|
|
void toggle_dialog_has_protected_content(DialogId dialog_id, bool has_protected_content, Promise<Unit> &&promise);
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
void set_dialog_description(DialogId dialog_id, const string &description, Promise<Unit> &&promise);
|
|
|
|
|
2024-02-19 22:43:04 +01:00
|
|
|
void set_dialog_location(DialogId dialog_id, const DialogLocation &location, Promise<Unit> &&promise);
|
|
|
|
|
2024-01-04 20:46:13 +01:00
|
|
|
bool can_report_dialog(DialogId dialog_id) const;
|
|
|
|
|
|
|
|
void report_dialog(DialogId dialog_id, const vector<MessageId> &message_ids, ReportReason &&reason,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void report_dialog_photo(DialogId dialog_id, FileId file_id, ReportReason &&reason, Promise<Unit> &&promise);
|
|
|
|
|
2024-01-03 21:07:50 +01:00
|
|
|
Status can_pin_messages(DialogId dialog_id) const;
|
|
|
|
|
2024-01-04 14:32:04 +01:00
|
|
|
bool is_dialog_removed_from_dialog_list(DialogId dialog_id) const;
|
|
|
|
|
2024-01-04 18:44:12 +01:00
|
|
|
void upload_dialog_photo(DialogId dialog_id, FileId file_id, bool is_animation, double main_frame_timestamp,
|
|
|
|
bool is_reupload, Promise<Unit> &&promise, vector<int> bad_parts = {});
|
|
|
|
|
2024-01-07 21:45:33 +01:00
|
|
|
void on_dialog_usernames_updated(DialogId dialog_id, const Usernames &old_usernames, const Usernames &new_usernames);
|
|
|
|
|
|
|
|
void on_dialog_usernames_received(DialogId dialog_id, const Usernames &usernames, bool from_database);
|
|
|
|
|
2024-01-08 17:14:41 +01:00
|
|
|
enum class CheckDialogUsernameResult : uint8 {
|
|
|
|
Ok,
|
|
|
|
Invalid,
|
|
|
|
Occupied,
|
|
|
|
Purchasable,
|
|
|
|
PublicDialogsTooMany,
|
|
|
|
PublicGroupsUnavailable
|
|
|
|
};
|
|
|
|
void check_dialog_username(DialogId dialog_id, const string &username, Promise<CheckDialogUsernameResult> &&promise);
|
|
|
|
|
|
|
|
static td_api::object_ptr<td_api::CheckChatUsernameResult> get_check_chat_username_result_object(
|
|
|
|
CheckDialogUsernameResult result);
|
|
|
|
|
2024-01-07 21:45:33 +01:00
|
|
|
void resolve_dialog(const string &username, ChannelId channel_id, Promise<DialogId> promise);
|
|
|
|
|
|
|
|
DialogId get_resolved_dialog_by_username(const string &username) const;
|
|
|
|
|
|
|
|
DialogId resolve_dialog_username(const string &username, Promise<Unit> &promise);
|
|
|
|
|
|
|
|
DialogId search_public_dialog(const string &username_to_search, bool force, Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void reload_voice_chat_on_search(const string &username);
|
|
|
|
|
2024-01-02 14:22:25 +01:00
|
|
|
private:
|
2024-01-04 18:15:29 +01:00
|
|
|
static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title
|
|
|
|
|
2024-01-07 21:45:33 +01:00
|
|
|
static constexpr int32 USERNAME_CACHE_EXPIRE_TIME = 86400;
|
|
|
|
|
2024-01-02 14:22:25 +01:00
|
|
|
void tear_down() final;
|
|
|
|
|
2024-01-04 18:44:12 +01:00
|
|
|
void on_upload_dialog_photo(FileId file_id, telegram_api::object_ptr<telegram_api::InputFile> input_file);
|
|
|
|
|
|
|
|
void on_upload_dialog_photo_error(FileId file_id, Status status);
|
|
|
|
|
|
|
|
void send_edit_dialog_photo_query(DialogId dialog_id, FileId file_id,
|
|
|
|
telegram_api::object_ptr<telegram_api::InputChatPhoto> &&input_chat_photo,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2024-01-07 21:45:33 +01:00
|
|
|
void send_resolve_dialog_username_query(const string &username, Promise<Unit> &&promise);
|
|
|
|
|
2024-03-02 22:39:11 +01:00
|
|
|
void on_resolved_username(const string &username, Result<DialogId> r_dialog_id);
|
|
|
|
|
|
|
|
void drop_username(const string &username);
|
|
|
|
|
2024-01-07 21:45:33 +01:00
|
|
|
void on_resolve_dialog(const string &username, ChannelId channel_id, Promise<DialogId> &&promise);
|
|
|
|
|
2024-01-04 18:44:12 +01:00
|
|
|
class UploadDialogPhotoCallback;
|
|
|
|
std::shared_ptr<UploadDialogPhotoCallback> upload_dialog_photo_callback_;
|
|
|
|
|
|
|
|
struct UploadedDialogPhotoInfo {
|
|
|
|
DialogId dialog_id;
|
|
|
|
double main_frame_timestamp;
|
|
|
|
bool is_animation;
|
|
|
|
bool is_reupload;
|
|
|
|
Promise<Unit> promise;
|
|
|
|
|
|
|
|
UploadedDialogPhotoInfo(DialogId dialog_id, double main_frame_timestamp, bool is_animation, bool is_reupload,
|
|
|
|
Promise<Unit> promise)
|
|
|
|
: dialog_id(dialog_id)
|
|
|
|
, main_frame_timestamp(main_frame_timestamp)
|
|
|
|
, is_animation(is_animation)
|
|
|
|
, is_reupload(is_reupload)
|
|
|
|
, promise(std::move(promise)) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
FlatHashMap<FileId, UploadedDialogPhotoInfo, FileIdHash> being_uploaded_dialog_photos_;
|
|
|
|
|
2024-01-07 21:45:33 +01:00
|
|
|
struct ResolvedUsername {
|
|
|
|
DialogId dialog_id;
|
|
|
|
double expires_at = 0.0;
|
|
|
|
|
|
|
|
ResolvedUsername() = default;
|
|
|
|
ResolvedUsername(DialogId dialog_id, double expires_at) : dialog_id(dialog_id), expires_at(expires_at) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
WaitFreeHashMap<string, ResolvedUsername> resolved_usernames_;
|
|
|
|
WaitFreeHashMap<string, DialogId> inaccessible_resolved_usernames_;
|
|
|
|
FlatHashSet<string> reload_voice_chat_on_search_usernames_;
|
|
|
|
|
2024-03-02 22:39:11 +01:00
|
|
|
FlatHashMap<string, vector<Promise<Unit>>> resolve_dialog_username_queries_;
|
|
|
|
|
2024-01-02 14:22:25 +01:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|