Skip to content

Commit

Permalink
Pass UserManager to get_text_entity_object.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Jul 21, 2024
1 parent 8330062 commit c9a92f6
Show file tree
Hide file tree
Showing 28 changed files with 123 additions and 94 deletions.
13 changes: 8 additions & 5 deletions td/telegram/BusinessChatLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ BusinessChatLink::BusinessChatLink(const UserManager *user_manager,
, view_count_(link->views_) {
}

td_api::object_ptr<td_api::businessChatLink> BusinessChatLink::get_business_chat_link_object() const {
return td_api::make_object<td_api::businessChatLink>(link_, get_formatted_text_object(text_, true, -1), title_,
view_count_);
td_api::object_ptr<td_api::businessChatLink> BusinessChatLink::get_business_chat_link_object(
const UserManager *user_manager) const {
return td_api::make_object<td_api::businessChatLink>(link_, get_formatted_text_object(user_manager, text_, true, -1),
title_, view_count_);
}

StringBuilder &operator<<(StringBuilder &string_builder, const BusinessChatLink &link) {
Expand All @@ -41,9 +42,11 @@ BusinessChatLinks::BusinessChatLinks(const UserManager *user_manager,
}
}

td_api::object_ptr<td_api::businessChatLinks> BusinessChatLinks::get_business_chat_links_object() const {
td_api::object_ptr<td_api::businessChatLinks> BusinessChatLinks::get_business_chat_links_object(
const UserManager *user_manager) const {
return td_api::make_object<td_api::businessChatLinks>(transform(
business_chat_links_, [](const BusinessChatLink &link) { return link.get_business_chat_link_object(); }));
business_chat_links_,
[user_manager](const BusinessChatLink &link) { return link.get_business_chat_link_object(user_manager); }));
}

StringBuilder &operator<<(StringBuilder &string_builder, const BusinessChatLinks &links) {
Expand Down
4 changes: 2 additions & 2 deletions td/telegram/BusinessChatLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BusinessChatLink {
return !link_.empty();
}

td_api::object_ptr<td_api::businessChatLink> get_business_chat_link_object() const;
td_api::object_ptr<td_api::businessChatLink> get_business_chat_link_object(const UserManager *user_manager) const;
};

StringBuilder &operator<<(StringBuilder &string_builder, const BusinessChatLink &link);
Expand All @@ -46,7 +46,7 @@ class BusinessChatLinks {
explicit BusinessChatLinks(const UserManager *user_manager,
vector<telegram_api::object_ptr<telegram_api::businessChatLink>> &&links);

td_api::object_ptr<td_api::businessChatLinks> get_business_chat_links_object() const;
td_api::object_ptr<td_api::businessChatLinks> get_business_chat_links_object(const UserManager *user_manager) const;
};

StringBuilder &operator<<(StringBuilder &string_builder, const BusinessChatLinks &links);
Expand Down
12 changes: 7 additions & 5 deletions td/telegram/BusinessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ class GetBusinessChatLinksQuery final : public Td::ResultHandler {
LOG(INFO) << "Receive result for GetBusinessChatLinksQuery: " << to_string(ptr);
td_->user_manager_->on_get_users(std::move(ptr->users_), "GetBusinessChatLinksQuery");
td_->chat_manager_->on_get_chats(std::move(ptr->chats_), "GetBusinessChatLinksQuery");
promise_.set_value(
BusinessChatLinks(td_->user_manager_.get(), std::move(ptr->links_)).get_business_chat_links_object());
promise_.set_value(BusinessChatLinks(td_->user_manager_.get(), std::move(ptr->links_))
.get_business_chat_links_object(td_->user_manager_.get()));
}

void on_error(Status status) final {
Expand Down Expand Up @@ -238,7 +238,8 @@ class CreateBusinessChatLinkQuery final : public Td::ResultHandler {

auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for CreateBusinessChatLinkQuery: " << to_string(ptr);
promise_.set_value(BusinessChatLink(td_->user_manager_.get(), std::move(ptr)).get_business_chat_link_object());
promise_.set_value(BusinessChatLink(td_->user_manager_.get(), std::move(ptr))
.get_business_chat_link_object(td_->user_manager_.get()));
}

void on_error(Status status) final {
Expand Down Expand Up @@ -269,7 +270,8 @@ class EditBusinessChatLinkQuery final : public Td::ResultHandler {

auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for EditBusinessChatLinkQuery: " << to_string(ptr);
promise_.set_value(BusinessChatLink(td_->user_manager_.get(), std::move(ptr)).get_business_chat_link_object());
promise_.set_value(BusinessChatLink(td_->user_manager_.get(), std::move(ptr))
.get_business_chat_link_object(td_->user_manager_.get()));
}

void on_error(Status status) final {
Expand Down Expand Up @@ -343,7 +345,7 @@ class ResolveBusinessChatLinkQuery final : public Td::ResultHandler {

promise_.set_value(td_api::make_object<td_api::businessChatLinkInfo>(
td_->dialog_manager_->get_chat_id_object(dialog_id, "businessChatLinkInfo"),
get_formatted_text_object(text, true, -1)));
get_formatted_text_object(td_->user_manager_.get(), text, true, -1)));
}

void on_error(Status status) final {
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/DraftMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ td_api::object_ptr<td_api::draftMessage> DraftMessage::get_draft_message_object(
if (local_content_ != nullptr) {
input_message_content = local_content_->get_draft_input_message_content_object();
} else {
input_message_content = input_message_text_.get_input_message_text_object();
input_message_content = input_message_text_.get_input_message_text_object(td->user_manager_.get());
}
return td_api::make_object<td_api::draftMessage>(message_input_reply_to_.get_input_message_reply_to_object(td), date_,
std::move(input_message_content), message_effect_id_.get());
Expand Down
11 changes: 6 additions & 5 deletions td/telegram/FactCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
#include "td/telegram/FactCheck.h"

#include "td/telegram/Dependencies.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"

namespace td {

FactCheck::~FactCheck() = default;

unique_ptr<FactCheck> FactCheck::get_fact_check(Td *td, telegram_api::object_ptr<telegram_api::factCheck> &&fact_check,
unique_ptr<FactCheck> FactCheck::get_fact_check(const UserManager *user_manager,
telegram_api::object_ptr<telegram_api::factCheck> &&fact_check,
bool is_bot) {
if (is_bot || fact_check == nullptr || fact_check->hash_ == 0) {
return nullptr;
}
auto result = make_unique<FactCheck>();
result->country_code_ = std::move(fact_check->country_);
if (fact_check->text_ != nullptr) {
result->text_ = get_formatted_text(td->user_manager_.get(), std::move(fact_check->text_), true, false, "factCheck");
result->text_ = get_formatted_text(user_manager, std::move(fact_check->text_), true, false, "factCheck");
}
result->hash_ = fact_check->hash_;
result->need_check_ = fact_check->need_check_;
Expand All @@ -42,11 +42,12 @@ void FactCheck::add_dependencies(Dependencies &dependencies) const {
add_formatted_text_dependencies(dependencies, &text_);
}

td_api::object_ptr<td_api::factCheck> FactCheck::get_fact_check_object() const {
td_api::object_ptr<td_api::factCheck> FactCheck::get_fact_check_object(const UserManager *user_manager) const {
if (is_empty() || need_check_) {
return nullptr;
}
return td_api::make_object<td_api::factCheck>(get_formatted_text_object(text_, true, -1), country_code_);
return td_api::make_object<td_api::factCheck>(get_formatted_text_object(user_manager, text_, true, -1),
country_code_);
}

bool operator==(const unique_ptr<FactCheck> &lhs, const unique_ptr<FactCheck> &rhs) {
Expand Down
7 changes: 4 additions & 3 deletions td/telegram/FactCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace td {

class Dependencies;

class Td;
class UserManager;

class FactCheck {
string country_code_;
Expand All @@ -34,7 +34,8 @@ class FactCheck {
FactCheck &operator=(FactCheck &&) = default;
~FactCheck();

static unique_ptr<FactCheck> get_fact_check(Td *td, telegram_api::object_ptr<telegram_api::factCheck> &&fact_check,
static unique_ptr<FactCheck> get_fact_check(const UserManager *user_manager,
telegram_api::object_ptr<telegram_api::factCheck> &&fact_check,
bool is_bot);

bool is_empty() const {
Expand All @@ -49,7 +50,7 @@ class FactCheck {

void add_dependencies(Dependencies &dependencies) const;

td_api::object_ptr<td_api::factCheck> get_fact_check_object() const;
td_api::object_ptr<td_api::factCheck> get_fact_check_object(const UserManager *user_manager) const;

template <class StorerT>
void store(StorerT &storer) const;
Expand Down
3 changes: 2 additions & 1 deletion td/telegram/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ const FormattedText &Game::get_text() const {
}

tl_object_ptr<td_api::game> Game::get_game_object(Td *td, bool skip_bot_commands) const {
return make_tl_object<td_api::game>(id_, short_name_, title_, get_formatted_text_object(text_, skip_bot_commands, -1),
return make_tl_object<td_api::game>(id_, short_name_, title_,
get_formatted_text_object(td->user_manager_.get(), text_, skip_bot_commands, -1),
description_, get_photo_object(td->file_manager_.get(), photo_),
td->animations_manager_->get_animation_object(animation_file_id_));
}
Expand Down
13 changes: 7 additions & 6 deletions td/telegram/InputInvoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ Result<InputInvoice> InputInvoice::process_input_message_invoice(
td_api::object_ptr<td_api::messageInvoice> InputInvoice::get_message_invoice_object(Td *td, bool skip_bot_commands,
int32 max_media_timestamp) const {
auto extended_media_object = extended_media_.get_message_extended_media_object(td);
auto extended_media_caption_object =
extended_media_object == nullptr
? nullptr
: get_formatted_text_object(extended_media_caption_, skip_bot_commands, max_media_timestamp);
auto extended_media_caption_object = extended_media_object == nullptr
? nullptr
: get_formatted_text_object(td->user_manager_.get(), extended_media_caption_,
skip_bot_commands, max_media_timestamp);
return td_api::make_object<td_api::messageInvoice>(
get_product_info_object(td, title_, description_, photo_), invoice_.currency_, total_amount_, start_parameter_,
invoice_.is_test_, invoice_.need_shipping_address_, receipt_message_id_.get(), std::move(extended_media_object),
Expand Down Expand Up @@ -441,8 +441,9 @@ td_api::object_ptr<td_api::productInfo> get_product_info_object(Td *td, const st
FormattedText formatted_description;
formatted_description.text = description;
formatted_description.entities = find_entities(formatted_description.text, true, true);
return td_api::make_object<td_api::productInfo>(title, get_formatted_text_object(formatted_description, true, 0),
get_photo_object(td->file_manager_.get(), photo));
return td_api::make_object<td_api::productInfo>(
title, get_formatted_text_object(td->user_manager_.get(), formatted_description, true, 0),
get_photo_object(td->file_manager_.get(), photo));
}

} // namespace td
7 changes: 4 additions & 3 deletions td/telegram/InputMessageText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ telegram_api::object_ptr<telegram_api::InputMedia> InputMessageText::get_input_m
}

// used only for draft
td_api::object_ptr<td_api::inputMessageText> InputMessageText::get_input_message_text_object() const {
td_api::object_ptr<td_api::inputMessageText> InputMessageText::get_input_message_text_object(
const UserManager *user_manager) const {
td_api::object_ptr<td_api::linkPreviewOptions> options;
if (!web_page_url.empty() || disable_web_page_preview || force_small_media || force_large_media || show_above_text) {
options = td_api::make_object<td_api::linkPreviewOptions>(disable_web_page_preview, web_page_url, force_small_media,
force_large_media, show_above_text);
}
return td_api::make_object<td_api::inputMessageText>(get_formatted_text_object(text, false, -1), std::move(options),
clear_draft);
return td_api::make_object<td_api::inputMessageText>(get_formatted_text_object(user_manager, text, false, -1),
std::move(options), clear_draft);
}

} // namespace td
4 changes: 3 additions & 1 deletion td/telegram/InputMessageText.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Dependencies;

class Td;

class UserManager;

class InputMessageText {
public:
FormattedText text;
Expand Down Expand Up @@ -50,7 +52,7 @@ class InputMessageText {

telegram_api::object_ptr<telegram_api::InputMedia> get_input_media_web_page() const;

td_api::object_ptr<td_api::inputMessageText> get_input_message_text_object() const;
td_api::object_ptr<td_api::inputMessageText> get_input_message_text_object(const UserManager *user_manager) const;
};

bool operator==(const InputMessageText &lhs, const InputMessageText &rhs);
Expand Down
8 changes: 4 additions & 4 deletions td/telegram/LinkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ class LinkManager::InternalLinkMessageDraft final : public InternalLink {
bool contains_link_ = false;

td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeMessageDraft>(get_formatted_text_object(text_, true, -1),
contains_link_);
return td_api::make_object<td_api::internalLinkTypeMessageDraft>(
get_formatted_text_object(nullptr, text_, true, -1), contains_link_);
}

public:
Expand Down Expand Up @@ -855,8 +855,8 @@ class GetDeepLinkInfoQuery final : public Td::ResultHandler {
auto info = telegram_api::move_object_as<telegram_api::help_deepLinkInfo>(result);
auto text = get_formatted_text(nullptr, std::move(info->message_), std::move(info->entities_), true, true,
"GetDeepLinkInfoQuery");
return promise_.set_value(
td_api::make_object<td_api::deepLinkInfo>(get_formatted_text_object(text, true, -1), info->update_app_));
return promise_.set_value(td_api::make_object<td_api::deepLinkInfo>(
get_formatted_text_object(td_->user_manager_.get(), text, true, -1), info->update_app_));
}
default:
UNREACHABLE();
Expand Down
25 changes: 14 additions & 11 deletions td/telegram/MessageContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7392,14 +7392,14 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
const auto *m = static_cast<const MessageAnimation *>(content);
return make_tl_object<td_api::messageAnimation>(
td->animations_manager_->get_animation_object(m->file_id),
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), invert_media, m->has_spoiler,
is_content_secret);
get_formatted_text_object(td->user_manager_.get(), m->caption, skip_bot_commands, max_media_timestamp),
invert_media, m->has_spoiler, is_content_secret);
}
case MessageContentType::Audio: {
const auto *m = static_cast<const MessageAudio *>(content);
return make_tl_object<td_api::messageAudio>(
td->audios_manager_->get_audio_object(m->file_id),
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp));
get_formatted_text_object(td->user_manager_.get(), m->caption, skip_bot_commands, max_media_timestamp));
}
case MessageContentType::Contact: {
const auto *m = static_cast<const MessageContact *>(content);
Expand All @@ -7409,7 +7409,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
const auto *m = static_cast<const MessageDocument *>(content);
return make_tl_object<td_api::messageDocument>(
td->documents_manager_->get_document_object(m->file_id, PhotoFormat::Jpeg),
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp));
get_formatted_text_object(td->user_manager_.get(), m->caption, skip_bot_commands, max_media_timestamp));
}
case MessageContentType::Game: {
const auto *m = static_cast<const MessageGame *>(content);
Expand Down Expand Up @@ -7439,7 +7439,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
LOG(ERROR) << "Have empty " << m->photo;
return make_tl_object<td_api::messageExpiredPhoto>();
}
auto caption = get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp);
auto caption =
get_formatted_text_object(td->user_manager_.get(), m->caption, skip_bot_commands, max_media_timestamp);
return make_tl_object<td_api::messagePhoto>(std::move(photo), std::move(caption), invert_media, m->has_spoiler,
is_content_secret);
}
Expand Down Expand Up @@ -7479,8 +7480,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
disable_web_page_preview, m->web_page_url, m->force_small_media, m->force_large_media, invert_media);
}
return make_tl_object<td_api::messageText>(
get_formatted_text_object(m->text, skip_bot_commands, max_media_timestamp), std::move(web_page),
std::move(link_preview_options));
get_formatted_text_object(td->user_manager_.get(), m->text, skip_bot_commands, max_media_timestamp),
std::move(web_page), std::move(link_preview_options));
}
case MessageContentType::Unsupported:
return make_tl_object<td_api::messageUnsupported>();
Expand All @@ -7492,8 +7493,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
const auto *m = static_cast<const MessageVideo *>(content);
return make_tl_object<td_api::messageVideo>(
td->videos_manager_->get_video_object(m->file_id),
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), invert_media, m->has_spoiler,
is_content_secret);
get_formatted_text_object(td->user_manager_.get(), m->caption, skip_bot_commands, max_media_timestamp),
invert_media, m->has_spoiler, is_content_secret);
}
case MessageContentType::VideoNote: {
const auto *m = static_cast<const MessageVideoNote *>(content);
Expand All @@ -7504,7 +7505,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
const auto *m = static_cast<const MessageVoiceNote *>(content);
return make_tl_object<td_api::messageVoiceNote>(
td->voice_notes_manager_->get_voice_note_object(m->file_id),
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), m->is_listened);
get_formatted_text_object(td->user_manager_.get(), m->caption, skip_bot_commands, max_media_timestamp),
m->is_listened);
}
case MessageContentType::ChatCreate: {
const auto *m = static_cast<const MessageChatCreate *>(content);
Expand Down Expand Up @@ -7795,7 +7797,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
return td_api::make_object<td_api::messagePaidMedia>(
m->star_count,
transform(m->media, [&](const auto &media) { return media.get_message_extended_media_object(td); }),
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), invert_media);
get_formatted_text_object(td->user_manager_.get(), m->caption, skip_bot_commands, max_media_timestamp),
invert_media);
}
case MessageContentType::PaymentRefunded: {
const auto *m = static_cast<const MessagePaymentRefunded *>(content);
Expand Down
Loading

0 comments on commit c9a92f6

Please sign in to comment.