diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 8505c5a60..a3e404600 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -626,7 +626,8 @@ businessWorkHours time_zone_id:string work_hours:vector away_message) - : shortcut_id_(away_message->shortcut_id_) - , recipients_(std::move(away_message->recipients_)) - , schedule_(std::move(away_message->schedule_)) { +BusinessAwayMessage::BusinessAwayMessage(telegram_api::object_ptr away_message) { + if (away_message == nullptr) { + return; + } + shortcut_id_ = QuickReplyShortcutId(away_message->shortcut_id_); + recipients_ = BusinessRecipients(std::move(away_message->recipients_)); + schedule_ = BusinessAwayMessageSchedule(std::move(away_message->schedule_)); } BusinessAwayMessage::BusinessAwayMessage(td_api::object_ptr away_message) { @@ -33,7 +36,7 @@ BusinessAwayMessage::BusinessAwayMessage(td_api::object_ptr BusinessAwayMessage::get_business_away_message_settings_object( Td *td) const { - if (!is_valid()) { + if (is_empty()) { return nullptr; } return td_api::make_object( diff --git a/td/telegram/BusinessGreetingMessage.cpp b/td/telegram/BusinessGreetingMessage.cpp index 71bb1ee1a..08967767b 100644 --- a/td/telegram/BusinessGreetingMessage.cpp +++ b/td/telegram/BusinessGreetingMessage.cpp @@ -17,10 +17,13 @@ namespace td { BusinessGreetingMessage::BusinessGreetingMessage( - telegram_api::object_ptr greeting_message) - : shortcut_id_(greeting_message->shortcut_id_) - , recipients_(std::move(greeting_message->recipients_)) - , inactivity_days_(clamp(greeting_message->no_activity_days_ / 7 * 7, 7, 28)) { + telegram_api::object_ptr greeting_message) { + if (greeting_message == nullptr) { + return; + } + shortcut_id_ = QuickReplyShortcutId(greeting_message->shortcut_id_); + recipients_ = BusinessRecipients(std::move(greeting_message->recipients_)); + inactivity_days_ = clamp(greeting_message->no_activity_days_ / 7 * 7, 7, 28); } BusinessGreetingMessage::BusinessGreetingMessage( @@ -39,7 +42,7 @@ BusinessGreetingMessage::BusinessGreetingMessage( td_api::object_ptr BusinessGreetingMessage::get_business_greeting_message_settings_object(Td *td) const { - if (!is_valid()) { + if (is_empty()) { return nullptr; } return td_api::make_object( diff --git a/td/telegram/BusinessGreetingMessage.h b/td/telegram/BusinessGreetingMessage.h index 475954ae0..f1919f57c 100644 --- a/td/telegram/BusinessGreetingMessage.h +++ b/td/telegram/BusinessGreetingMessage.h @@ -32,6 +32,10 @@ class BusinessGreetingMessage { telegram_api::object_ptr get_input_business_greeting_message( Td *td) const; + bool is_empty() const { + return !is_valid(); + } + bool is_valid() const { return shortcut_id_.is_server(); } diff --git a/td/telegram/BusinessInfo.cpp b/td/telegram/BusinessInfo.cpp index 9451ab047..0ae2fb272 100644 --- a/td/telegram/BusinessInfo.cpp +++ b/td/telegram/BusinessInfo.cpp @@ -11,7 +11,8 @@ namespace td { td_api::object_ptr BusinessInfo::get_business_info_object(Td *td) const { return td_api::make_object(location_.get_business_location_object(), work_hours_.get_business_work_hours_object(), - away_message_.get_business_away_message_settings_object(td)); + away_message_.get_business_away_message_settings_object(td), + greeting_message_.get_business_greeting_message_settings_object(td)); } bool BusinessInfo::is_empty_location(const DialogLocation &location) { @@ -19,7 +20,8 @@ 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(); + return is_empty_location(location_) && work_hours_.is_empty() && away_message_.is_empty() && + greeting_message_.is_empty(); } bool BusinessInfo::set_location(unique_ptr &business_info, DialogLocation &&location) { @@ -64,4 +66,19 @@ bool BusinessInfo::set_away_message(unique_ptr &business_info, Bus return false; } +bool BusinessInfo::set_greeting_message(unique_ptr &business_info, + BusinessGreetingMessage &&greeting_message) { + if (business_info == nullptr) { + if (greeting_message.is_empty()) { + return false; + } + business_info = make_unique(); + } + if (business_info->greeting_message_ != greeting_message) { + business_info->greeting_message_ = std::move(greeting_message); + return true; + } + return false; +} + } // namespace td diff --git a/td/telegram/BusinessInfo.h b/td/telegram/BusinessInfo.h index 33e0fe19d..4750be32c 100644 --- a/td/telegram/BusinessInfo.h +++ b/td/telegram/BusinessInfo.h @@ -7,6 +7,7 @@ #pragma once #include "td/telegram/BusinessAwayMessage.h" +#include "td/telegram/BusinessGreetingMessage.h" #include "td/telegram/BusinessWorkHours.h" #include "td/telegram/DialogLocation.h" #include "td/telegram/td_api.h" @@ -29,6 +30,8 @@ class BusinessInfo { static bool set_away_message(unique_ptr &business_info, BusinessAwayMessage &&away_message); + static bool set_greeting_message(unique_ptr &business_info, BusinessGreetingMessage &&greeting_message); + template void store(StorerT &storer) const; @@ -41,6 +44,7 @@ class BusinessInfo { DialogLocation location_; BusinessWorkHours work_hours_; BusinessAwayMessage away_message_; + BusinessGreetingMessage greeting_message_; }; } // namespace td diff --git a/td/telegram/BusinessInfo.hpp b/td/telegram/BusinessInfo.hpp index 71ce1a9be..390ba313e 100644 --- a/td/telegram/BusinessInfo.hpp +++ b/td/telegram/BusinessInfo.hpp @@ -9,6 +9,7 @@ #include "td/telegram/BusinessInfo.h" #include "td/telegram/BusinessAwayMessage.hpp" +#include "td/telegram/BusinessGreetingMessage.hpp" #include "td/telegram/BusinessWorkHours.hpp" #include "td/utils/common.h" @@ -21,10 +22,12 @@ void BusinessInfo::store(StorerT &storer) const { bool has_location = !is_empty_location(location_); bool has_work_hours = !work_hours_.is_empty(); bool has_away_message = away_message_.is_valid(); + bool has_greeting_message = greeting_message_.is_valid(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_location); STORE_FLAG(has_work_hours); STORE_FLAG(has_away_message); + STORE_FLAG(has_greeting_message); END_STORE_FLAGS(); if (has_location) { td::store(location_, storer); @@ -35,6 +38,9 @@ void BusinessInfo::store(StorerT &storer) const { if (has_away_message) { td::store(away_message_, storer); } + if (has_greeting_message) { + td::store(greeting_message_, storer); + } } template @@ -42,10 +48,12 @@ void BusinessInfo::parse(ParserT &parser) { bool has_location; bool has_work_hours; bool has_away_message; + bool has_greeting_message; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_location); PARSE_FLAG(has_work_hours); PARSE_FLAG(has_away_message); + PARSE_FLAG(has_greeting_message); END_PARSE_FLAGS(); if (has_location) { td::parse(location_, parser); @@ -56,6 +64,9 @@ void BusinessInfo::parse(ParserT &parser) { if (has_away_message) { td::parse(away_message_, parser); } + if (has_greeting_message) { + td::parse(greeting_message_, parser); + } } } // namespace td diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 5a3c446c7..82cd72a95 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -12,6 +12,7 @@ #include "td/telegram/BlockListId.h" #include "td/telegram/BotMenuButton.h" #include "td/telegram/BusinessAwayMessage.h" +#include "td/telegram/BusinessGreetingMessage.h" #include "td/telegram/BusinessInfo.h" #include "td/telegram/BusinessInfo.hpp" #include "td/telegram/BusinessWorkHours.h" @@ -11375,6 +11376,8 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u on_update_user_full_location(user_full, user_id, DialogLocation(td_, std::move(user->business_location_))); on_update_user_full_work_hours(user_full, user_id, BusinessWorkHours(std::move(user->business_work_hours_))); 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_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_); @@ -12822,6 +12825,33 @@ void ContactsManager::on_update_user_full_away_message(UserFull *user_full, User } } +void ContactsManager::on_update_user_greeting_message(UserId user_id, BusinessGreetingMessage &&greeting_message) { + LOG(INFO) << "Receive " << greeting_message << " 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_greeting_message"); + if (user_full == nullptr) { + return; + } + on_update_user_full_greeting_message(user_full, user_id, std::move(greeting_message)); + update_user_full(user_full, user_id, "on_update_user_greeting_message"); +} + +void ContactsManager::on_update_user_full_greeting_message(UserFull *user_full, UserId user_id, + BusinessGreetingMessage &&greeting_message) const { + CHECK(user_full != nullptr); + if (greeting_message.is_valid() && user_id != get_my_id()) { + LOG(ERROR) << "Receive " << greeting_message << " for " << user_id; + return; + } + if (BusinessInfo::set_greeting_message(user_full->business_info, std::move(greeting_message))) { + 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); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 7a8377846..64b951164 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -67,6 +67,7 @@ namespace td { struct BinlogEvent; class BusinessAwayMessage; +class BusinessGreetingMessage; class BusinessInfo; class BusinessWorkHours; struct MinChannel; @@ -254,6 +255,7 @@ class ContactsManager final : public Actor { 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_away_message(UserId user_id, BusinessAwayMessage &&away_message); + void on_update_user_greeting_message(UserId user_id, BusinessGreetingMessage &&greeting_message); 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); @@ -1442,6 +1444,8 @@ class ContactsManager final : public Actor { 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); 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_commands(UserFull *user_full, UserId user_id, vector> &&bot_commands); static void on_update_user_full_menu_button(UserFull *user_full, UserId user_id,