Fix grouped media display in MediaView.

This commit is contained in:
John Preston 2017-12-15 22:05:10 +03:00
parent b6087ce7ce
commit efa72578cd
9 changed files with 42 additions and 30 deletions

View File

@ -480,7 +480,7 @@ EditCaptionBox::EditCaptionBox(QWidget*, HistoryMedia *media, FullMsgId msgId) :
case MediaTypePhoto: {
_photo = true;
auto photo = static_cast<HistoryPhoto*>(media)->photo();
auto photo = static_cast<HistoryPhoto*>(media)->getPhoto();
dimensions = QSize(photo->full->width(), photo->full->height());
image = photo->full;
} break;

View File

@ -291,7 +291,7 @@ base::optional<bool> SharedMediaWithLastSlice::IsLastIsolated(
| [](HistoryItem *item) { return item ? item->getMedia() : nullptr; }
| [](HistoryMedia *media) {
return (media && media->type() == MediaTypePhoto)
? static_cast<HistoryPhoto*>(media)->photo().get()
? static_cast<HistoryPhoto*>(media)->getPhoto()
: nullptr;
}
| [](PhotoData *photo) { return photo ? photo->id : 0; }

View File

@ -138,7 +138,10 @@ public:
not_null<HistoryItem*> newParent,
not_null<HistoryItem*> realParent) const = 0;
virtual DocumentData *getDocument() {
virtual PhotoData *getPhoto() const {
return nullptr;
}
virtual DocumentData *getDocument() const {
return nullptr;
}
virtual Media::Clip::Reader *getClipReader() {

View File

@ -65,6 +65,13 @@ public:
return !_caption.isEmpty();
}
PhotoData *getPhoto() const override {
return main()->getPhoto();
}
DocumentData *getDocument() const override {
return main()->getDocument();
}
QString notificationText() const override;
QString inDialogsText() const override;
TextWithEntities selectedText(TextSelection selection) const override;

View File

@ -123,7 +123,7 @@ QSize CountPixSizeForSize(QSize original, QSize geometry) {
auto tw = original.width();
auto th = original.height();
if (tw * height > th * width) {
if (tw * height < 2 * th * width) {
if (th > height || tw * height < 2 * th * width) {
tw = (height * tw) / th;
th = height;
} else if (tw < width) {
@ -131,7 +131,7 @@ QSize CountPixSizeForSize(QSize original, QSize geometry) {
tw = width;
}
} else {
if (th * width < 2 * tw * height) {
if (tw > width || th * width < 2 * tw * height) {
th = (width * th) / tw;
tw = width;
} else if (tw > 0 && th < height) {

View File

@ -199,7 +199,7 @@ public:
Storage::SharedMediaTypesMask sharedMediaTypes() const override;
not_null<PhotoData*> photo() const {
PhotoData *getPhoto() const override {
return _data;
}
@ -318,7 +318,7 @@ public:
Storage::SharedMediaTypesMask sharedMediaTypes() const override;
DocumentData *getDocument() override {
DocumentData *getDocument() const override {
return _data;
}
@ -517,7 +517,7 @@ public:
return _data->uploading();
}
DocumentData *getDocument() override {
DocumentData *getDocument() const override {
return _data;
}
@ -632,7 +632,7 @@ public:
return _data->uploading();
}
DocumentData *getDocument() override {
DocumentData *getDocument() const override {
return _data;
}
Media::Clip::Reader *getClipReader() override {
@ -743,7 +743,7 @@ public:
QString notificationText() const override;
TextWithEntities selectedText(TextSelection selection) const override;
DocumentData *getDocument() override {
DocumentData *getDocument() const override {
return _data;
}
@ -973,7 +973,10 @@ public:
bool isDisplayed() const override {
return !_data->pendingTill && !_parent->Has<HistoryMessageLogEntryOriginal>();
}
DocumentData *getDocument() override {
PhotoData *getPhoto() const override {
return _attach ? _attach->getPhoto() : nullptr;
}
DocumentData *getDocument() const override {
return _attach ? _attach->getDocument() : nullptr;
}
Media::Clip::Reader *getClipReader() override {
@ -1089,7 +1092,10 @@ public:
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
DocumentData *getDocument() override {
PhotoData *getPhoto() const override {
return _attach ? _attach->getPhoto() : nullptr;
}
DocumentData *getDocument() const override {
return _attach ? _attach->getDocument() : nullptr;
}
Media::Clip::Reader *getClipReader() override {

View File

@ -4508,7 +4508,7 @@ void HistoryWidget::onThumbDocumentUploaded(
void HistoryWidget::onPhotoProgress(const FullMsgId &newId) {
if (const auto item = App::histItemById(newId)) {
const auto photo = (item->getMedia() && item->getMedia()->type() == MediaTypePhoto)
? static_cast<HistoryPhoto*>(item->getMedia())->photo().get()
? static_cast<HistoryPhoto*>(item->getMedia())->getPhoto()
: nullptr;
updateSendAction(item->history(), SendAction::Type::UploadPhoto, 0);
Auth().data().requestItemRepaint(item);

View File

@ -849,7 +849,7 @@ std::unique_ptr<BaseLayout> ListWidget::createLayout(
auto getPhoto = [&]() -> PhotoData* {
if (auto media = item->getMedia()) {
if (media->type() == MediaTypePhoto) {
return static_cast<HistoryPhoto*>(media)->photo();
return static_cast<HistoryPhoto*>(media)->getPhoto();
}
}
return nullptr;

View File

@ -1266,8 +1266,9 @@ void MediaView::displayPhoto(not_null<PhotoData*> photo, HistoryItem *item) {
_zoom = 0;
_caption = Text();
if (auto itemMsg = item ? item->toHistoryMessage() : nullptr) {
if (auto photoMsg = dynamic_cast<HistoryPhoto*>(itemMsg->getMedia())) {
if (const auto media = item ? item->getMedia() : nullptr) {
const auto caption = media->getCaption();
if (!caption.text.isEmpty()) {
auto asBot = (item->author()->isUser()
&& item->author()->asUser()->botInfo);
auto skipw = qMax(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width());
@ -1275,7 +1276,7 @@ void MediaView::displayPhoto(not_null<PhotoData*> photo, HistoryItem *item) {
_caption = Text(maxw);
_caption.setMarkedText(
st::mediaviewCaptionStyle,
photoMsg->getCaption(),
caption,
itemTextOptions(item));
}
}
@ -2254,21 +2255,16 @@ MediaView::Entity MediaView::entityForSharedMedia(int index) const {
return { base::none, nullptr };
}
auto value = (*_sharedMediaData)[index];
if (auto photo = base::get_if<not_null<PhotoData*>>(&value)) {
if (const auto photo = base::get_if<not_null<PhotoData*>>(&value)) {
// Last peer photo.
return { *photo, nullptr };
} else if (auto itemId = base::get_if<FullMsgId>(&value)) {
if (auto item = App::histItemById(*itemId)) {
if (auto media = item->getMedia()) {
switch (media->type()) {
case MediaTypePhoto: return {
static_cast<HistoryPhoto*>(item->getMedia())->photo(),
item
};
case MediaTypeFile:
case MediaTypeVideo:
case MediaTypeGif:
case MediaTypeSticker: return { media->getDocument(), item };
} else if (const auto itemId = base::get_if<FullMsgId>(&value)) {
if (const auto item = App::histItemById(*itemId)) {
if (const auto media = item->getMedia()) {
if (const auto photo = media->getPhoto()) {
return { photo, item };
} else if (const auto document = media->getDocument()) {
return { document, item };
}
}
return { base::none, item };