Move business info setters to BusinessManager.

This commit is contained in:
levlam 2024-03-04 16:57:36 +03:00
parent e78c0aa360
commit 261a3d0c22
5 changed files with 189 additions and 172 deletions

View File

@ -6,8 +6,163 @@
//
#include "td/telegram/BusinessManager.h"
#include "td/telegram/BusinessAwayMessage.h"
#include "td/telegram/BusinessGreetingMessage.h"
#include "td/telegram/BusinessWorkHours.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogLocation.h"
#include "td/telegram/Global.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/buffer.h"
#include "td/utils/Status.h"
namespace td {
class UpdateBusinessLocationQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogLocation location_;
public:
explicit UpdateBusinessLocationQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogLocation &&location) {
location_ = std::move(location);
int32 flags = 0;
if (!location_.empty()) {
flags |= telegram_api::account_updateBusinessLocation::GEO_POINT_MASK;
}
if (!location_.get_address().empty()) {
flags |= telegram_api::account_updateBusinessLocation::ADDRESS_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::account_updateBusinessLocation(flags, location_.get_input_geo_point(), location_.get_address()),
{{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_updateBusinessLocation>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
td_->contacts_manager_->on_update_user_location(td_->contacts_manager_->get_my_id(), std::move(location_));
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class UpdateBusinessWorkHoursQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
BusinessWorkHours work_hours_;
public:
explicit UpdateBusinessWorkHoursQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(BusinessWorkHours &&work_hours) {
work_hours_ = std::move(work_hours);
int32 flags = 0;
if (!work_hours_.is_empty()) {
flags |= telegram_api::account_updateBusinessWorkHours::BUSINESS_WORK_HOURS_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::account_updateBusinessWorkHours(flags, work_hours_.get_input_business_work_hours()), {{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_updateBusinessWorkHours>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
td_->contacts_manager_->on_update_user_work_hours(td_->contacts_manager_->get_my_id(), std::move(work_hours_));
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class UpdateBusinessGreetingMessageQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
BusinessGreetingMessage greeting_message_;
public:
explicit UpdateBusinessGreetingMessageQuery(Promise<Unit> &&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<telegram_api::account_updateBusinessGreetingMessage>(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<Unit> promise_;
BusinessAwayMessage away_message_;
public:
explicit UpdateBusinessAwayMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(BusinessAwayMessage &&away_message) {
away_message_ = std::move(away_message);
int32 flags = 0;
if (!away_message_.is_empty()) {
flags |= telegram_api::account_updateBusinessAwayMessage::MESSAGE_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::account_updateBusinessAwayMessage(flags, away_message_.get_input_business_away_message(td_)),
{{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_updateBusinessAwayMessage>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
td_->contacts_manager_->on_update_user_away_message(td_->contacts_manager_->get_my_id(), std::move(away_message_));
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
BusinessManager::BusinessManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
}
@ -15,4 +170,21 @@ void BusinessManager::tear_down() {
parent_.reset();
}
void BusinessManager::set_business_location(DialogLocation &&location, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessLocationQuery>(std::move(promise))->send(std::move(location));
}
void BusinessManager::set_business_work_hours(BusinessWorkHours &&work_hours, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessWorkHoursQuery>(std::move(promise))->send(std::move(work_hours));
}
void BusinessManager::set_business_greeting_message(BusinessGreetingMessage &&greeting_message,
Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessGreetingMessageQuery>(std::move(promise))->send(std::move(greeting_message));
}
void BusinessManager::set_business_away_message(BusinessAwayMessage &&away_message, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessAwayMessageQuery>(std::move(promise))->send(std::move(away_message));
}
} // namespace td

View File

@ -9,15 +9,28 @@
#include "td/actor/actor.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {
class BusinessAwayMessage;
class BusinessGreetingMessage;
class BusinessWorkHours;
class DialogLocation;
class Td;
class BusinessManager final : public Actor {
public:
BusinessManager(Td *td, ActorShared<> parent);
void set_business_location(DialogLocation &&location, Promise<Unit> &&promise);
void set_business_work_hours(BusinessWorkHours &&work_hours, Promise<Unit> &&promise);
void set_business_greeting_message(BusinessGreetingMessage &&greeting_message, Promise<Unit> &&promise);
void set_business_away_message(BusinessAwayMessage &&away_message, Promise<Unit> &&promise);
private:
void tear_down() final;

View File

@ -1095,149 +1095,6 @@ class UpdateEmojiStatusQuery final : public Td::ResultHandler {
}
};
class UpdateBusinessLocationQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogLocation location_;
public:
explicit UpdateBusinessLocationQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogLocation &&location) {
location_ = std::move(location);
int32 flags = 0;
if (!location_.empty()) {
flags |= telegram_api::account_updateBusinessLocation::GEO_POINT_MASK;
}
if (!location_.get_address().empty()) {
flags |= telegram_api::account_updateBusinessLocation::ADDRESS_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::account_updateBusinessLocation(flags, location_.get_input_geo_point(), location_.get_address()),
{{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_updateBusinessLocation>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
td_->contacts_manager_->on_update_user_location(td_->contacts_manager_->get_my_id(), std::move(location_));
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class UpdateBusinessWorkHoursQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
BusinessWorkHours work_hours_;
public:
explicit UpdateBusinessWorkHoursQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(BusinessWorkHours &&work_hours) {
work_hours_ = std::move(work_hours);
int32 flags = 0;
if (!work_hours_.is_empty()) {
flags |= telegram_api::account_updateBusinessWorkHours::BUSINESS_WORK_HOURS_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::account_updateBusinessWorkHours(flags, work_hours_.get_input_business_work_hours()), {{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_updateBusinessWorkHours>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
td_->contacts_manager_->on_update_user_work_hours(td_->contacts_manager_->get_my_id(), std::move(work_hours_));
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class UpdateBusinessGreetingMessageQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
BusinessGreetingMessage greeting_message_;
public:
explicit UpdateBusinessGreetingMessageQuery(Promise<Unit> &&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<telegram_api::account_updateBusinessGreetingMessage>(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<Unit> promise_;
BusinessAwayMessage away_message_;
public:
explicit UpdateBusinessAwayMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(BusinessAwayMessage &&away_message) {
away_message_ = std::move(away_message);
int32 flags = 0;
if (!away_message_.is_empty()) {
flags |= telegram_api::account_updateBusinessAwayMessage::MESSAGE_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::account_updateBusinessAwayMessage(flags, away_message_.get_input_business_away_message(td_)),
{{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_updateBusinessAwayMessage>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
td_->contacts_manager_->on_update_user_away_message(td_->contacts_manager_->get_my_id(), std::move(away_message_));
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class CreateChatQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chat>> promise_;
@ -7092,23 +6949,6 @@ void ContactsManager::on_set_emoji_status(EmojiStatus emoji_status, Promise<Unit
promise.set_value(Unit());
}
void ContactsManager::set_business_location(DialogLocation &&location, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessLocationQuery>(std::move(promise))->send(std::move(location));
}
void ContactsManager::set_business_work_hours(BusinessWorkHours &&work_hours, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessWorkHoursQuery>(std::move(promise))->send(std::move(work_hours));
}
void ContactsManager::set_business_greeting_message(BusinessGreetingMessage &&greeting_message,
Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessGreetingMessageQuery>(std::move(promise))->send(std::move(greeting_message));
}
void ContactsManager::set_business_away_message(BusinessAwayMessage &&away_message, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessAwayMessageQuery>(std::move(promise))->send(std::move(away_message));
}
void ContactsManager::set_chat_description(ChatId chat_id, const string &description, Promise<Unit> &&promise) {
auto new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH);
auto c = get_chat(chat_id);

View File

@ -468,14 +468,6 @@ class ContactsManager final : public Actor {
void set_emoji_status(const EmojiStatus &emoji_status, Promise<Unit> &&promise);
void set_business_location(DialogLocation &&location, Promise<Unit> &&promise);
void set_business_work_hours(BusinessWorkHours &&work_hours, Promise<Unit> &&promise);
void set_business_greeting_message(BusinessGreetingMessage &&greeting_message, Promise<Unit> &&promise);
void set_business_away_message(BusinessAwayMessage &&away_message, Promise<Unit> &&promise);
void set_chat_description(ChatId chat_id, const string &description, Promise<Unit> &&promise);
void set_channel_username(ChannelId channel_id, const string &username, Promise<Unit> &&promise);

View File

@ -7806,26 +7806,26 @@ void Td::on_request(uint64 id, const td_api::setLocation &request) {
void Td::on_request(uint64 id, td_api::setBusinessLocation &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_business_location(DialogLocation(std::move(request.location_)), std::move(promise));
business_manager_->set_business_location(DialogLocation(std::move(request.location_)), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setBusinessOpeningHours &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_business_work_hours(BusinessWorkHours(std::move(request.opening_hours_)), std::move(promise));
business_manager_->set_business_work_hours(BusinessWorkHours(std::move(request.opening_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(
business_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();
contacts_manager_->set_business_away_message(BusinessAwayMessage(std::move(request.away_message_settings_)),
business_manager_->set_business_away_message(BusinessAwayMessage(std::move(request.away_message_settings_)),
std::move(promise));
}