diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 420fbbb5..c307bcae 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -39,6 +39,7 @@ #include "td/telegram/Payments.hpp" #include "td/telegram/Photo.h" #include "td/telegram/Photo.hpp" +#include "td/telegram/PhotoSizeSource.h" #include "td/telegram/PollId.h" #include "td/telegram/PollId.hpp" #include "td/telegram/PollManager.h" @@ -1560,9 +1561,19 @@ static Result create_input_message_content( message_photo->photo.id = file_view.remote_location().get_id(); } message_photo->photo.date = G()->unix_time(); + int32 type = 'i'; + if (file_view.has_remote_location() && !file_view.remote_location().is_web()) { + auto photo_size_source = file_view.remote_location().get_source(); + if (photo_size_source.get_type() == PhotoSizeSource::Type::Thumbnail) { + auto old_type = photo_size_source.thumbnail().thumbnail_type; + if (old_type != 't') { + type = old_type; + } + } + } PhotoSize s; - s.type = 'i'; + s.type = type; s.dimensions = get_dimensions(input_photo->width_, input_photo->height_); s.size = static_cast(file_view.size()); s.file_id = file_id; @@ -4002,13 +4013,13 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const result->caption = FormattedText(); } - if (result->photo.photos.size() > 2 && !to_secret) { + CHECK(!result->photo.photos.empty()); + if ((result->photo.photos.size() > 2 || result->photo.photos.back().type != 'i') && !to_secret) { // already sent photo return std::move(result); } // Find 'i' or largest - CHECK(!result->photo.photos.empty()); PhotoSize photo; for (const auto &size : result->photo.photos) { if (size.type == 'i') { diff --git a/td/telegram/PhotoSizeSource.cpp b/td/telegram/PhotoSizeSource.cpp index 09fca6d0..ce584ff8 100644 --- a/td/telegram/PhotoSizeSource.cpp +++ b/td/telegram/PhotoSizeSource.cpp @@ -80,4 +80,24 @@ bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) { return !(lhs == rhs); } +StringBuilder &operator<<(StringBuilder &string_builder, const PhotoSizeSource &source) { + switch (source.get_type()) { + case PhotoSizeSource::Type::Thumbnail: + return string_builder << "PhotoSizeSourceThumbnail[" << source.thumbnail().file_type + << ", type = " << source.thumbnail().thumbnail_type << ']'; + case PhotoSizeSource::Type::DialogPhotoSmall: + return string_builder << "PhotoSizeSourceChatPhotoSmall[" << source.dialog_photo().dialog_id << ']'; + case PhotoSizeSource::Type::DialogPhotoBig: + return string_builder << "PhotoSizeSourceChatPhotoBig[" << source.dialog_photo().dialog_id << ']'; + case PhotoSizeSource::Type::StickerSetThumbnail: + return string_builder << "PhotoSizeSourceStickerSetThumbnail[" << source.sticker_set_thumbnail().sticker_set_id + << ']'; + case PhotoSizeSource::Type::Legacy: + return string_builder << "PhotoSizeSourceLegacy[]"; + default: + UNREACHABLE(); + return string_builder; + } +} + } // namespace td diff --git a/td/telegram/PhotoSizeSource.h b/td/telegram/PhotoSizeSource.h index 18017bdd..f6dacfb1 100644 --- a/td/telegram/PhotoSizeSource.h +++ b/td/telegram/PhotoSizeSource.h @@ -12,6 +12,7 @@ #include "td/telegram/telegram_api.h" #include "td/utils/common.h" +#include "td/utils/StringBuilder.h" #include "td/utils/Variant.h" namespace td { @@ -131,4 +132,6 @@ struct PhotoSizeSource { bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs); bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs); +StringBuilder &operator<<(StringBuilder &string_builder, const PhotoSizeSource &source); + } // namespace td diff --git a/td/telegram/PrivacyManager.h b/td/telegram/PrivacyManager.h index a5f9c13b..0aedf70a 100644 --- a/td/telegram/PrivacyManager.h +++ b/td/telegram/PrivacyManager.h @@ -135,4 +135,5 @@ class PrivacyManager : public NetQueryCallback { void hangup() override; }; + } // namespace td