2024-02-21 18:43:55 +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-02-21 20:06:07 +01:00
|
|
|
#include "td/telegram/DialogId.h"
|
|
|
|
#include "td/telegram/MessageId.h"
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/UserId.h"
|
|
|
|
|
2024-02-21 18:43:55 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2024-02-21 20:06:07 +01:00
|
|
|
class Dependencies;
|
|
|
|
class MessageContent;
|
|
|
|
class MessageForwardInfo;
|
2024-02-21 18:43:55 +01:00
|
|
|
class Td;
|
|
|
|
|
|
|
|
class QuickReplyManager final : public Actor {
|
|
|
|
public:
|
|
|
|
QuickReplyManager(Td *td, ActorShared<> parent);
|
|
|
|
|
2024-02-22 15:32:12 +01:00
|
|
|
void get_quick_reply_shortcuts(Promise<td_api::object_ptr<td_api::quickReplyShortcuts>> &&promise);
|
|
|
|
|
|
|
|
void reload_quick_reply_shortcuts();
|
|
|
|
|
2024-02-21 18:43:55 +01:00
|
|
|
private:
|
2024-02-21 20:06:07 +01:00
|
|
|
struct QuickReplyMessage {
|
2024-02-22 15:32:12 +01:00
|
|
|
QuickReplyMessage() = default;
|
|
|
|
QuickReplyMessage(const QuickReplyMessage &) = delete;
|
|
|
|
QuickReplyMessage &operator=(const QuickReplyMessage &) = delete;
|
|
|
|
QuickReplyMessage(QuickReplyMessage &&) = delete;
|
|
|
|
QuickReplyMessage &operator=(QuickReplyMessage &&) = delete;
|
|
|
|
~QuickReplyMessage();
|
|
|
|
|
2024-02-21 20:06:07 +01:00
|
|
|
MessageId message_id;
|
2024-02-22 15:32:12 +01:00
|
|
|
int32 shortcut_id = 0;
|
2024-02-21 20:06:07 +01:00
|
|
|
int32 sending_id = 0; // for yet unsent messages
|
|
|
|
|
|
|
|
int64 random_id = 0; // for send_message
|
|
|
|
|
|
|
|
unique_ptr<MessageForwardInfo> forward_info;
|
|
|
|
|
2024-02-21 20:27:46 +01:00
|
|
|
MessageId reply_to_message_id;
|
2024-02-21 20:06:07 +01:00
|
|
|
|
2024-02-21 20:27:46 +01:00
|
|
|
string send_emoji; // for send_message
|
2024-02-21 20:06:07 +01:00
|
|
|
|
|
|
|
UserId via_bot_user_id;
|
|
|
|
|
|
|
|
bool is_failed_to_send = false;
|
|
|
|
bool disable_notification = false;
|
|
|
|
bool noforwards = false;
|
|
|
|
bool invert_media = false;
|
|
|
|
|
|
|
|
bool has_explicit_sender = false; // for send_message
|
|
|
|
bool is_copy = false; // for send_message
|
|
|
|
bool from_background = false; // for send_message
|
|
|
|
bool disable_web_page_preview = false; // for send_message
|
|
|
|
bool hide_via_bot = false; // for resend_message
|
|
|
|
|
|
|
|
DialogId real_forward_from_dialog_id; // for resend_message
|
|
|
|
MessageId real_forward_from_message_id; // for resend_message
|
|
|
|
|
|
|
|
int32 legacy_layer = 0;
|
|
|
|
|
|
|
|
int32 send_error_code = 0;
|
|
|
|
string send_error_message;
|
|
|
|
double try_resend_at = 0;
|
|
|
|
|
|
|
|
int64 media_album_id = 0;
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> content;
|
|
|
|
|
|
|
|
mutable uint64 send_message_log_event_id = 0;
|
2024-02-22 15:32:12 +01:00
|
|
|
};
|
2024-02-21 20:06:07 +01:00
|
|
|
|
2024-02-22 15:32:12 +01:00
|
|
|
struct Shortcut {
|
|
|
|
Shortcut() = default;
|
|
|
|
Shortcut(const Shortcut &) = delete;
|
|
|
|
Shortcut &operator=(const Shortcut &) = delete;
|
|
|
|
Shortcut(Shortcut &&) = delete;
|
|
|
|
Shortcut &operator=(Shortcut &&) = delete;
|
|
|
|
~Shortcut();
|
|
|
|
|
|
|
|
string name_;
|
|
|
|
int32 shortcut_id_ = 0;
|
|
|
|
int32 total_count_ = 0;
|
|
|
|
vector<unique_ptr<QuickReplyMessage>> messages_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Shortcuts {
|
|
|
|
vector<unique_ptr<Shortcut>> shortcuts_;
|
|
|
|
bool are_inited_ = false;
|
|
|
|
|
|
|
|
vector<Promise<td_api::object_ptr<td_api::quickReplyShortcuts>>> load_queries_;
|
2024-02-21 20:06:07 +01:00
|
|
|
};
|
|
|
|
|
2024-02-21 18:43:55 +01:00
|
|
|
void tear_down() final;
|
|
|
|
|
2024-02-21 20:06:07 +01:00
|
|
|
void add_quick_reply_message_dependencies(Dependencies &dependencies, const QuickReplyMessage *m) const;
|
|
|
|
|
|
|
|
unique_ptr<QuickReplyMessage> create_message(telegram_api::object_ptr<telegram_api::Message> message_ptr,
|
|
|
|
const char *source) const;
|
|
|
|
|
2024-02-21 20:43:29 +01:00
|
|
|
bool can_resend_message(const QuickReplyMessage *m) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::MessageSendingState> get_message_sending_state_object(const QuickReplyMessage *m) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::MessageContent> get_quick_reply_message_message_content_object(
|
|
|
|
const QuickReplyMessage *m) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::quickReplyMessage> get_quick_reply_message_object(const QuickReplyMessage *m,
|
|
|
|
const char *source) const;
|
|
|
|
|
2024-02-22 15:32:12 +01:00
|
|
|
td_api::object_ptr<td_api::quickReplyShortcut> get_quick_reply_shortcut_object(const Shortcut *s,
|
|
|
|
const char *source) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::quickReplyShortcuts> get_quick_reply_shortcuts_object(const char *source) const;
|
|
|
|
|
2024-02-22 17:45:49 +01:00
|
|
|
static int32 get_shortcut_message_count(const Shortcut *s);
|
|
|
|
|
2024-02-22 15:32:12 +01:00
|
|
|
void load_quick_reply_shortcuts(Promise<td_api::object_ptr<td_api::quickReplyShortcuts>> &&promise);
|
|
|
|
|
|
|
|
void on_reload_quick_reply_shortcuts(
|
|
|
|
Result<telegram_api::object_ptr<telegram_api::messages_QuickReplies>> r_shortcuts);
|
|
|
|
|
|
|
|
void on_load_quick_reply_success();
|
|
|
|
|
|
|
|
void on_load_quick_reply_fail(Status error);
|
|
|
|
|
2024-02-22 17:45:49 +01:00
|
|
|
Shortcut *get_shortcut(int32 shortcut_id);
|
|
|
|
|
|
|
|
static void sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages);
|
|
|
|
|
|
|
|
static vector<MessageId> get_quick_reply_message_ids(const vector<unique_ptr<QuickReplyMessage>> &messages);
|
|
|
|
|
|
|
|
static vector<MessageId> get_server_quick_reply_message_ids(const vector<unique_ptr<QuickReplyMessage>> &messages);
|
|
|
|
|
|
|
|
static bool update_shortcut_from(Shortcut *new_shortcut, Shortcut *old_shortcut, bool is_partial);
|
|
|
|
|
2024-02-22 15:32:12 +01:00
|
|
|
Shortcuts shortcuts_;
|
|
|
|
|
2024-02-21 18:43:55 +01:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|