Add class BusinessIntro.

This commit is contained in:
levlam 2024-03-18 23:46:08 +03:00
parent b28e1d2fd8
commit dd0fb9486f
6 changed files with 214 additions and 0 deletions

View File

@ -307,6 +307,7 @@ set(TDLIB_SOURCE
td/telegram/BusinessConnectionManager.cpp
td/telegram/BusinessGreetingMessage.cpp
td/telegram/BusinessInfo.cpp
td/telegram/BusinessIntro.cpp
td/telegram/BusinessManager.cpp
td/telegram/BusinessRecipients.cpp
td/telegram/BusinessWorkHours.cpp
@ -597,6 +598,7 @@ set(TDLIB_SOURCE
td/telegram/BusinessConnectionManager.h
td/telegram/BusinessGreetingMessage.h
td/telegram/BusinessInfo.h
td/telegram/BusinessIntro.h
td/telegram/BusinessManager.h
td/telegram/BusinessRecipients.h
td/telegram/BusinessWorkHours.h
@ -906,6 +908,7 @@ set(TDLIB_SOURCE
td/telegram/BusinessConnectedBot.hpp
td/telegram/BusinessGreetingMessage.hpp
td/telegram/BusinessInfo.hpp
td/telegram/BusinessIntro.hpp
td/telegram/BusinessRecipients.hpp
td/telegram/BusinessWorkHours.hpp
td/telegram/ChatReactions.hpp

View File

@ -315,6 +315,7 @@ function split_file($file, $chunks, $undo) {
'business_connection_manager[_(-](?![.]get[(][)])|BusinessConnectionManager' => 'BusinessConnectionManager',
'BusinessGreetingMessage' => 'BusinessGreetingMessage',
'BusinessInfo|business_info' => 'BusinessInfo',
'BusinessIntro' => 'BusinessIntro',
'business_manager[_(-](?![.]get[(][)])|BusinessManager' => 'BusinessManager',
'BusinessRecipients' => 'BusinessRecipients',
'BusinessWorkHours' => 'BusinessWorkHours',

View File

@ -621,6 +621,18 @@ businessGreetingMessageSettings shortcut_id:int32 recipients:businessRecipients
//@can_reply True, if the bot can send messages to the private chats; false otherwise
businessConnectedBot bot_user_id:int53 recipients:businessRecipients can_reply:Bool = BusinessConnectedBot;
//@description Describes settings for a business account intro
//@title Title text of the intro
//@param_description Description text of the intro
//@sticker Greeting sticker of the intro; may be null if none
businessIntro title:string description:string sticker:sticker = BusinessIntro;
//@description Describes settings for a business account intro to set
//@title Title text of the intro
//@param_description Description text of the intro
//@sticker Greeting sticker of the intro; pass null if none. The sticker must belong to a sticker set and must not be a custom emoji
inputBusinessIntro title:string description:string sticker:InputFile = InputBusinessIntro;
//@description Describes an interval of time when the business is open
//@start_minute The first minute of the interval since start of the week; 0-7*24*60
//@end_minute The first minute after the end of the interval since start of the week; 1-8*24*60

View File

@ -0,0 +1,75 @@
//
// 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/BusinessIntro.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/Td.h"
namespace td {
BusinessIntro::BusinessIntro(Td *td, telegram_api::object_ptr<telegram_api::businessIntro> intro) {
if (intro == nullptr) {
return;
}
title_ = std::move(intro->title_);
description_ = std::move(intro->description_);
sticker_file_id_ =
td->stickers_manager_->on_get_sticker_document(std::move(intro->sticker_), StickerFormat::Unknown).second;
}
BusinessIntro::BusinessIntro(Td *td, td_api::object_ptr<td_api::inputBusinessIntro> intro) {
if (intro == nullptr) {
return;
}
title_ = std::move(intro->title_);
description_ = std::move(intro->description_);
auto r_file_id = td->file_manager_->get_input_file_id(FileType::Sticker, intro->sticker_, DialogId(), true, false);
auto file_id = r_file_id.is_ok() ? r_file_id.move_as_ok() : FileId();
if (file_id.is_valid()) {
auto file_view = td->file_manager_->get_file_view(file_id);
if (!file_view.has_remote_location() || !file_view.main_remote_location().is_document() ||
file_view.main_remote_location().is_web() ||
td->stickers_manager_->get_sticker_type(file_id) == StickerType::CustomEmoji) {
file_id = FileId();
}
}
sticker_file_id_ = file_id;
}
td_api::object_ptr<td_api::businessIntro> BusinessIntro::get_business_intro_object(Td *td) const {
if (is_empty()) {
return nullptr;
}
return td_api::make_object<td_api::businessIntro>(title_, description_,
td->stickers_manager_->get_sticker_object(sticker_file_id_));
}
telegram_api::object_ptr<telegram_api::inputBusinessIntro> BusinessIntro::get_input_business_intro(Td *td) const {
int32 flags = 0;
telegram_api::object_ptr<telegram_api::InputDocument> input_document;
if (sticker_file_id_.is_valid()) {
auto file_view = td->file_manager_->get_file_view(sticker_file_id_);
input_document = file_view.main_remote_location().as_input_document();
flags |= telegram_api::inputBusinessIntro::STICKER_MASK;
}
return telegram_api::make_object<telegram_api::inputBusinessIntro>(flags, title_, description_,
std::move(input_document));
}
bool operator==(const BusinessIntro &lhs, const BusinessIntro &rhs) {
return lhs.title_ == rhs.title_ && lhs.description_ == rhs.description_ &&
lhs.sticker_file_id_ == rhs.sticker_file_id_;
}
StringBuilder &operator<<(StringBuilder &string_builder, const BusinessIntro &intro) {
return string_builder << "business intro " << intro.title_ << '|' << intro.description_ << '|'
<< intro.sticker_file_id_;
}
} // namespace td

View File

@ -0,0 +1,60 @@
//
// 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/files/FileId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
namespace td {
class Td;
class BusinessIntro {
public:
BusinessIntro() = default;
explicit BusinessIntro(Td *td, telegram_api::object_ptr<telegram_api::businessIntro> intro);
explicit BusinessIntro(Td *td, td_api::object_ptr<td_api::inputBusinessIntro> intro);
td_api::object_ptr<td_api::businessIntro> get_business_intro_object(Td *td) const;
telegram_api::object_ptr<telegram_api::inputBusinessIntro> get_input_business_intro(Td *td) const;
bool is_empty() const {
return title_.empty() && description_.empty() && !sticker_file_id_.is_valid();
}
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
private:
string title_;
string description_;
FileId sticker_file_id_;
friend bool operator==(const BusinessIntro &lhs, const BusinessIntro &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const BusinessIntro &intro);
};
bool operator==(const BusinessIntro &lhs, const BusinessIntro &rhs);
inline bool operator!=(const BusinessIntro &lhs, const BusinessIntro &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const BusinessIntro &intro);
} // namespace td

View File

@ -0,0 +1,63 @@
//
// 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/BusinessIntro.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/StickersManager.hpp"
#include "td/telegram/Td.h"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void BusinessIntro::store(StorerT &storer) const {
bool has_title = !title_.empty();
bool has_description = !description_.empty();
bool has_sticker_file_id = sticker_file_id_.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_title);
STORE_FLAG(has_description);
STORE_FLAG(has_sticker_file_id);
END_STORE_FLAGS();
if (has_title) {
td::store(title_, storer);
}
if (has_description) {
td::store(description_, storer);
}
if (has_sticker_file_id) {
StickersManager *stickers_manager = storer.context()->td().get_actor_unsafe()->stickers_manager_.get();
stickers_manager->store_sticker(sticker_file_id_, false, storer, "BusinessIntro");
}
}
template <class ParserT>
void BusinessIntro::parse(ParserT &parser) {
bool has_title;
bool has_description;
bool has_sticker_file_id;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_title);
PARSE_FLAG(has_description);
PARSE_FLAG(has_sticker_file_id);
END_PARSE_FLAGS();
if (has_title) {
td::parse(title_, parser);
}
if (has_description) {
td::parse(description_, parser);
}
if (has_sticker_file_id) {
StickersManager *stickers_manager = parser.context()->td().get_actor_unsafe()->stickers_manager_.get();
sticker_file_id_ = stickers_manager->parse_sticker(false, parser);
}
}
} // namespace td