Add businessInfo.local_opening_hours.
This commit is contained in:
parent
78038f1fc9
commit
7682cf6e61
@ -661,10 +661,11 @@ businessOpeningHours time_zone_id:string opening_hours:vector<businessOpeningHou
|
|||||||
//@description Contains information about a Telegram Business account
|
//@description Contains information about a Telegram Business account
|
||||||
//@location Location of the business; may be null if none
|
//@location Location of the business; may be null if none
|
||||||
//@opening_hours Opening hours of the business; may be null if none. The hours are guaranteed to be valid and has already been split by week days
|
//@opening_hours Opening hours of the business; may be null if none. The hours are guaranteed to be valid and has already been split by week days
|
||||||
|
//@local_opening_hours Opening hours of the business in the local time; may be null if none. The hours are guaranteed to be valid and has already been split by week days. Local time zone identifier will be empty
|
||||||
//@greeting_message_settings The greeting message; may be null if none or the Business account is not of the current user
|
//@greeting_message_settings The greeting message; may be null if none or the Business account is not of the current user
|
||||||
//@away_message_settings The away message; may be null if none or the Business account is not of the current user
|
//@away_message_settings The away message; may be null if none or the Business account is not of the current user
|
||||||
//@start_page Information about start page of the account; may be null if none
|
//@start_page Information about start page of the account; may be null if none
|
||||||
businessInfo location:businessLocation opening_hours:businessOpeningHours greeting_message_settings:businessGreetingMessageSettings away_message_settings:businessAwayMessageSettings start_page:businessStartPage = BusinessInfo;
|
businessInfo location:businessLocation opening_hours:businessOpeningHours local_opening_hours:businessOpeningHours greeting_message_settings:businessGreetingMessageSettings away_message_settings:businessAwayMessageSettings start_page:businessStartPage = BusinessInfo;
|
||||||
|
|
||||||
|
|
||||||
//@description Contains information about a business chat link
|
//@description Contains information about a business chat link
|
||||||
|
@ -16,6 +16,7 @@ td_api::object_ptr<td_api::businessInfo> BusinessInfo::get_business_info_object(
|
|||||||
}
|
}
|
||||||
return td_api::make_object<td_api::businessInfo>(
|
return td_api::make_object<td_api::businessInfo>(
|
||||||
location_.get_business_location_object(), work_hours_.get_business_opening_hours_object(),
|
location_.get_business_location_object(), work_hours_.get_business_opening_hours_object(),
|
||||||
|
work_hours_.get_local_business_opening_hours_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), intro_.get_business_start_page_object(td));
|
away_message_.get_business_away_message_settings_object(td), intro_.get_business_start_page_object(td));
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,15 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/BusinessWorkHours.h"
|
#include "td/telegram/BusinessWorkHours.h"
|
||||||
|
|
||||||
|
#include "td/telegram/AuthManager.h"
|
||||||
|
#include "td/telegram/OptionManager.h"
|
||||||
|
#include "td/telegram/Td.h"
|
||||||
|
#include "td/telegram/TimeZoneManager.h"
|
||||||
|
|
||||||
#include "td/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
#include "td/utils/misc.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -68,6 +74,46 @@ td_api::object_ptr<td_api::businessOpeningHours> BusinessWorkHours::get_business
|
|||||||
return td_api::make_object<td_api::businessOpeningHours>(time_zone_id_, std::move(intervals));
|
return td_api::make_object<td_api::businessOpeningHours>(time_zone_id_, std::move(intervals));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::businessOpeningHours> BusinessWorkHours::get_local_business_opening_hours_object(
|
||||||
|
Td *td) const {
|
||||||
|
if (is_empty() || td->auth_manager_->is_bot()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto offset = narrow_cast<int32>((td->time_zone_manager_->get_time_zone_offset(time_zone_id_) -
|
||||||
|
td->option_manager_->get_option_integer("utc_time_offset")) /
|
||||||
|
60);
|
||||||
|
if (offset == 0) {
|
||||||
|
return get_business_opening_hours_object();
|
||||||
|
}
|
||||||
|
|
||||||
|
BusinessWorkHours local_work_hours;
|
||||||
|
for (auto &interval : work_hours_) {
|
||||||
|
auto start_minute = interval.start_minute_ - offset;
|
||||||
|
auto end_minute = interval.end_minute_ - offset;
|
||||||
|
if (start_minute < 0) {
|
||||||
|
if (end_minute <= 24 * 60) {
|
||||||
|
start_minute += 7 * 24 * 60;
|
||||||
|
end_minute += 7 * 24 * 60;
|
||||||
|
} else {
|
||||||
|
local_work_hours.work_hours_.emplace_back(start_minute + 7 * 24 * 60, 7 * 24 * 60);
|
||||||
|
start_minute = 0;
|
||||||
|
}
|
||||||
|
} else if (end_minute > 8 * 24 * 60) {
|
||||||
|
if (start_minute >= 7 * 24 * 60) {
|
||||||
|
start_minute -= 7 * 24 * 60;
|
||||||
|
end_minute -= 7 * 24 * 60;
|
||||||
|
} else {
|
||||||
|
local_work_hours.work_hours_.emplace_back(0, end_minute - 7 * 24 * 60);
|
||||||
|
end_minute = 7 * 24 * 60;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
local_work_hours.work_hours_.emplace_back(start_minute, end_minute);
|
||||||
|
}
|
||||||
|
local_work_hours.sanitize_work_hours();
|
||||||
|
return local_work_hours.get_business_opening_hours_object();
|
||||||
|
}
|
||||||
|
|
||||||
telegram_api::object_ptr<telegram_api::businessWorkHours> BusinessWorkHours::get_input_business_work_hours() const {
|
telegram_api::object_ptr<telegram_api::businessWorkHours> BusinessWorkHours::get_input_business_work_hours() const {
|
||||||
if (is_empty()) {
|
if (is_empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
class Td;
|
||||||
|
|
||||||
class BusinessWorkHours {
|
class BusinessWorkHours {
|
||||||
public:
|
public:
|
||||||
BusinessWorkHours() = default;
|
BusinessWorkHours() = default;
|
||||||
@ -26,6 +28,8 @@ class BusinessWorkHours {
|
|||||||
|
|
||||||
td_api::object_ptr<td_api::businessOpeningHours> get_business_opening_hours_object() const;
|
td_api::object_ptr<td_api::businessOpeningHours> get_business_opening_hours_object() const;
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::businessOpeningHours> get_local_business_opening_hours_object(Td *td) const;
|
||||||
|
|
||||||
telegram_api::object_ptr<telegram_api::businessWorkHours> get_input_business_work_hours() const;
|
telegram_api::object_ptr<telegram_api::businessWorkHours> get_input_business_work_hours() const;
|
||||||
|
|
||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "td/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/tl_helpers.h"
|
#include "td/utils/tl_helpers.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@ -109,6 +110,16 @@ void TimeZoneManager::tear_down() {
|
|||||||
parent_.reset();
|
parent_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 TimeZoneManager::get_time_zone_offset(const string &time_zone_id) {
|
||||||
|
load_time_zones();
|
||||||
|
for (auto &time_zone : time_zones_.time_zones_) {
|
||||||
|
if (time_zone.id_ == time_zone_id) {
|
||||||
|
return time_zone.utc_offset_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return narrow_cast<int32>(G()->get_option_integer("utc_time_offset"));
|
||||||
|
}
|
||||||
|
|
||||||
void TimeZoneManager::get_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise) {
|
void TimeZoneManager::get_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise) {
|
||||||
load_time_zones();
|
load_time_zones();
|
||||||
if (time_zones_.hash_ != 0) {
|
if (time_zones_.hash_ != 0) {
|
||||||
|
@ -28,6 +28,8 @@ class TimeZoneManager final : public Actor {
|
|||||||
TimeZoneManager &operator=(TimeZoneManager &&) = delete;
|
TimeZoneManager &operator=(TimeZoneManager &&) = delete;
|
||||||
~TimeZoneManager() final;
|
~TimeZoneManager() final;
|
||||||
|
|
||||||
|
int32 get_time_zone_offset(const string &time_zone_id);
|
||||||
|
|
||||||
void get_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise);
|
void get_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise);
|
||||||
|
|
||||||
void reload_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise);
|
void reload_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise);
|
||||||
|
Loading…
Reference in New Issue
Block a user