diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f3435ca8e..31481fd4d 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -646,7 +646,8 @@ businessOpeningHours time_zone_id:string opening_hours:vector BusinessInfo::get_business_info_object( if (is_empty()) { return nullptr; } - return td_api::make_object(location_.get_business_location_object(), - work_hours_.get_business_opening_hours_object(), - greeting_message_.get_business_greeting_message_settings_object(td), - away_message_.get_business_away_message_settings_object(td)); + return td_api::make_object( + location_.get_business_location_object(), work_hours_.get_business_opening_hours_object(), + greeting_message_.get_business_greeting_message_settings_object(td), + away_message_.get_business_away_message_settings_object(td), intro_.get_business_intro_object(td)); } bool BusinessInfo::is_empty_location(const DialogLocation &location) { @@ -24,7 +24,7 @@ bool BusinessInfo::is_empty_location(const DialogLocation &location) { bool BusinessInfo::is_empty() const { return is_empty_location(location_) && work_hours_.is_empty() && away_message_.is_empty() && - greeting_message_.is_empty(); + greeting_message_.is_empty() && intro_.is_empty(); } bool BusinessInfo::set_location(unique_ptr &business_info, DialogLocation &&location) { @@ -84,4 +84,18 @@ bool BusinessInfo::set_greeting_message(unique_ptr &business_info, return false; } +bool BusinessInfo::set_intro(unique_ptr &business_info, BusinessIntro &&intro) { + if (business_info == nullptr) { + if (intro.is_empty()) { + return false; + } + business_info = make_unique(); + } + if (business_info->intro_ != intro) { + business_info->intro_ = std::move(intro); + return true; + } + return false; +} + } // namespace td diff --git a/td/telegram/BusinessInfo.h b/td/telegram/BusinessInfo.h index 4750be32c..c59eef021 100644 --- a/td/telegram/BusinessInfo.h +++ b/td/telegram/BusinessInfo.h @@ -8,6 +8,7 @@ #include "td/telegram/BusinessAwayMessage.h" #include "td/telegram/BusinessGreetingMessage.h" +#include "td/telegram/BusinessIntro.h" #include "td/telegram/BusinessWorkHours.h" #include "td/telegram/DialogLocation.h" #include "td/telegram/td_api.h" @@ -32,6 +33,8 @@ class BusinessInfo { static bool set_greeting_message(unique_ptr &business_info, BusinessGreetingMessage &&greeting_message); + static bool set_intro(unique_ptr &business_info, BusinessIntro &&intro); + template void store(StorerT &storer) const; @@ -45,6 +48,7 @@ class BusinessInfo { BusinessWorkHours work_hours_; BusinessAwayMessage away_message_; BusinessGreetingMessage greeting_message_; + BusinessIntro intro_; }; } // namespace td diff --git a/td/telegram/BusinessInfo.hpp b/td/telegram/BusinessInfo.hpp index 390ba313e..c59764d68 100644 --- a/td/telegram/BusinessInfo.hpp +++ b/td/telegram/BusinessInfo.hpp @@ -10,6 +10,7 @@ #include "td/telegram/BusinessAwayMessage.hpp" #include "td/telegram/BusinessGreetingMessage.hpp" +#include "td/telegram/BusinessIntro.hpp" #include "td/telegram/BusinessWorkHours.hpp" #include "td/utils/common.h" @@ -23,11 +24,13 @@ void BusinessInfo::store(StorerT &storer) const { bool has_work_hours = !work_hours_.is_empty(); bool has_away_message = away_message_.is_valid(); bool has_greeting_message = greeting_message_.is_valid(); + bool has_intro = !intro_.is_empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_location); STORE_FLAG(has_work_hours); STORE_FLAG(has_away_message); STORE_FLAG(has_greeting_message); + STORE_FLAG(has_intro); END_STORE_FLAGS(); if (has_location) { td::store(location_, storer); @@ -41,6 +44,9 @@ void BusinessInfo::store(StorerT &storer) const { if (has_greeting_message) { td::store(greeting_message_, storer); } + if (has_intro) { + td::store(intro_, storer); + } } template @@ -49,11 +55,13 @@ void BusinessInfo::parse(ParserT &parser) { bool has_work_hours; bool has_away_message; bool has_greeting_message; + bool has_intro; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_location); PARSE_FLAG(has_work_hours); PARSE_FLAG(has_away_message); PARSE_FLAG(has_greeting_message); + PARSE_FLAG(has_intro); END_PARSE_FLAGS(); if (has_location) { td::parse(location_, parser); @@ -67,6 +75,9 @@ void BusinessInfo::parse(ParserT &parser) { if (has_greeting_message) { td::parse(greeting_message_, parser); } + if (has_intro) { + td::parse(intro_, parser); + } } } // namespace td diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index ed32eb882..4d036e60d 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -14,6 +14,7 @@ #include "td/telegram/BusinessGreetingMessage.h" #include "td/telegram/BusinessInfo.h" #include "td/telegram/BusinessInfo.hpp" +#include "td/telegram/BusinessIntro.h" #include "td/telegram/BusinessWorkHours.h" #include "td/telegram/CommonDialogManager.h" #include "td/telegram/ConfigManager.h" @@ -10302,6 +10303,7 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u on_update_user_full_away_message(user_full, user_id, BusinessAwayMessage(std::move(user->business_away_message_))); on_update_user_full_greeting_message(user_full, user_id, BusinessGreetingMessage(std::move(user->business_greeting_message_))); + on_update_user_full_intro(user_full, user_id, BusinessIntro(td_, std::move(user->business_intro_))); on_update_user_full_need_phone_number_privacy_exception(user_full, user_id, user->settings_->need_contacts_exception_); on_update_user_full_wallpaper_overridden(user_full, user_id, user->wallpaper_overridden_); @@ -11751,6 +11753,28 @@ void ContactsManager::on_update_user_full_greeting_message(UserFull *user_full, } } +void ContactsManager::on_update_user_intro(UserId user_id, BusinessIntro &&intro) { + LOG(INFO) << "Receive " << intro << " 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_intro"); + if (user_full == nullptr) { + return; + } + on_update_user_full_intro(user_full, user_id, std::move(intro)); + update_user_full(user_full, user_id, "on_update_user_intro"); +} + +void ContactsManager::on_update_user_full_intro(UserFull *user_full, UserId user_id, BusinessIntro &&intro) { + CHECK(user_full != nullptr); + if (BusinessInfo::set_intro(user_full->business_info, std::move(intro))) { + user_full->is_changed = true; + } +} + void ContactsManager::on_update_user_commands( UserId user_id, vector> &&bot_commands) { UserFull *user_full = get_user_full_force(user_id, "on_update_user_commands"); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index c6e0289c6..9f89ef1e2 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -67,6 +67,7 @@ struct BinlogEvent; class BusinessAwayMessage; class BusinessGreetingMessage; class BusinessInfo; +class BusinessIntro; class BusinessWorkHours; struct MinChannel; class Td; @@ -258,6 +259,7 @@ class ContactsManager final : public Actor { void on_update_user_work_hours(UserId user_id, BusinessWorkHours &&work_hours); void on_update_user_away_message(UserId user_id, BusinessAwayMessage &&away_message); void on_update_user_greeting_message(UserId user_id, BusinessGreetingMessage &&greeting_message); + void on_update_user_intro(UserId user_id, BusinessIntro &&intro); 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); void on_update_user_commands(UserId user_id, @@ -1390,6 +1392,7 @@ class ContactsManager final : public Actor { void on_update_user_full_away_message(UserFull *user_full, UserId user_id, BusinessAwayMessage &&away_message) const; void on_update_user_full_greeting_message(UserFull *user_full, UserId user_id, BusinessGreetingMessage &&greeting_message) const; + static void on_update_user_full_intro(UserFull *user_full, UserId user_id, BusinessIntro &&intro); 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,