Add td_api::businessInfo.

This commit is contained in:
levlam 2024-02-26 23:09:52 +03:00
parent 0636fb180e
commit 72a4cd0398
8 changed files with 175 additions and 35 deletions

View File

@ -304,6 +304,7 @@ set(TDLIB_SOURCE
td/telegram/BusinessAwayMessage.cpp
td/telegram/BusinessAwayMessageSchedule.cpp
td/telegram/BusinessGreetingMessage.cpp
td/telegram/BusinessInfo.cpp
td/telegram/BusinessRecipients.cpp
td/telegram/BusinessWorkHours.cpp
td/telegram/CallActor.cpp
@ -587,6 +588,7 @@ set(TDLIB_SOURCE
td/telegram/BusinessAwayMessage.h
td/telegram/BusinessAwayMessageSchedule.h
td/telegram/BusinessGreetingMessage.h
td/telegram/BusinessInfo.h
td/telegram/BusinessRecipients.h
td/telegram/BusinessWorkHours.h
td/telegram/CallActor.h
@ -890,6 +892,7 @@ set(TDLIB_SOURCE
td/telegram/BusinessAwayMessage.hpp
td/telegram/BusinessAwayMessageSchedule.hpp
td/telegram/BusinessGreetingMessage.hpp
td/telegram/BusinessInfo.hpp
td/telegram/BusinessRecipients.hpp
td/telegram/BusinessWorkHours.hpp
td/telegram/ChatReactions.hpp

View File

@ -311,6 +311,7 @@ function split_file($file, $chunks, $undo) {
'bot_info_manager[_(-](?![.]get[(][)])|BotInfoManager' => 'BotInfoManager',
'BusinessAwayMessage' => 'BusinessAwayMessage',
'BusinessGreetingMessage' => 'BusinessGreetingMessage',
'BusinessInfo|business_info' => 'BusinessInfo',
'BusinessRecipients' => 'BusinessRecipients',
'BusinessWorkHours' => 'BusinessWorkHours',
'callback_queries_manager[_(-](?![.]get[(][)])|CallbackQueriesManager' => 'CallbackQueriesManager',

View File

@ -622,6 +622,11 @@ businessWorkHoursInterval start_minute:int32 end_minute:int32 = BusinessWorkHour
//@description Describes work hours of a business @time_zone_id Unique time zone identifier @work_hours Intervals of the time when the business is open
businessWorkHours time_zone_id:string work_hours:vector<businessWorkHoursInterval> = BusinessWorkHours;
//@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;
//@class ChatPhotoStickerType @description Describes type of a sticker, which was used to create a chat photo
@ -894,10 +899,9 @@ botInfo short_description:string description:string photo:photo animation:animat
//@bio A short user bio; may be null for bots
//@premium_gift_options The list of available options for gifting Telegram Premium to the user
//@group_in_common_count Number of group chats where both the other user and the current user are a member; 0 for the current user
//@business_location Location of the business for Telegram Business users; may be null if none
//@business_work_hours Work hours of the business for Telegram Business users; may be null if none
//@business_info Information about business settings for Telegram Business accounts; may be null if none
//@bot_info For bots, information about the bot; may be null if the user isn't a bot
userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto block_list:BlockList can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool has_pinned_stories:Bool need_phone_number_privacy_exception:Bool set_chat_background:Bool bio:formattedText premium_gift_options:vector<premiumPaymentOption> group_in_common_count:int32 business_location:businessLocation business_work_hours:businessWorkHours bot_info:botInfo = UserFullInfo;
userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto block_list:BlockList can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool has_pinned_stories:Bool need_phone_number_privacy_exception:Bool set_chat_background:Bool bio:formattedText premium_gift_options:vector<premiumPaymentOption> group_in_common_count:int32 business_info:businessInfo bot_info:botInfo = UserFullInfo;
//@description Represents a list of users @total_count Approximate total number of users found @user_ids A list of user identifiers
users total_count:int32 user_ids:vector<int53> = Users;

View File

@ -0,0 +1,52 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/BusinessInfo.h"
namespace td {
td_api::object_ptr<td_api::businessInfo> BusinessInfo::get_business_info_object() const {
return td_api::make_object<td_api::businessInfo>(location_.get_business_location_object(),
work_hours_.get_business_work_hours_object());
}
bool BusinessInfo::is_empty_location(const DialogLocation &location) {
return location.empty() && location.get_address().empty();
}
bool BusinessInfo::is_empty() const {
return is_empty_location(location_) && work_hours_.is_empty();
}
bool BusinessInfo::set_location(unique_ptr<BusinessInfo> &business_info, DialogLocation &&location) {
if (business_info == nullptr) {
if (is_empty_location(location)) {
return false;
}
business_info = make_unique<BusinessInfo>();
}
if (business_info->location_ != location) {
business_info->location_ = std::move(location);
return true;
}
return false;
}
bool BusinessInfo::set_work_hours(unique_ptr<BusinessInfo> &business_info, BusinessWorkHours &&work_hours) {
if (business_info == nullptr) {
if (work_hours.is_empty()) {
return false;
}
business_info = make_unique<BusinessInfo>();
}
if (business_info->work_hours_ != work_hours) {
business_info->work_hours_ = std::move(work_hours);
return true;
}
return false;
}
} // namespace td

View File

@ -0,0 +1,42 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/BusinessWorkHours.h"
#include "td/telegram/DialogLocation.h"
#include "td/telegram/td_api.h"
#include "td/utils/common.h"
namespace td {
class Td;
class BusinessInfo {
public:
td_api::object_ptr<td_api::businessInfo> get_business_info_object() const;
bool is_empty() const;
static bool set_location(unique_ptr<BusinessInfo> &business_info, DialogLocation &&location);
static bool set_work_hours(unique_ptr<BusinessInfo> &business_info, BusinessWorkHours &&work_hours);
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
private:
static bool is_empty_location(const DialogLocation &location);
DialogLocation location_;
BusinessWorkHours work_hours_;
};
} // namespace td

View File

@ -0,0 +1,49 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/BusinessInfo.h"
#include "td/telegram/BusinessWorkHours.hpp"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void BusinessInfo::store(StorerT &storer) const {
bool has_location = !is_empty_location(location_);
bool has_work_hours = !work_hours_.is_empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_location);
STORE_FLAG(has_work_hours);
END_STORE_FLAGS();
if (has_location) {
td::store(location_, storer);
}
if (has_work_hours) {
td::store(work_hours_, storer);
}
}
template <class ParserT>
void BusinessInfo::parse(ParserT &parser) {
bool has_location;
bool has_work_hours;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_location);
PARSE_FLAG(has_work_hours);
END_PARSE_FLAGS();
if (has_location) {
td::parse(location_, parser);
}
if (has_work_hours) {
td::parse(work_hours_, parser);
}
}
} // namespace td

