diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 935c2e8a5..8505c5a60 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -625,7 +625,8 @@ businessWorkHours time_zone_id:string work_hours:vector get_input_business_away_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/BusinessAwayMessageSchedule.hpp b/td/telegram/BusinessAwayMessageSchedule.hpp index acd4b3645..82c6b0b51 100644 --- a/td/telegram/BusinessAwayMessageSchedule.hpp +++ b/td/telegram/BusinessAwayMessageSchedule.hpp @@ -23,10 +23,10 @@ void BusinessAwayMessageSchedule::store(StorerT &storer) const { END_STORE_FLAGS(); td::store(type_, storer); if (has_start_date) { - td::store(start_date, storer); + td::store(start_date_, storer); } if (has_end_date) { - td::store(end_date, storer); + td::store(end_date_, storer); } } @@ -40,10 +40,10 @@ void BusinessAwayMessageSchedule::parse(ParserT &parser) { END_PARSE_FLAGS(); td::parse(type_, parser); if (has_start_date) { - td::parse(start_date, parser); + td::parse(start_date_, parser); } if (has_end_date) { - td::parse(end_date, parser); + td::parse(end_date_, parser); } } diff --git a/td/telegram/BusinessInfo.cpp b/td/telegram/BusinessInfo.cpp index 9a607f3e0..9451ab047 100644 --- a/td/telegram/BusinessInfo.cpp +++ b/td/telegram/BusinessInfo.cpp @@ -8,9 +8,10 @@ namespace td { -td_api::object_ptr BusinessInfo::get_business_info_object() const { +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()); + work_hours_.get_business_work_hours_object(), + away_message_.get_business_away_message_settings_object(td)); } bool BusinessInfo::is_empty_location(const DialogLocation &location) { @@ -18,7 +19,7 @@ bool BusinessInfo::is_empty_location(const DialogLocation &location) { } bool BusinessInfo::is_empty() const { - return is_empty_location(location_) && work_hours_.is_empty(); + return is_empty_location(location_) && work_hours_.is_empty() && away_message_.is_empty(); } bool BusinessInfo::set_location(unique_ptr &business_info, DialogLocation &&location) { @@ -49,4 +50,18 @@ bool BusinessInfo::set_work_hours(unique_ptr &business_info, Busin return false; } +bool BusinessInfo::set_away_message(unique_ptr &business_info, BusinessAwayMessage &&away_message) { + if (business_info == nullptr) { + if (away_message.is_empty()) { + return false; + } + business_info = make_unique(); + } + if (business_info->away_message_ != away_message) { + business_info->away_message_ = std::move(away_message); + return true; + } + return false; +} + } // namespace td diff --git a/td/telegram/BusinessInfo.h b/td/telegram/BusinessInfo.h index b18154687..33e0fe19d 100644 --- a/td/telegram/BusinessInfo.h +++ b/td/telegram/BusinessInfo.h @@ -6,6 +6,7 @@ // #pragma once +#include "td/telegram/BusinessAwayMessage.h" #include "td/telegram/BusinessWorkHours.h" #include "td/telegram/DialogLocation.h" #include "td/telegram/td_api.h" @@ -18,7 +19,7 @@ class Td; class BusinessInfo { public: - td_api::object_ptr get_business_info_object() const; + td_api::object_ptr get_business_info_object(Td *td) const; bool is_empty() const; @@ -26,6 +27,8 @@ class BusinessInfo { static bool set_work_hours(unique_ptr &business_info, BusinessWorkHours &&work_hours); + static bool set_away_message(unique_ptr &business_info, BusinessAwayMessage &&away_message); + template void store(StorerT &storer) const; @@ -37,6 +40,7 @@ class BusinessInfo { DialogLocation location_; BusinessWorkHours work_hours_; + BusinessAwayMessage away_message_; }; } // namespace td diff --git a/td/telegram/BusinessInfo.hpp b/td/telegram/BusinessInfo.hpp index 089817eb4..71ce1a9be 100644 --- a/td/telegram/BusinessInfo.hpp +++ b/td/telegram/BusinessInfo.hpp @@ -7,6 +7,8 @@ #pragma once #include "td/telegram/BusinessInfo.h" + +#include "td/telegram/BusinessAwayMessage.hpp" #include "td/telegram/BusinessWorkHours.hpp" #include "td/utils/common.h" @@ -18,9 +20,11 @@ template 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(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_location); STORE_FLAG(has_work_hours); + STORE_FLAG(has_away_message); END_STORE_FLAGS(); if (has_location) { td::store(location_, storer); @@ -28,15 +32,20 @@ void BusinessInfo::store(StorerT &storer) const { if (has_work_hours) { td::store(work_hours_, storer); } + if (has_away_message) { + td::store(away_message_, storer); + } } template void BusinessInfo::parse(ParserT &parser) { bool has_location; bool has_work_hours; + bool has_away_message; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_location); PARSE_FLAG(has_work_hours); + PARSE_FLAG(has_away_message); END_PARSE_FLAGS(); if (has_location) { td::parse(location_, parser); @@ -44,6 +53,9 @@ void BusinessInfo::parse(ParserT &parser) { if (has_work_hours) { td::parse(work_hours_, parser); } + if (has_away_message) { + td::parse(away_message_, parser); + } } } // namespace td diff --git a/td/telegram/BusinessRecipients.hpp b/td/telegram/BusinessRecipients.hpp index 064452c7a..f073a6fe5 100644 --- a/td/telegram/BusinessRecipients.hpp +++ b/td/telegram/BusinessRecipients.hpp @@ -22,6 +22,7 @@ void BusinessRecipients::store(StorerT &storer) const { STORE_FLAG(contacts_); STORE_FLAG(non_contacts_); STORE_FLAG(exclude_selected_); + STORE_FLAG(has_user_ids); END_STORE_FLAGS(); if (has_user_ids) { td::store(user_ids_, storer); @@ -37,6 +38,7 @@ void BusinessRecipients::parse(ParserT &parser) { PARSE_FLAG(contacts_); PARSE_FLAG(non_contacts_); PARSE_FLAG(exclude_selected_); + PARSE_FLAG(has_user_ids); END_PARSE_FLAGS(); if (has_user_ids) { td::parse(user_ids_, parser); diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index da4b9bda1..5a3c446c7 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/BusinessAwayMessage.h" #include "td/telegram/BusinessInfo.h" #include "td/telegram/BusinessInfo.hpp" #include "td/telegram/BusinessWorkHours.h" @@ -11372,6 +11373,8 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u on_update_user_full_is_blocked(user_full, user_id, user->blocked_, user->blocked_my_stories_from_); on_update_user_full_common_chat_count(user_full, user_id, user->common_chats_count_); 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_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_); @@ -12792,6 +12795,33 @@ void ContactsManager::on_update_user_full_work_hours(UserFull *user_full, UserId } } +void ContactsManager::on_update_user_away_message(UserId user_id, BusinessAwayMessage &&away_message) { + LOG(INFO) << "Receive " << away_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_away_message"); + if (user_full == nullptr) { + return; + } + on_update_user_full_away_message(user_full, user_id, std::move(away_message)); + update_user_full(user_full, user_id, "on_update_user_away_message"); +} + +void ContactsManager::on_update_user_full_away_message(UserFull *user_full, UserId user_id, + BusinessAwayMessage &&away_message) const { + CHECK(user_full != nullptr); + if (away_message.is_valid() && user_id != get_my_id()) { + LOG(ERROR) << "Receive " << away_message << " for " << user_id; + return; + } + if (BusinessInfo::set_away_message(user_full->business_info, std::move(away_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); @@ -17144,7 +17174,7 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U auto voice_messages_forbidden = is_premium ? user_full->voice_messages_forbidden : false; auto block_list_id = BlockListId(user_full->is_blocked, user_full->is_blocked_for_stories); auto business_info = is_premium && user_full->business_info != nullptr - ? user_full->business_info->get_business_info_object() + ? user_full->business_info->get_business_info_object(td_) : nullptr; return td_api::make_object( get_chat_photo_object(td_->file_manager_.get(), user_full->personal_photo), diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 3bdfb7105..7a8377846 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -66,6 +66,7 @@ namespace td { struct BinlogEvent; +class BusinessAwayMessage; class BusinessInfo; class BusinessWorkHours; struct MinChannel; @@ -252,6 +253,7 @@ class ContactsManager final : public Actor { 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_away_message(UserId user_id, BusinessAwayMessage &&away_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); @@ -1439,6 +1441,7 @@ class ContactsManager final : public Actor { 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); + void on_update_user_full_away_message(UserFull *user_full, UserId user_id, BusinessAwayMessage &&away_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,