From ea58ed88318cfcc30be6d99eb9e98cc6746d8e6b Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 20 Feb 2024 15:22:02 +0300 Subject: [PATCH] Add userFullInfo.business_work_hours. --- CMakeLists.txt | 3 ++ td/generate/scheme/td_api.tl | 12 ++++- td/telegram/BusinessWorkHours.cpp | 67 +++++++++++++++++++++++++++ td/telegram/BusinessWorkHours.h | 75 +++++++++++++++++++++++++++++++ td/telegram/BusinessWorkHours.hpp | 43 ++++++++++++++++++ td/telegram/ContactsManager.cpp | 41 ++++++++++++++++- td/telegram/ContactsManager.h | 4 ++ 7 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 td/telegram/BusinessWorkHours.cpp create mode 100644 td/telegram/BusinessWorkHours.h create mode 100644 td/telegram/BusinessWorkHours.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ac8ccccf3..4b3907e50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,6 +301,7 @@ set(TDLIB_SOURCE td/telegram/BotCommandScope.cpp td/telegram/BotInfoManager.cpp td/telegram/BotMenuButton.cpp + td/telegram/BusinessWorkHours.cpp td/telegram/CallActor.cpp td/telegram/CallbackQueriesManager.cpp td/telegram/CallDiscardReason.cpp @@ -578,6 +579,7 @@ set(TDLIB_SOURCE td/telegram/BotCommandScope.h td/telegram/BotInfoManager.h td/telegram/BotMenuButton.h + td/telegram/BusinessWorkHours.h td/telegram/CallActor.h td/telegram/CallDiscardReason.h td/telegram/CallId.h @@ -874,6 +876,7 @@ set(TDLIB_SOURCE td/telegram/AuthManager.hpp td/telegram/BackgroundInfo.hpp td/telegram/BackgroundType.hpp + td/telegram/BusinessWorkHours.hpp td/telegram/ChatReactions.hpp td/telegram/DialogNotificationSettings.hpp td/telegram/DialogFilter.hpp diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 6a2fe616f..80b9882d7 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -576,6 +576,15 @@ botMenuButton text:string url:string = BotMenuButton; chatLocation location:location address:string = ChatLocation; +//@description Describes an interval of time when the business is open +//@start_minute The first minute of the interval since start of the week; 0-7*24*60 +//@end_minute The first minute after the end of the interval since start of the week; 1-8*24*60 +businessWorkHoursInterval start_minute:int32 end_minute:int32 = BusinessWorkHoursInterval; + +//@description Describes work hours of a business @time_zone_id Unique time zone identifier @work_hours Intervals of the time when the business is open +businessWorkHours time_zone_id:string work_hours:vector = BusinessWorkHours; + + //@class ChatPhotoStickerType @description Describes type of a sticker, which was used to create a chat photo //@description Information about the sticker, which was used to create the chat photo @@ -848,8 +857,9 @@ botInfo short_description:string description:string photo:photo animation:animat //@premium_gift_options The list of available options for gifting Telegram Premium to the user //@group_in_common_count Number of group chats where both the other user and the current user are a member; 0 for the current user //@business_location Location of the business for Telegram Business users; may be null if none +//@business_work_hours Work hours of the business for Telegram Business users; may be null if none //@bot_info For bots, information about the bot; may be null if the user isn't a bot -userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto block_list:BlockList can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool has_pinned_stories:Bool need_phone_number_privacy_exception:Bool set_chat_background:Bool bio:formattedText premium_gift_options:vector group_in_common_count:int32 business_location:chatLocation bot_info:botInfo = UserFullInfo; +userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto block_list:BlockList can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool has_pinned_stories:Bool need_phone_number_privacy_exception:Bool set_chat_background:Bool bio:formattedText premium_gift_options:vector group_in_common_count:int32 business_location:chatLocation business_work_hours:businessWorkHours bot_info:botInfo = UserFullInfo; //@description Represents a list of users @total_count Approximate total number of users found @user_ids A list of user identifiers users total_count:int32 user_ids:vector = Users; diff --git a/td/telegram/BusinessWorkHours.cpp b/td/telegram/BusinessWorkHours.cpp new file mode 100644 index 000000000..97ee42045 --- /dev/null +++ b/td/telegram/BusinessWorkHours.cpp @@ -0,0 +1,67 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/telegram/BusinessWorkHours.h" + +#include "td/utils/algorithm.h" +#include "td/utils/format.h" + +namespace td { + +td_api::object_ptr +BusinessWorkHours::WorkHoursInterval::get_business_work_hours_interval_object() const { + return td_api::make_object(start_minute_, end_minute_); +} + +BusinessWorkHours::BusinessWorkHours(telegram_api::object_ptr &&work_hours) { + if (work_hours != nullptr) { + work_hours_ = transform(work_hours->weekly_open_, + [](const telegram_api::object_ptr &weekly_open) { + return WorkHoursInterval(weekly_open->start_minute_, weekly_open->end_minute_); + }); + time_zone_id_ = std::move(work_hours->timezone_id_); + } +} + +bool BusinessWorkHours::is_empty() const { + return work_hours_.empty(); +} + +td_api::object_ptr BusinessWorkHours::get_business_work_hours_object() const { + if (is_empty()) { + return nullptr; + } + return td_api::make_object(time_zone_id_, + transform(work_hours_, [](const WorkHoursInterval &interval) { + return interval.get_business_work_hours_interval_object(); + })); +} + +bool operator==(const BusinessWorkHours::WorkHoursInterval &lhs, const BusinessWorkHours::WorkHoursInterval &rhs) { + return lhs.start_minute_ == rhs.start_minute_ && lhs.end_minute_ == rhs.end_minute_; +} + +bool operator!=(const BusinessWorkHours::WorkHoursInterval &lhs, const BusinessWorkHours::WorkHoursInterval &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const BusinessWorkHours::WorkHoursInterval &interval) { + return string_builder << '[' << interval.start_minute_ << ',' << interval.end_minute_ << ')'; +} + +bool operator==(const BusinessWorkHours &lhs, const BusinessWorkHours &rhs) { + return lhs.work_hours_ == rhs.work_hours_ && lhs.time_zone_id_ == rhs.time_zone_id_; +} + +bool operator!=(const BusinessWorkHours &lhs, const BusinessWorkHours &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const BusinessWorkHours &work_hours) { + return string_builder << "BusinessWorkHours[" << work_hours.work_hours_ << " in " << work_hours.time_zone_id_ << ']'; +} + +} // namespace td diff --git a/td/telegram/BusinessWorkHours.h b/td/telegram/BusinessWorkHours.h new file mode 100644 index 000000000..811b98ad5 --- /dev/null +++ b/td/telegram/BusinessWorkHours.h @@ -0,0 +1,75 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class Td; + +class BusinessWorkHours { + struct WorkHoursInterval { + int32 start_minute_ = 0; + int32 end_minute_ = 0; + + WorkHoursInterval() = default; + WorkHoursInterval(int32 start_minute, int32 end_minute) : start_minute_(start_minute), end_minute_(end_minute) { + } + + td_api::object_ptr get_business_work_hours_interval_object() const; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); + }; + vector work_hours_; + string time_zone_id_; + + friend bool operator==(const WorkHoursInterval &lhs, const WorkHoursInterval &rhs); + friend bool operator!=(const WorkHoursInterval &lhs, const WorkHoursInterval &rhs); + + friend bool operator==(const BusinessWorkHours &lhs, const BusinessWorkHours &rhs); + friend bool operator!=(const BusinessWorkHours &lhs, const BusinessWorkHours &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const WorkHoursInterval &interval); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const BusinessWorkHours &work_hours); + + public: + BusinessWorkHours() = default; + + BusinessWorkHours(telegram_api::object_ptr &&work_hours); + + bool is_empty() const; + + td_api::object_ptr get_business_work_hours_object() const; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); +}; + +bool operator==(const BusinessWorkHours::WorkHoursInterval &lhs, const BusinessWorkHours::WorkHoursInterval &rhs); +bool operator!=(const BusinessWorkHours::WorkHoursInterval &lhs, const BusinessWorkHours::WorkHoursInterval &rhs); + +StringBuilder &operator<<(StringBuilder &string_builder, const BusinessWorkHours::WorkHoursInterval &interval); + +bool operator==(const BusinessWorkHours &lhs, const BusinessWorkHours &rhs); +bool operator!=(const BusinessWorkHours &lhs, const BusinessWorkHours &rhs); + +StringBuilder &operator<<(StringBuilder &string_builder, const BusinessWorkHours &work_hours); + +} // namespace td diff --git a/td/telegram/BusinessWorkHours.hpp b/td/telegram/BusinessWorkHours.hpp new file mode 100644 index 000000000..5bd157212 --- /dev/null +++ b/td/telegram/BusinessWorkHours.hpp @@ -0,0 +1,43 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/BusinessWorkHours.h" + +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void BusinessWorkHours::WorkHoursInterval::store(StorerT &storer) const { + td::store(start_minute_, storer); + td::store(end_minute_, storer); +} + +template +void BusinessWorkHours::WorkHoursInterval::parse(ParserT &parser) { + td::parse(start_minute_, parser); + td::parse(end_minute_, parser); +} + +template +void BusinessWorkHours::store(StorerT &storer) const { + BEGIN_STORE_FLAGS(); + END_STORE_FLAGS(); + td::store(work_hours_, storer); + td::store(time_zone_id_, storer); +} + +template +void BusinessWorkHours::parse(ParserT &parser) { + BEGIN_PARSE_FLAGS(); + END_PARSE_FLAGS(); + td::parse(work_hours_, parser); + td::parse(time_zone_id_, parser); +} + +} // namespace td diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index e672ae220..53288387f 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -11,6 +11,7 @@ #include "td/telegram/AuthManager.h" #include "td/telegram/BlockListId.h" #include "td/telegram/BotMenuButton.h" +#include "td/telegram/BusinessWorkHours.hpp" #include "td/telegram/CommonDialogManager.h" #include "td/telegram/ConfigManager.h" #include "td/telegram/Dependencies.h" @@ -3464,6 +3465,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const { bool has_personal_photo = !personal_photo.is_empty(); bool has_fallback_photo = !fallback_photo.is_empty(); bool has_location = !location.empty(); + bool has_work_hours = !work_hours.is_empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_about); STORE_FLAG(is_blocked); @@ -3490,7 +3492,8 @@ void ContactsManager::UserFull::store(StorerT &storer) const { STORE_FLAG(wallpaper_overridden); STORE_FLAG(read_dates_private); STORE_FLAG(contact_require_premium); - STORE_FLAG(has_location); + STORE_FLAG(has_location); // 25 + STORE_FLAG(has_work_hours); END_STORE_FLAGS(); if (has_about) { store(about, storer); @@ -3537,6 +3540,9 @@ void ContactsManager::UserFull::store(StorerT &storer) const { if (has_location) { store(location, storer); } + if (has_work_hours) { + store(work_hours, storer); + } } template @@ -3556,6 +3562,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) { bool has_personal_photo; bool has_fallback_photo; bool has_location; + bool has_work_hours; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_about); PARSE_FLAG(is_blocked); @@ -3583,6 +3590,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) { PARSE_FLAG(read_dates_private); PARSE_FLAG(contact_require_premium); PARSE_FLAG(has_location); + PARSE_FLAG(has_work_hours); END_PARSE_FLAGS(); if (has_about) { parse(about, parser); @@ -3629,6 +3637,9 @@ void ContactsManager::UserFull::parse(ParserT &parser) { if (has_location) { parse(location, parser); } + if (has_work_hours) { + parse(work_hours, parser); + } } template @@ -12725,6 +12736,30 @@ void ContactsManager::on_update_user_full_location(UserFull *user_full, UserId u } } +void ContactsManager::on_update_user_work_hours(UserId user_id, BusinessWorkHours &&work_hours) { + LOG(INFO) << "Receive " << work_hours << " for " << user_id; + if (!user_id.is_valid()) { + LOG(ERROR) << "Receive invalid " << user_id; + return; + } + + UserFull *user_full = get_user_full_force(user_id, "on_update_user_work_hours"); + if (user_full == nullptr) { + return; + } + on_update_user_full_work_hours(user_full, user_id, std::move(work_hours)); + update_user_full(user_full, user_id, "on_update_user_work_hours"); +} + +void ContactsManager::on_update_user_full_work_hours(UserFull *user_full, UserId user_id, + BusinessWorkHours &&work_hours) { + CHECK(user_full != nullptr); + if (user_full->work_hours != work_hours) { + user_full->work_hours = std::move(work_hours); + user_full->is_changed = true; + } +} + void ContactsManager::on_update_user_full_commands(UserFull *user_full, UserId user_id, vector> &&bot_commands) { CHECK(user_full != nullptr); @@ -13112,6 +13147,7 @@ void ContactsManager::drop_user_full(UserId user_id) { user_full->commands.clear(); user_full->common_chat_count = 0; user_full->location = {}; + user_full->work_hours = {}; user_full->private_forward_name.clear(); user_full->group_administrator_rights = {}; user_full->broadcast_administrator_rights = {}; @@ -17084,7 +17120,8 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U !user_full->private_forward_name.empty(), voice_messages_forbidden, user_full->has_pinned_stories, user_full->need_phone_number_privacy_exception, user_full->wallpaper_overridden, std::move(bio_object), get_premium_payment_options_object(user_full->premium_gift_options), user_full->common_chat_count, - user_full->location.get_chat_location_object(), std::move(bot_info)); + user_full->location.get_chat_location_object(), user_full->work_hours.get_business_work_hours_object(), + std::move(bot_info)); } td_api::object_ptr ContactsManager::get_update_basic_group_object(ChatId chat_id, diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 9c6eb527b..a753664ad 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -10,6 +10,7 @@ #include "td/telegram/AccessRights.h" #include "td/telegram/BotCommand.h" #include "td/telegram/BotMenuButton.h" +#include "td/telegram/BusinessWorkHours.h" #include "td/telegram/ChannelId.h" #include "td/telegram/ChannelType.h" #include "td/telegram/ChatId.h" @@ -251,6 +252,7 @@ class ContactsManager final : public Actor { void on_update_user_has_pinned_stories(UserId user_id, bool has_pinned_stories); void on_update_user_common_chat_count(UserId user_id, int32 common_chat_count); void on_update_user_location(UserId user_id, DialogLocation &&location); + void on_update_user_work_hours(UserId user_id, BusinessWorkHours &&work_hours); void on_update_user_need_phone_number_privacy_exception(UserId user_id, bool need_phone_number_privacy_exception); void on_update_user_wallpaper_overridden(UserId user_id, bool wallpaper_overridden); @@ -828,6 +830,7 @@ class ContactsManager final : public Actor { int32 common_chat_count = 0; DialogLocation location; + BusinessWorkHours work_hours; bool is_blocked = false; bool is_blocked_for_stories = false; @@ -1435,6 +1438,7 @@ class ContactsManager final : public Actor { bool is_blocked_for_stories); static void on_update_user_full_common_chat_count(UserFull *user_full, UserId user_id, int32 common_chat_count); static void on_update_user_full_location(UserFull *user_full, UserId user_id, DialogLocation &&location); + static void on_update_user_full_work_hours(UserFull *user_full, UserId user_id, BusinessWorkHours &&work_hours); static void on_update_user_full_commands(UserFull *user_full, UserId user_id, vector> &&bot_commands); static void on_update_user_full_menu_button(UserFull *user_full, UserId user_id,