Add td_api::setBusinessWorkHours.

This commit is contained in:
levlam 2024-02-20 15:55:17 +03:00
parent ea58ed8831
commit 5097989a4d
8 changed files with 105 additions and 3 deletions

View File

@ -9260,6 +9260,9 @@ setLocation location:location = Ok;
//@description Changes the business location of the current user. Requires Telegram Business subscription @location The new location of the business; pass null to remove the location //@description Changes the business location of the current user. Requires Telegram Business subscription @location The new location of the business; pass null to remove the location
setBusinessLocation location:chatLocation = Ok; setBusinessLocation location:chatLocation = Ok;
//@description Changes the business work hours of the current user. Requires Telegram Business subscription @work_hours The new work hours of the business; pass null to remove the work hours
setBusinessWorkHours work_hours:businessWorkHours = Ok;
//@description Changes the phone number of the user and sends an authentication code to the user's new phone number; for official Android and iOS applications only. On success, returns information about the sent code //@description Changes the phone number of the user and sends an authentication code to the user's new phone number; for official Android and iOS applications only. On success, returns information about the sent code
//@phone_number The new phone number of the user in international format //@phone_number The new phone number of the user in international format
//@settings Settings for the authentication of the user's phone number; pass null to use default settings //@settings Settings for the authentication of the user's phone number; pass null to use default settings

View File

@ -16,6 +16,11 @@ BusinessWorkHours::WorkHoursInterval::get_business_work_hours_interval_object()
return td_api::make_object<td_api::businessWorkHoursInterval>(start_minute_, end_minute_); return td_api::make_object<td_api::businessWorkHoursInterval>(start_minute_, end_minute_);
} }
telegram_api::object_ptr<telegram_api::businessWeeklyOpen>
BusinessWorkHours::WorkHoursInterval::get_input_business_weekly_open() const {
return telegram_api::make_object<telegram_api::businessWeeklyOpen>(start_minute_, end_minute_);
}
BusinessWorkHours::BusinessWorkHours(telegram_api::object_ptr<telegram_api::businessWorkHours> &&work_hours) { BusinessWorkHours::BusinessWorkHours(telegram_api::object_ptr<telegram_api::businessWorkHours> &&work_hours) {
if (work_hours != nullptr) { if (work_hours != nullptr) {
work_hours_ = transform(work_hours->weekly_open_, work_hours_ = transform(work_hours->weekly_open_,
@ -26,6 +31,16 @@ BusinessWorkHours::BusinessWorkHours(telegram_api::object_ptr<telegram_api::busi
} }
} }
BusinessWorkHours::BusinessWorkHours(td_api::object_ptr<td_api::businessWorkHours> &&work_hours) {
if (work_hours != nullptr) {
work_hours_ =
transform(work_hours->work_hours_, [](const td_api::object_ptr<td_api::businessWorkHoursInterval> &interval) {
return WorkHoursInterval(interval->start_minute_, interval->end_minute_);
});
time_zone_id_ = std::move(work_hours->time_zone_id_);
}
}
bool BusinessWorkHours::is_empty() const { bool BusinessWorkHours::is_empty() const {
return work_hours_.empty(); return work_hours_.empty();
} }
@ -40,6 +55,16 @@ td_api::object_ptr<td_api::businessWorkHours> BusinessWorkHours::get_business_wo
})); }));
} }
telegram_api::object_ptr<telegram_api::businessWorkHours> BusinessWorkHours::get_input_business_work_hours() const {
if (is_empty()) {
return nullptr;
}
return telegram_api::make_object<telegram_api::businessWorkHours>(
0, false, time_zone_id_, transform(work_hours_, [](const WorkHoursInterval &interval) {
return interval.get_input_business_weekly_open();
}));
}
bool operator==(const BusinessWorkHours::WorkHoursInterval &lhs, const BusinessWorkHours::WorkHoursInterval &rhs) { bool operator==(const BusinessWorkHours::WorkHoursInterval &lhs, const BusinessWorkHours::WorkHoursInterval &rhs) {
return lhs.start_minute_ == rhs.start_minute_ && lhs.end_minute_ == rhs.end_minute_; return lhs.start_minute_ == rhs.start_minute_ && lhs.end_minute_ == rhs.end_minute_;
} }

View File