View File

@ -11,7 +11,9 @@
#include "td/telegram/AuthManager.h"
#include "td/telegram/BlockListId.h"
#include "td/telegram/BotMenuButton.h"
#include "td/telegram/BusinessWorkHours.hpp"
#include "td/telegram/BusinessInfo.h"
#include "td/telegram/BusinessInfo.hpp"
#include "td/telegram/BusinessWorkHours.h"
#include "td/telegram/CommonDialogManager.h"
#include "td/telegram/ConfigManager.h"
#include "td/telegram/Dependencies.h"
@ -3501,8 +3503,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const {
bool has_premium_gift_options = !premium_gift_options.empty();
bool has_personal_photo = !personal_photo.is_empty();
bool has_fallback_photo = !fallback_photo.is_empty();
bool has_location = !location.empty() || !location.get_address().empty();
bool has_work_hours = !work_hours.is_empty();
bool has_business_info = business_info != nullptr && !business_info->is_empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_about);
STORE_FLAG(is_blocked);
@ -3529,8 +3530,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const {
STORE_FLAG(wallpaper_overridden);
STORE_FLAG(read_dates_private);
STORE_FLAG(contact_require_premium);
STORE_FLAG(has_location); // 25
STORE_FLAG(has_work_hours);
STORE_FLAG(has_business_info); // 25
END_STORE_FLAGS();
if (has_about) {
store(about, storer);
@ -3574,11 +3574,8 @@ void ContactsManager::UserFull::store(StorerT &storer) const {
if (has_fallback_photo) {
store(fallback_photo, storer);
}
if (has_location) {
store(location, storer);
}
if (has_work_hours) {
store(work_hours, storer);
if (has_business_info) {
store(business_info, storer);
}
}
@ -3598,8 +3595,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) {
bool has_premium_gift_options;
bool has_personal_photo;
bool has_fallback_photo;
bool has_location;
bool has_work_hours;
bool has_business_info;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_about);
PARSE_FLAG(is_blocked);
@ -3626,8 +3622,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) {
PARSE_FLAG(wallpaper_overridden);
PARSE_FLAG(read_dates_private);
PARSE_FLAG(contact_require_premium);
PARSE_FLAG(has_location);
PARSE_FLAG(has_work_hours);
PARSE_FLAG(has_business_info);
END_PARSE_FLAGS();
if (has_about) {
parse(about, parser);
@ -3671,11 +3666,8 @@ void ContactsManager::UserFull::parse(ParserT &parser) {
if (has_fallback_photo) {
parse(fallback_photo, parser);
}
if (has_location) {
parse(location, parser);
}
if (has_work_hours) {
parse(work_hours, parser);
if (has_business_info) {
parse(business_info, parser);
}
}
@ -12772,8 +12764,7 @@ void ContactsManager::on_update_user_location(UserId user_id, DialogLocation &&l
void ContactsManager::on_update_user_full_location(UserFull *user_full, UserId user_id, DialogLocation &&location) {
CHECK(user_full != nullptr);
if (user_full->location != location) {
user_full->location = std::move(location);
if (BusinessInfo::set_location(user_full->business_info, std::move(location))) {
user_full->is_changed = true;
}
}
@ -12796,8 +12787,7 @@ void ContactsManager::on_update_user_work_hours(UserId user_id, BusinessWorkHour
void ContactsManager::on_update_user_full_work_hours(UserFull *user_full, UserId user_id,
BusinessWorkHours &&work_hours) {
CHECK(user_full != nullptr);
if (user_full->work_hours != work_hours) {
user_full->work_hours = std::move(work_hours);
if (BusinessInfo::set_work_hours(user_full->business_info, std::move(work_hours))) {
user_full->is_changed = true;
}
}
@ -13188,8 +13178,7 @@ void ContactsManager::drop_user_full(UserId user_id) {
user_full->menu_button = nullptr;
user_full->commands.clear();
user_full->common_chat_count = 0;
user_full->location = {};
user_full->work_hours = {};
user_full->business_info = nullptr;
user_full->private_forward_name.clear();
user_full->group_administrator_rights = {};
user_full->broadcast_administrator_rights = {};
@ -17154,6 +17143,9 @@ 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()
: nullptr;
return td_api::make_object<td_api::userFullInfo>(
get_chat_photo_object(td_->file_manager_.get(), user_full->personal_photo),
get_chat_photo_object(td_->file_manager_.get(), user_full->photo),
@ -17162,8 +17154,7 @@ tl_object_ptr<td_api::userFullInfo> ContactsManager::get_user_full_info_object(U
!user_full->private_forward_name.empty(), voice_messages_forbidden, user_full->has_pinned_stories,
user_full->need_phone_number_privacy_exception, user_full->wallpaper_overridden, std::move(bio_object),
get_premium_payment_options_object(user_full->premium_gift_options), user_full->common_chat_count,
user_full->location.get_business_location_object(), user_full->work_hours.get_business_work_hours_object(),
std::move(bot_info));
std::move(business_info), std::move(bot_info));
}
td_api::object_ptr<td_api::updateBasicGroup> ContactsManager::get_update_basic_group_object(ChatId chat_id,

View File

@ -10,7 +10,6 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/BotCommand.h"
#include "td/telegram/BotMenuButton.h"
#include "td/telegram/BusinessWorkHours.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ChatId.h"
@ -67,9 +66,9 @@
namespace td {
struct BinlogEvent;
class BusinessInfo;
class BusinessWorkHours;
struct MinChannel;
class Td;
class ContactsManager final : public Actor {
@ -831,8 +830,7 @@ class ContactsManager final : public Actor {
int32 common_chat_count = 0;
DialogLocation location;
BusinessWorkHours work_hours;
unique_ptr<BusinessInfo> business_info;
bool is_blocked = false;
bool is_blocked_for_stories = false;