Add businessInfo.away_message_settings.

This commit is contained in:
levlam 2024-02-27 01:58:14 +03:00
parent 8c82a19ca9
commit 74fbe7f549
9 changed files with 81 additions and 10 deletions

View File

@ -625,7 +625,8 @@ businessWorkHours time_zone_id:string work_hours:vector<businessWorkHoursInterva
//@description Contains information about a Telegram Business account
//@location Location of the business; may be null if none
//@work_hours Work hours of the business; may be null if none
businessInfo location:businessLocation work_hours:businessWorkHours = BusinessInfo;
//@away_message_settings The away message; may be null if none or the Business account is not of the current user
businessInfo location:businessLocation work_hours:businessWorkHours away_message_settings:businessAwayMessageSettings = BusinessInfo;
//@class ChatPhotoStickerType @description Describes type of a sticker, which was used to create a chat photo

View File

@ -31,6 +31,10 @@ class BusinessAwayMessage {
telegram_api::object_ptr<telegram_api::inputBusinessAwayMessage> get_input_business_away_message(Td *td) const;
bool is_empty() const {
return !is_valid();
}
bool is_valid() const {
return shortcut_id_.is_server();
}

View File

@ -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);
}
}

View File

@ -8,9 +8,10 @@
namespace td {
td_api::object_ptr<td_api::businessInfo> BusinessInfo::get_business_info_object() const {
td_api::object_ptr<td_api::businessInfo> BusinessInfo::get_business_info_object(Td *td) const {
return td_api::make_object<td_api::businessInfo>(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<BusinessInfo> &business_info, DialogLocation &&location) {
@ -49,4 +50,18 @@ bool BusinessInfo::set_work_hours(unique_ptr<BusinessInfo> &business_info, Busin
return false;
}
bool BusinessInfo::set_away_message(unique_ptr<BusinessInfo> &business_info, BusinessAwayMessage &&away_message) {
if (business_info == nullptr) {
if (away_message.is_empty()) {
return false;
}
business_info = make_unique<BusinessInfo>();
}
if (business_info->away_message_ != away_message) {
business_info->away_message_ = std::move(away_message);
return true;
}
return false;
}
} // namespace td

View File

@ -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<td_api::businessInfo> get_business_info_object() const;
td_api::object_ptr<td_api::businessInfo> get_business_info_object(Td *td) const;
bool is_empty() const;
@ -26,6 +27,8 @@ class BusinessInfo {
static bool set_work_hours(unique_ptr<BusinessInfo> &business_info, BusinessWorkHours &&work_hours);
static bool set_away_message(unique_ptr<BusinessInfo> &business_info, BusinessAwayMessage &&away_message);
template <class StorerT>
void store(StorerT &storer) const;
@ -37,6 +40,7 @@ class BusinessInfo {
DialogLocation location_;
BusinessWorkHours work_hours_;
BusinessAwayMessage away_message_;
};
} // namespace td

View File

@ -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 <class StorerT>
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 <class ParserT>
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

View File

@ -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);

View File

@ -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<telegram_api::userFull> &&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<tl_object_ptr<telegram_api::botCommand>> &&bot_commands) {
CHECK(user_full != nullptr);
@ -17144,7 +17174,7 @@ tl_object_ptr<td_api::userFullInfo> 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<td_api::userFullInfo>(
get_chat_photo_object(td_->file_manager_.get(), user_full->personal_photo),

View File

@ -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<tl_object_ptr<telegram_api::botCommand>> &&bot_commands);
static void on_update_user_full_menu_button(UserFull *user_full, UserId user_id,