Support background type for links to backgrounds with files.

This commit is contained in:
levlam 2024-08-09 16:49:31 +03:00
parent 31249fa0c2
commit 6b16461547
5 changed files with 21 additions and 4 deletions

View File

@ -729,6 +729,12 @@ void DocumentsManager::delete_document_thumbnail(FileId file_id) {
document->thumbnail = PhotoSize();
}
Slice DocumentsManager::get_document_mime_type(FileId file_id) const {
auto document = get_document(file_id);
CHECK(document != nullptr);
return document->mime_type;
}
FileId DocumentsManager::dup_document(FileId new_id, FileId old_id) {
const GeneralDocument *old_document = get_document(old_id);
CHECK(old_document != nullptr);

View File

@ -19,6 +19,7 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Slice.h"
#include "td/utils/WaitFreeHashMap.h"
#include <utility>
@ -106,6 +107,8 @@ class DocumentsManager {
void delete_document_thumbnail(FileId file_id);
Slice get_document_mime_type(FileId file_id) const;
FileId dup_document(FileId new_id, FileId old_id);
void merge_documents(FileId new_id, FileId old_id);

View File

@ -2684,7 +2684,8 @@ Result<string> LinkManager::get_background_url(const string &name,
return url;
}
td_api::object_ptr<td_api::BackgroundType> LinkManager::get_background_type_object(const string &link) {
td_api::object_ptr<td_api::BackgroundType> LinkManager::get_background_type_object(const string &link,
bool is_pattern) {
auto parsed_link = parse_internal_link(link);
if (parsed_link == nullptr) {
return nullptr;
@ -2696,7 +2697,9 @@ td_api::object_ptr<td_api::BackgroundType> LinkManager::get_background_type_obje
auto background_name =
std::move(static_cast<td_api::internalLinkTypeBackground *>(parsed_object.get())->background_name_);
if (!BackgroundType::is_background_name_local(background_name)) {
return nullptr;
BackgroundType type(false, is_pattern, nullptr);
type.apply_parameters_from_link(background_name);
return type.get_background_type_object();
}
auto r_background_type = BackgroundType::get_local_background_type(background_name);
if (r_background_type.is_error()) {

View File

@ -84,7 +84,7 @@ class LinkManager final : public Actor {
static Result<string> get_background_url(const string &name,
td_api::object_ptr<td_api::BackgroundType> background_type);
static td_api::object_ptr<td_api::BackgroundType> get_background_type_object(const string &link);
static td_api::object_ptr<td_api::BackgroundType> get_background_type_object(const string &link, bool is_pattern);
static string get_dialog_filter_invite_link_slug(Slice invite_link);

View File

@ -1455,11 +1455,16 @@ td_api::object_ptr<td_api::LinkPreviewType> WebPagesManager::get_link_preview_ty
LOG_IF(ERROR,
web_page->document_.type != Document::Type::Unknown && web_page->document_.type != Document::Type::General)
<< "Receive wrong document for " << web_page->url_;
bool is_pattern = false;
if (web_page->document_.type == Document::Type::General) {
auto mime_type = td_->documents_manager_->get_document_mime_type(web_page->document_.file_id);
is_pattern = mime_type == "image/png" || mime_type == "application/x-tgwallpattern";
}
return td_api::make_object<td_api::linkPreviewTypeBackground>(
web_page->document_.type == Document::Type::General
? td_->documents_manager_->get_document_object(web_page->document_.file_id, PhotoFormat::Png)
: nullptr,
LinkManager::get_background_type_object(web_page->url_));
LinkManager::get_background_type_object(web_page->url_, is_pattern));
}
if (type == "bot") {
LOG_IF(ERROR, web_page->document_.type != Document::Type::Unknown)