tdlight/td/telegram/BusinessIntro.cpp

95 lines
3.6 KiB
C++
Raw Normal View History

2024-03-18 21:46:08 +01:00
//
// 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"
2024-03-31 17:30:18 +02:00
#include "td/telegram/DialogId.h"
2024-03-20 17:40:10 +01:00
#include "td/telegram/Document.h"
2024-03-18 21:46:08 +01:00
#include "td/telegram/files/FileManager.h"
2024-03-31 17:30:18 +02:00
#include "td/telegram/files/FileType.h"
2024-03-19 12:52:52 +01:00
#include "td/telegram/misc.h"
2024-03-31 17:30:18 +02:00
#include "td/telegram/StickerFormat.h"
2024-03-18 21:46:08 +01:00
#include "td/telegram/StickersManager.h"
2024-03-31 17:30:18 +02:00
#include "td/telegram/StickerType.h"
2024-03-18 21:46:08 +01:00
#include "td/telegram/Td.h"
namespace td {
BusinessIntro::BusinessIntro(Td *td, telegram_api::object_ptr<telegram_api::businessIntro> intro) {
if (intro == nullptr) {
return;
}
2024-03-19 12:52:52 +01:00
if (!clean_input_string(intro->title_)) {
intro->title_.clear();
}
if (!clean_input_string(intro->description_)) {
intro->description_.clear();
}
2024-03-18 21:46:08 +01:00
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;
}
2024-04-08 02:29:57 +02:00
BusinessIntro::BusinessIntro(Td *td, td_api::object_ptr<td_api::inputBusinessStartPage> intro) {
2024-03-18 21:46:08 +01:00
if (intro == nullptr) {
return;
}
title_ = std::move(intro->title_);
2024-03-19 12:42:40 +01:00
description_ = std::move(intro->message_);
2024-03-18 21:46:08 +01:00
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;
}
2024-04-08 02:29:57 +02:00
td_api::object_ptr<td_api::businessStartPage> BusinessIntro::get_business_start_page_object(Td *td) const {
2024-03-18 21:46:08 +01:00
if (is_empty()) {
return nullptr;
}
2024-04-08 02:29:57 +02:00
return td_api::make_object<td_api::businessStartPage>(title_, description_,
td->stickers_manager_->get_sticker_object(sticker_file_id_));
2024-03-18 21:46:08 +01:00
}
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));
}
2024-03-20 17:40:10 +01:00
vector<FileId> BusinessIntro::get_file_ids(const Td *td) const {
if (!sticker_file_id_.is_valid()) {
return {};
}
return Document(Document::Type::Sticker, sticker_file_id_).get_file_ids(td);
}
2024-03-18 21:46:08 +01:00
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