@ -27,6 +27,8 @@ class BusinessWorkHours {
td_api::object_ptr<td_api::businessWorkHoursInterval> get_business_work_hours_interval_object() const; td_api::object_ptr<td_api::businessWorkHoursInterval> get_business_work_hours_interval_object() const;
telegram_api::object_ptr<telegram_api::businessWeeklyOpen> get_input_business_weekly_open() const;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;
@ -49,12 +51,16 @@ class BusinessWorkHours {
public: public:
BusinessWorkHours() = default; BusinessWorkHours() = default;
BusinessWorkHours(telegram_api::object_ptr<telegram_api::businessWorkHours> &&work_hours); explicit BusinessWorkHours(telegram_api::object_ptr<telegram_api::businessWorkHours> &&work_hours);
explicit BusinessWorkHours(td_api::object_ptr<td_api::businessWorkHours> &&work_hours);
bool is_empty() const; bool is_empty() const;
td_api::object_ptr<td_api::businessWorkHours> get_business_work_hours_object() const; td_api::object_ptr<td_api::businessWorkHours> get_business_work_hours_object() const;
telegram_api::object_ptr<telegram_api::businessWorkHours> get_input_business_work_hours() const;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;

View File

@ -1126,6 +1126,40 @@ class UpdateBusinessLocationQuery final : public Td::ResultHandler {
} }
}; };
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 CreateChatQuery final : public Td::ResultHandler { class CreateChatQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chat>> promise_; Promise<td_api::object_ptr<td_api::chat>> promise_;
@ -6994,6 +7028,10 @@ void ContactsManager::set_business_location(DialogLocation &&location, Promise<U
td_->create_handler<UpdateBusinessLocationQuery>(std::move(promise))->send(std::move(location)); 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_chat_description(ChatId chat_id, const string &description, Promise<Unit> &&promise) { 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 new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH);
auto c = get_chat(chat_id); auto c = get_chat(chat_id);

View File

@ -467,6 +467,8 @@ class ContactsManager final : public Actor {
void set_business_location(DialogLocation &&location, 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_chat_description(ChatId chat_id, const string &description, 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); void set_channel_username(ChannelId channel_id, const string &username, Promise<Unit> &&promise);

View File

@ -22,6 +22,7 @@
#include "td/telegram/BotCommand.h" #include "td/telegram/BotCommand.h"
#include "td/telegram/BotInfoManager.h" #include "td/telegram/BotInfoManager.h"
#include "td/telegram/BotMenuButton.h" #include "td/telegram/BotMenuButton.h"
#include "td/telegram/BusinessWorkHours.h"
#include "td/telegram/CallbackQueriesManager.h" #include "td/telegram/CallbackQueriesManager.h"
#include "td/telegram/CallId.h" #include "td/telegram/CallId.h"
#include "td/telegram/CallManager.h" #include "td/telegram/CallManager.h"
@ -7744,6 +7745,12 @@ void Td::on_request(uint64 id, td_api::setBusinessLocation &request) {
contacts_manager_->set_business_location(DialogLocation(std::move(request.location_)), std::move(promise)); contacts_manager_->set_business_location(DialogLocation(std::move(request.location_)), std::move(promise));
} }
void Td::on_request(uint64 id, td_api::setBusinessWorkHours &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_business_work_hours(BusinessWorkHours(std::move(request.work_hours_)), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setProfilePhoto &request) { void Td::on_request(uint64 id, td_api::setProfilePhoto &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();

View File

@ -1369,6 +1369,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setBusinessLocation &request); void on_request(uint64 id, td_api::setBusinessLocation &request);
void on_request(uint64 id, td_api::setBusinessWorkHours &request);
void on_request(uint64 id, td_api::setProfilePhoto &request); void on_request(uint64 id, td_api::setProfilePhoto &request);
void on_request(uint64 id, const td_api::deleteProfilePhoto &request); void on_request(uint64 id, const td_api::deleteProfilePhoto &request);

View File

@ -5907,9 +5907,28 @@ class CliClient final : public Actor {
get_args(args, latitude, longitude); get_args(args, latitude, longitude);
if (latitude.empty() || longitude.empty()) { if (latitude.empty() || longitude.empty()) {
send_request(td_api::make_object<td_api::setBusinessLocation>(nullptr)); send_request(td_api::make_object<td_api::setBusinessLocation>(nullptr));
} } else {
send_request(td_api::make_object<td_api::setBusinessLocation>( send_request(td_api::make_object<td_api::setBusinessLocation>(
td_api::make_object<td_api::chatLocation>(as_location(latitude, longitude, string()), "business address"))); td_api::make_object<td_api::chatLocation>(as_location(latitude, longitude, string()), "business address")));
}
} else if (op == "sbwh") {
string time_zone_id;
string work_hours;
get_args(args, time_zone_id, work_hours);
if (time_zone_id.empty()) {
send_request(td_api::make_object<td_api::setBusinessWorkHours>(nullptr));
} else {
auto minutes = to_integers<int32>(work_hours);
if (minutes.size() % 2 == 1) {
minutes.push_back(8 * 24 * 60);
}
vector<td_api::object_ptr<td_api::businessWorkHoursInterval>> intervals;
for (size_t i = 0; i < minutes.size(); i += 2) {
intervals.push_back(td_api::make_object<td_api::businessWorkHoursInterval>(minutes[i], minutes[i + 1]));
}
send_request(td_api::make_object<td_api::setBusinessWorkHours>(
td_api::make_object<td_api::businessWorkHours>(time_zone_id, std::move(intervals))));
}
} else if (op == "sco") { } else if (op == "sco") {
SearchQuery query; SearchQuery query;
get_args(args, query); get_args(args, query);