@@ -72,31 +72,21 @@ EditCaptionBox::EditCaptionBox(
72
72
_isAllowedEditMedia = item->media ()->allowsEditMedia ();
73
73
_isAlbum = !item->groupId ().empty ();
74
74
75
- QSize dimensions;
76
- auto image = (Image*)nullptr ;
77
-
75
+ auto dimensions = QSize ();
78
76
const auto media = item->media ();
79
77
if (const auto photo = media->photo ()) {
80
78
_photoMedia = photo->createMediaView ();
81
79
_photoMedia->wanted (PhotoSize::Large, _msgId);
82
- image = _photoMedia->image (PhotoSize::Large);
83
- if (!image) {
84
- image = _photoMedia->image (PhotoSize::Thumbnail);
85
- if (!image) {
86
- image = _photoMedia->image (PhotoSize::Small);
87
- if (!image) {
88
- image = _photoMedia->thumbnailInline ();
89
- }
90
- }
91
- }
92
80
dimensions = _photoMedia->size (PhotoSize::Large);
81
+ if (dimensions.isEmpty ()) {
82
+ dimensions = QSize (1 , 1 );
83
+ }
93
84
_photo = true ;
94
85
} else if (const auto document = media->document ()) {
95
86
_documentMedia = document->createMediaView ();
96
87
_documentMedia->thumbnailWanted (_msgId);
97
- image = _documentMedia->thumbnail ();
98
- dimensions = image
99
- ? image->size ()
88
+ dimensions = _documentMedia->thumbnail ()
89
+ ? _documentMedia->thumbnail ()->size ()
100
90
: document->dimensions ;
101
91
if (document->isAnimation ()) {
102
92
_gifw = style::ConvertScale (document->dimensions .width ());
@@ -107,24 +97,42 @@ EditCaptionBox::EditCaptionBox(
107
97
} else {
108
98
_doc = true ;
109
99
}
100
+ } else {
101
+ Unexpected (" Photo or document should be set." );
110
102
}
111
103
const auto editData = PrepareEditText (item);
112
104
113
- if (!_animated
114
- && (dimensions.isEmpty ()
115
- || _documentMedia
116
- || (!_photoMedia && !image))) {
117
- if (!image) {
105
+ const auto computeImage = [=] {
106
+ if (_documentMedia) {
107
+ return _documentMedia->thumbnail ();
108
+ } else if (const auto large = _photoMedia->image (PhotoSize::Large)) {
109
+ return large;
110
+ } else if (const auto thumbnail = _photoMedia->image (
111
+ PhotoSize::Thumbnail)) {
112
+ return thumbnail;
113
+ } else if (const auto small = _photoMedia->image (PhotoSize::Small)) {
114
+ return small;
115
+ } else {
116
+ return _photoMedia->thumbnailInline ();
117
+ }
118
+ };
119
+
120
+ if (!_animated && _documentMedia) {
121
+ if (dimensions.isEmpty ()) {
118
122
_thumbw = 0 ;
123
+ _thumbnailImageLoaded = true ;
119
124
} else {
120
- const auto tw = image-> width (), th = image-> height ();
125
+ const auto tw = dimensions. width (), th = dimensions. height ();
121
126
if (tw > th) {
122
127
_thumbw = (tw * st::msgFileThumbSize) / th;
123
128
} else {
124
129
_thumbw = st::msgFileThumbSize;
125
130
}
126
- _thumbnailImage = image;
127
131
_refreshThumbnail = [=] {
132
+ const auto image = computeImage ();
133
+ if (!image) {
134
+ return ;
135
+ }
128
136
const auto options = Images::Option::Smooth
129
137
| Images::Option::RoundedSmall
130
138
| Images::Option::RoundedTopLeft
@@ -138,7 +146,9 @@ EditCaptionBox::EditCaptionBox(
138
146
options,
139
147
st::msgFileThumbSize,
140
148
st::msgFileThumbSize));
149
+ _thumbnailImageLoaded = true ;
141
150
};
151
+ _refreshThumbnail ();
142
152
}
143
153
144
154
if (_documentMedia) {
@@ -151,13 +161,7 @@ EditCaptionBox::EditCaptionBox(
151
161
_isAudio = document->isVoiceMessage ()
152
162
|| document->isAudioFile ();
153
163
}
154
- if (_refreshThumbnail) {
155
- _refreshThumbnail ();
156
- }
157
164
} else {
158
- if (!image && !_photoMedia) {
159
- image = Image::BlankMedia ();
160
- }
161
165
auto maxW = 0 , maxH = 0 ;
162
166
const auto limitW = st::sendMediaPreviewSize;
163
167
auto limitH = std::min (st::confirmMaxHeight, _gifh ? _gifh : INT_MAX);
@@ -175,35 +179,38 @@ EditCaptionBox::EditCaptionBox(
175
179
maxH = limitH;
176
180
}
177
181
}
178
- _thumbnailImage = image;
179
182
_refreshThumbnail = [=] {
183
+ const auto image = computeImage ();
184
+ const auto use = image ? image : Image::BlankMedia ().get ();
180
185
const auto options = Images::Option::Smooth
181
186
| Images::Option::Blurred;
182
- _thumb = image ->pixNoCache (
187
+ _thumb = use ->pixNoCache (
183
188
maxW * cIntRetinaFactor (),
184
189
maxH * cIntRetinaFactor (),
185
190
options,
186
191
maxW,
187
192
maxH);
193
+ _thumbnailImageLoaded = true ;
188
194
};
189
195
prepareStreamedPreview ();
190
196
} else {
197
+ Assert (_photoMedia != nullptr );
198
+
191
199
maxW = dimensions.width ();
192
200
maxH = dimensions.height ();
193
- _thumbnailImage = image;
194
201
_refreshThumbnail = [=] {
195
- const auto photo = _photoMedia
196
- ? _photoMedia->image (Data::PhotoSize::Large)
197
- : nullptr ;
202
+ const auto image = computeImage ();
203
+ const auto photo = _photoMedia->image (Data::PhotoSize::Large);
198
204
const auto use = photo
199
205
? photo
200
- : _thumbnailImage
201
- ? _thumbnailImage
206
+ : image
207
+ ? image
202
208
: Image::BlankMedia ().get ();
203
209
const auto options = Images::Option::Smooth
204
- | ((_photoMedia && !photo)
205
- ? Images::Option::Blurred
206
- : Images::Option (0 ));
210
+ | (photo
211
+ ? Images::Option (0 )
212
+ : Images::Option::Blurred);
213
+ _thumbnailImageLoaded = (photo != nullptr );
207
214
_thumb = use->pixNoCache (
208
215
maxW * cIntRetinaFactor (),
209
216
maxH * cIntRetinaFactor (),
@@ -276,35 +283,17 @@ EditCaptionBox::EditCaptionBox(
276
283
scaleThumbDown ();
277
284
}
278
285
Assert (_animated || _photo || _doc);
286
+ Assert (_thumbnailImageLoaded || _refreshThumbnail);
279
287
280
- _thumbnailImageLoaded = _photoMedia
281
- ? (_photoMedia->image (Data::PhotoSize::Large) != nullptr )
282
- : _thumbnailImage
283
- ? true
284
- : _documentMedia
285
- ? !_documentMedia->owner ()->hasThumbnail ()
286
- : true ;
287
288
if (!_thumbnailImageLoaded) {
288
289
subscribe (_controller->session ().downloaderTaskFinished (), [=] {
289
- if (_thumbnailImageLoaded) {
290
+ if (_thumbnailImageLoaded
291
+ || (_photoMedia && !_photoMedia->image (PhotoSize::Large))
292
+ || (_documentMedia && !_documentMedia->thumbnail ())) {
290
293
return ;
291
- } else if (!_thumbnailImage
292
- && _photoMedia
293
- && _photoMedia->image (PhotoSize::Large)) {
294
- _thumbnailImage = _photoMedia->image (PhotoSize::Large);
295
- } else if (!_thumbnailImage
296
- && _documentMedia
297
- && _documentMedia->owner ()->hasThumbnail ()) {
298
- _thumbnailImage = _documentMedia->thumbnail ();
299
- }
300
- if (_thumbnailImage) {
301
- _thumbnailImageLoaded = !_photoMedia
302
- || _photoMedia->image (PhotoSize::Large);
303
- if (_thumbnailImageLoaded) {
304
- _refreshThumbnail ();
305
- update ();
306
- }
307
294
}
295
+ _refreshThumbnail ();
296
+ update ();
308
297
});
309
298
}
310
299
_field.create (
0 commit comments