Keep photo size type.

GitOrigin-RevId: b07bd8da83b8461d8f0a4314276cc74850c62989
This commit is contained in:
levlam 2019-09-02 03:51:41 +03:00
parent 5bd752da0d
commit 926dd7f8f4
4 changed files with 38 additions and 3 deletions

View File

@ -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<InputMessageContent> 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<int32>(file_view.size());
s.file_id = file_id;
@ -4002,13 +4013,13 @@ unique_ptr<MessageContent> 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') {

View File

@ -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

View File

@ -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

View File

@ -135,4 +135,5 @@ class PrivacyManager : public NetQueryCallback {
void hangup() override;
};
} // namespace td