From 50ba48fbfab2f72c49421cd152d2422cd167f169 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 27 Feb 2024 14:26:19 +0300 Subject: [PATCH] Add td_api::setBusinessGreetingMessageSettings. --- td/generate/scheme/td_api.tl | 7 ++++-- td/telegram/BusinessInfo.cpp | 4 ++-- td/telegram/ContactsManager.cpp | 41 +++++++++++++++++++++++++++++++++ td/telegram/ContactsManager.h | 2 ++ td/telegram/Td.cpp | 8 +++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 15 ++++++++++++ 7 files changed, 75 insertions(+), 4 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 95d06fb5b..5e4232fdb 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -625,9 +625,9 @@ businessWorkHours time_zone_id:string work_hours:vector BusinessInfo::get_business_info_object(Td *td) const { return td_api::make_object(location_.get_business_location_object(), work_hours_.get_business_work_hours_object(), - away_message_.get_business_away_message_settings_object(td), - greeting_message_.get_business_greeting_message_settings_object(td)); + greeting_message_.get_business_greeting_message_settings_object(td), + away_message_.get_business_away_message_settings_object(td)); } bool BusinessInfo::is_empty_location(const DialogLocation &location) { diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 04a8c021d..b11b2129b 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1167,6 +1167,42 @@ class UpdateBusinessWorkHoursQuery final : public Td::ResultHandler { } }; +class UpdateBusinessGreetingMessageQuery final : public Td::ResultHandler { + Promise promise_; + BusinessGreetingMessage greeting_message_; + + public: + explicit UpdateBusinessGreetingMessageQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(BusinessGreetingMessage &&greeting_message) { + greeting_message_ = std::move(greeting_message); + int32 flags = 0; + if (!greeting_message_.is_empty()) { + flags |= telegram_api::account_updateBusinessGreetingMessage::MESSAGE_MASK; + } + send_query(G()->net_query_creator().create(telegram_api::account_updateBusinessGreetingMessage( + flags, greeting_message_.get_input_business_greeting_message(td_)), + {{"me"}})); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + td_->contacts_manager_->on_update_user_greeting_message(td_->contacts_manager_->get_my_id(), + std::move(greeting_message_)); + + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class UpdateBusinessAwayMessageQuery final : public Td::ResultHandler { Promise promise_; BusinessAwayMessage away_message_; @@ -7064,6 +7100,11 @@ void ContactsManager::set_business_work_hours(BusinessWorkHours &&work_hours, Pr td_->create_handler(std::move(promise))->send(std::move(work_hours)); } +void ContactsManager::set_business_greeting_message(BusinessGreetingMessage &&greeting_message, + Promise &&promise) { + td_->create_handler(std::move(promise))->send(std::move(greeting_message)); +} + void ContactsManager::set_business_away_message(BusinessAwayMessage &&away_message, Promise &&promise) { td_->create_handler(std::move(promise))->send(std::move(away_message)); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index b08aed2f7..5440f9932 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -472,6 +472,8 @@ class ContactsManager final : public Actor { void set_business_work_hours(BusinessWorkHours &&work_hours, Promise &&promise); + void set_business_greeting_message(BusinessGreetingMessage &&greeting_message, Promise &&promise); + void set_business_away_message(BusinessAwayMessage &&away_message, Promise &&promise); void set_chat_description(ChatId chat_id, const string &description, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 48e6c7755..1eca9d392 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -23,6 +23,7 @@ #include "td/telegram/BotInfoManager.h" #include "td/telegram/BotMenuButton.h" #include "td/telegram/BusinessAwayMessage.h" +#include "td/telegram/BusinessGreetingMessage.h" #include "td/telegram/BusinessWorkHours.h" #include "td/telegram/CallbackQueriesManager.h" #include "td/telegram/CallId.h" @@ -7778,6 +7779,13 @@ void Td::on_request(uint64 id, td_api::setBusinessWorkHours &request) { contacts_manager_->set_business_work_hours(BusinessWorkHours(std::move(request.work_hours_)), std::move(promise)); } +void Td::on_request(uint64 id, td_api::setBusinessGreetingMessageSettings &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->set_business_greeting_message( + BusinessGreetingMessage(std::move(request.greeting_message_settings_)), std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setBusinessAwayMessageSettings &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 2e16cbb4d..829c49f66 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1380,6 +1380,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::setBusinessWorkHours &request); + void on_request(uint64 id, td_api::setBusinessGreetingMessageSettings &request); + void on_request(uint64 id, td_api::setBusinessAwayMessageSettings &request); void on_request(uint64 id, td_api::setProfilePhoto &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f987822be..832a8d264 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5939,6 +5939,21 @@ class CliClient final : public Actor { send_request(td_api::make_object( td_api::make_object(time_zone_id, std::move(intervals)))); } + } else if (op == "sbgms") { + string shortcut_id; + string chat_ids; + int32 inactivity_days; + get_args(args, shortcut_id, chat_ids, inactivity_days); + if (shortcut_id.empty()) { + send_request(td_api::make_object(nullptr)); + } else { + send_request(td_api::make_object( + td_api::make_object( + to_integer(shortcut_id), + td_api::make_object(as_chat_ids(chat_ids), rand_bool(), rand_bool(), + rand_bool(), rand_bool(), rand_bool()), + inactivity_days))); + } } else if (op == "sbams") { string shortcut_id; string chat_ids;