Add businessInfo.greeting_message_settings.

This commit is contained in:
levlam 2024-02-27 02:07:21 +03:00
parent 74fbe7f549
commit 44bdcd4920
9 changed files with 90 additions and 13 deletions

View File

@ -626,7 +626,8 @@ businessWorkHours time_zone_id:string work_hours:vector<businessWorkHoursInterva
//@location Location of the business; may be null if none
//@work_hours Work hours of the business; may be null if none
//@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;
//@greeting_message_settings The greeting 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 greeting_message_settings:businessGreetingMessageSettings = BusinessInfo;
//@class ChatPhotoStickerType @description Describes type of a sticker, which was used to create a chat photo

View File

@ -16,10 +16,13 @@
namespace td {
BusinessAwayMessage::BusinessAwayMessage(telegram_api::object_ptr<telegram_api::businessAwayMessage> 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<telegram_api::businessAwayMessage> 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<td_api::businessAwayMessageSettings> away_message) {
@ -33,7 +36,7 @@ BusinessAwayMessage::BusinessAwayMessage(td_api::object_ptr<td_api::businessAway
td_api::object_ptr<td_api::businessAwayMessageSettings> BusinessAwayMessage::get_business_away_message_settings_object(
Td *td) const {
if (!is_valid()) {
if (is_empty()) {
return nullptr;
}
return td_api::make_object<td_api::businessAwayMessageSettings>(

View File

@ -17,10 +17,13 @@
namespace td {
BusinessGreetingMessage::BusinessGreetingMessage(
telegram_api::object_ptr<telegram_api::businessGreetingMessage> 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<telegram_api::businessGreetingMessage> 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<td_api::businessGreetingMessageSettings>
BusinessGreetingMessage::get_business_greeting_message_settings_object(Td *td) const {
if (!is_valid()) {
if (is_empty()) {
return nullptr;
}
return td_api::make_object<td_api::businessGreetingMessageSettings>(

View File

@ -32,6 +32,10 @@ class BusinessGreetingMessage {
telegram_api::object_ptr<telegram_api::inputBusinessGreetingMessage> get_input_business_greeting_message(
Td *td) const;
bool is_empty() const {
return !is_valid();
}
bool is_valid() const {
return shortcut_id_.is_server();
}

View File

@ -11,7 +11,8 @@ namespace td {
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(),
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<BusinessInfo> &business_info, DialogLocation &&location) {
@ -64,4 +66,19 @@ bool BusinessInfo::set_away_message(unique_ptr<BusinessInfo> &business_info, Bus
return false;
}
bool BusinessInfo::set_greeting_message(unique_ptr<BusinessInfo> &business_info,
BusinessGreetingMessage &&greeting_message) {
if (business_info == nullptr) {
if (greeting_message.is_empty()) {
return false;
}
business_info = make_unique<BusinessInfo>();
}
if (business_info->greeting_message_ != greeting_message) {
business_info->greeting_message_ = std::move(greeting_message);
return true;
}
return false;
}
} // namespace td

View File

@ -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<BusinessInfo> &business_info, BusinessAwayMessage &&away_message);
static bool set_greeting_message(unique_ptr<BusinessInfo> &business_info, BusinessGreetingMessage &&greeting_message);
template <class StorerT>
void store(StorerT &storer) const;
@ -41,6 +44,7 @@ class BusinessInfo {
DialogLocation location_;
BusinessWorkHours work_hours_;
BusinessAwayMessage away_message_;
BusinessGreetingMessage greeting_message_;
};
} // namespace td

View File

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

View File

@ -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<telegram_api::userFull> &&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<tl_object_ptr<telegram_api::botCommand>> &&bot_commands) {
CHECK(user_full != nullptr);

View File

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