User only methods (#25)

Co-authored-by: code1mountain <none>
Co-authored-by: luckydonald <mac2019.git@luckydonald.de>
This commit is contained in:
Jannik 2021-01-02 12:32:34 +01:00 committed by GitHub
parent 00655e474d
commit 954bc416c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 852 additions and 99 deletions

File diff suppressed because it is too large Load Diff

View File

@ -41,10 +41,6 @@ class Client : public WebhookActor::Callback {
Client(td::ActorShared<> parent, const td::string &bot_token, bool is_user, bool is_test_dc, td::int64 tqueue_id, Client(td::ActorShared<> parent, const td::string &bot_token, bool is_user, bool is_test_dc, td::int64 tqueue_id,
std::shared_ptr<const ClientParameters> parameters, td::ActorId<BotStatActor> stat_actor); std::shared_ptr<const ClientParameters> parameters, td::ActorId<BotStatActor> stat_actor);
Client(td::ActorShared<> parent, const td::string &bot_token, const td::string &phone_number, bool is_user,
bool is_test_dc, td::int64 tqueue_id, std::shared_ptr<const ClientParameters> parameters,
td::ActorId<BotStatActor> stat_actor);
void send(PromisedQueryPtr query) override; void send(PromisedQueryPtr query) override;
void close(); void close();
@ -157,6 +153,14 @@ class Client : public WebhookActor::Callback {
class JsonStickerSet; class JsonStickerSet;
class JsonCustomJson; class JsonCustomJson;
//start custom Json objects
class JsonAuthorizationState;
class JsonCallbackQueryAnswer;
class JsonChats;
class JsonChatsNearby;
class JsonMessagesArray;
//stop custom Json objects
class TdOnOkCallback; class TdOnOkCallback;
class TdOnAuthorizationCallback; class TdOnAuthorizationCallback;
class TdOnAuthorizationQueryCallback; class TdOnAuthorizationQueryCallback;
@ -192,6 +196,12 @@ class Client : public WebhookActor::Callback {
//start custom callbacks //start custom callbacks
class TdOnPingCallback; class TdOnPingCallback;
class TdOnGetMemoryStatisticsCallback; class TdOnGetMemoryStatisticsCallback;
class TdOnGetChatsCallback;
class TdOnGetChatsNearbyCallback;
class TdOnJoinChatCallback;
class TdOnReturnChatCallback;
class TdOnReturnMessagesCallback;
class TdOnGetCallbackQueryAnswerCallback;
//end custom callbacks //end custom callbacks
void on_get_reply_message(int64 chat_id, object_ptr<td_api::message> reply_to_message); void on_get_reply_message(int64 chat_id, object_ptr<td_api::message> reply_to_message);
@ -404,7 +414,7 @@ class Client : public WebhookActor::Callback {
td::Result<td::vector<object_ptr<td_api::InputMessageContent>>> get_input_message_contents( td::Result<td::vector<object_ptr<td_api::InputMessageContent>>> get_input_message_contents(
const Query *query, td::JsonValue &&value) const; const Query *query, td::JsonValue &&value) const;
static object_ptr<td_api::messageSendOptions> get_message_send_options(bool disable_notification); static object_ptr<td_api::messageSendOptions> get_message_send_options(bool disable_notification, object_ptr<td_api::MessageSchedulingState> &&scheduling_state);
static td::Result<td::vector<td::string>> get_poll_options(const Query *query); static td::Result<td::vector<td::string>> get_poll_options(const Query *query);
@ -422,6 +432,24 @@ class Client : public WebhookActor::Callback {
int64 extract_yet_unsent_message_query_id(int64 chat_id, int64 message_id, bool *is_reply_to_message_deleted); int64 extract_yet_unsent_message_query_id(int64 chat_id, int64 message_id, bool *is_reply_to_message_deleted);
// start custom helper methods
static td::Result<object_ptr<td_api::MessageSchedulingState>> get_message_scheduling_state(const Query *query);
template <class T>
static td::Result<td::vector<T>> get_int_array_arg(const Query *query, Slice field_name, bool optional = false);
static int64 get_int64_arg(const Query *query, Slice field_name, int64 default_value,
int64 min_value = std::numeric_limits<int64>::min(),
int64 max_value = std::numeric_limits<int64>::max());
static td::Result<td_api::object_ptr<td_api::ChatReportReason>> get_report_reason(const Query *query,
Slice field_name = Slice("reason"));
static td::Result<td_api::object_ptr<td_api::SearchMessagesFilter>> get_search_messages_filter(
const Query *query, Slice field_name = Slice("filter"));
// end custom helper methods
void on_message_send_succeeded(object_ptr<td_api::message> &&message, int64 old_message_id); void on_message_send_succeeded(object_ptr<td_api::message> &&message, int64 old_message_id);
void on_message_send_failed(int64 chat_id, int64 old_message_id, int64 new_message_id, Status result); void on_message_send_failed(int64 chat_id, int64 old_message_id, int64 new_message_id, Status result);
@ -505,13 +533,32 @@ class Client : public WebhookActor::Callback {
//custom methods //custom methods
Status process_get_message_info_query(PromisedQueryPtr &query); Status process_get_message_info_query(PromisedQueryPtr &query);
Status process_get_participants_query(PromisedQueryPtr &query); Status process_get_chat_members_query(PromisedQueryPtr &query);
Status process_delete_messages_query(PromisedQueryPtr &query); Status process_delete_messages_query(PromisedQueryPtr &query);
Status process_toggle_group_invites_query(PromisedQueryPtr &query); Status process_toggle_group_invites_query(PromisedQueryPtr &query);
Status process_ping_query(PromisedQueryPtr &query); Status process_ping_query(PromisedQueryPtr &query);
Status process_get_memory_stats_query(PromisedQueryPtr &query); Status process_get_memory_stats_query(PromisedQueryPtr &query);
//custom user methods
Status process_get_chats_query(PromisedQueryPtr &query);
Status process_get_common_chats_query(PromisedQueryPtr &query);
Status process_get_inactive_chats_query(PromisedQueryPtr &query);
Status process_get_nearby_chats_query(PromisedQueryPtr &query);
Status process_search_public_chats_query(PromisedQueryPtr &query);
Status process_set_poll_answer_query(PromisedQueryPtr &query);
Status process_join_chat_query(PromisedQueryPtr &query);
Status process_add_chat_member_query(PromisedQueryPtr &query);
Status process_report_chat_query(PromisedQueryPtr &query);
Status process_create_chat_query(PromisedQueryPtr &query);
Status process_search_messages_query(PromisedQueryPtr &query);
Status process_search_chat_messages_query(PromisedQueryPtr &query);
Status process_get_callback_query_answer_query(PromisedQueryPtr &query);
Status process_delete_chat_history_query(PromisedQueryPtr &query);
Status process_get_scheduled_messages_query(PromisedQueryPtr &query);
Status process_edit_message_scheduling_query(PromisedQueryPtr &query);
//custom auth methods //custom auth methods
void process_auth_phone_number_query(PromisedQueryPtr &query);
void process_authcode_query(PromisedQueryPtr &query); void process_authcode_query(PromisedQueryPtr &query);
void process_2fapassword_query(PromisedQueryPtr &query); void process_2fapassword_query(PromisedQueryPtr &query);
void process_register_user_query(PromisedQueryPtr &query); void process_register_user_query(PromisedQueryPtr &query);
@ -579,8 +626,11 @@ class Client : public WebhookActor::Callback {
td::string bio; td::string bio;
// start custom properties
bool is_verified = false; bool is_verified = false;
bool is_scam = false; bool is_scam = false;
// end custom properties
bool have_access = false; bool have_access = false;
bool can_join_groups = false; bool can_join_groups = false;
bool can_read_all_group_messages = false; bool can_read_all_group_messages = false;
@ -617,8 +667,11 @@ class Client : public WebhookActor::Callback {
bool is_supergroup = false; bool is_supergroup = false;
bool can_set_sticker_set = false; bool can_set_sticker_set = false;
bool has_location = false; bool has_location = false;
// start custom properties
bool is_verified = false; bool is_verified = false;
bool is_scam = false; bool is_scam = false;
// end custom properties
}; };
static void add_supergroup(std::unordered_map<int32, SupergroupInfo> &supergroups, static void add_supergroup(std::unordered_map<int32, SupergroupInfo> &supergroups,
object_ptr<td_api::supergroup> &&supergroup); object_ptr<td_api::supergroup> &&supergroup);
@ -677,9 +730,14 @@ class Client : public WebhookActor::Callback {
object_ptr<td_api::MessageContent> content; object_ptr<td_api::MessageContent> content;
object_ptr<td_api::ReplyMarkup> reply_markup; object_ptr<td_api::ReplyMarkup> reply_markup;
// start custom properties
int32 views = 0; int32 views = 0;
int32 forwards = 0; int32 forwards = 0;
bool is_scheduled = false;
int32 scheduled_at = 0;
// end custom properties
mutable bool is_reply_to_message_deleted = false; mutable bool is_reply_to_message_deleted = false;
mutable bool is_content_changed = false; mutable bool is_content_changed = false;
}; };
@ -762,6 +820,8 @@ class Client : public WebhookActor::Callback {
static int32 as_client_message_id(int64 message_id); static int32 as_client_message_id(int64 message_id);
static int32 as_scheduled_message_id(int64 message_id);
static int64 get_supergroup_chat_id(int32 supergroup_id); static int64 get_supergroup_chat_id(int32 supergroup_id);
static int64 get_basic_group_chat_id(int32 basic_group_id); static int64 get_basic_group_chat_id(int32 basic_group_id);
@ -847,7 +907,6 @@ class Client : public WebhookActor::Callback {
td::string bot_token_; td::string bot_token_;
td::string bot_token_with_dc_; td::string bot_token_with_dc_;
td::string bot_token_id_; td::string bot_token_id_;
td::string phone_number_;
bool is_user_; bool is_user_;
bool is_test_dc_; bool is_test_dc_;
int64 tqueue_id_; int64 tqueue_id_;

View File

@ -145,15 +145,17 @@ void ClientManager::user_login(PromisedQueryPtr query) {
auto id = clients_.create(ClientInfo{BotStatActor(stat_.actor_id(&stat_)), user_token, td::ActorOwn<Client>()}); auto id = clients_.create(ClientInfo{BotStatActor(stat_.actor_id(&stat_)), user_token, td::ActorOwn<Client>()});
auto *client_info = clients_.get(id); auto *client_info = clients_.get(id);
auto stat_actor = client_info->stat_.actor_id(&client_info->stat_); auto stat_actor = client_info->stat_.actor_id(&client_info->stat_);
auto client_id = td::create_actor<Client>( auto client_id = td::create_actor<Client>(PSLICE() << "Client/" << user_token, actor_shared(this, id), user_token,
PSLICE() << "Client/" << user_token, actor_shared(this, id), user_token, td::to_string(phone_number), true, query->is_test_dc(), get_tqueue_id(token_hash, query->is_test_dc()),
true, query->is_test_dc(), get_tqueue_id(token_hash, query->is_test_dc()), parameters_, std::move(stat_actor)); parameters_, std::move(stat_actor));
clients_.get(id)->client_ = std::move(client_id); clients_.get(id)->client_ = std::move(client_id);
auto id_it = token_to_id_.end(); auto id_it = token_to_id_.end();
std::tie(id_it, std::ignore) = token_to_id_.emplace(user_token, id); std::tie(id_it, std::ignore) = token_to_id_.emplace(user_token, id);
send_closure(client_info->client_, &Client::send, std::move(query)); // will send 429 if the client is already closed
parameters_->shared_data_->user_db_->set(user_token_with_dc, "1"); parameters_->shared_data_->user_db_->set(user_token_with_dc, "1");
answer_query(td::VirtuallyJsonableString(user_token), std::move(query)); // answer_query(td::VirtuallyJsonableString(user_token), std::move(query));
} }
bool ClientManager::check_flood_limits(PromisedQueryPtr &query, bool is_user_login) { bool ClientManager::check_flood_limits(PromisedQueryPtr &query, bool is_user_login) {