From d4253d2025ac7f23178c3db96bdad6ff687c6a97 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 3 Mar 2018 15:55:53 +0300 Subject: [PATCH] Fix reply previews display. --- .../SourceFiles/data/data_media_types.cpp | 66 +++++++++++++++++++ Telegram/SourceFiles/data/data_media_types.h | 11 ++++ Telegram/SourceFiles/history/history_media.h | 6 -- .../history/history_media_grouped.cpp | 8 --- .../history/history_media_grouped.h | 2 - .../history/history_media_types.cpp | 43 ------------ .../SourceFiles/history/history_media_types.h | 40 ----------- 7 files changed, 77 insertions(+), 99 deletions(-) diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 0eb84fc02..cd297ae9f 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -294,6 +294,14 @@ bool MediaPhoto::canBeGrouped() const { return true; } +bool MediaPhoto::hasReplyPreview() const { + return !_photo->thumb->isNull(); +} + +ImagePtr MediaPhoto::replyPreview() const { + return _photo->makeReplyPreview(); +} + QString MediaPhoto::notificationText() const { return WithCaptionNotificationText( lang(lng_in_dlg_photo), @@ -487,6 +495,14 @@ bool MediaFile::canBeGrouped() const { return _document->isVideoFile(); } +bool MediaFile::hasReplyPreview() const { + return !_document->thumb->isNull(); +} + +ImagePtr MediaFile::replyPreview() const { + return _document->makeReplyPreview(); +} + QString MediaFile::chatsListText() const { if (const auto sticker = _document->sticker()) { return Media::chatsListText(); @@ -929,6 +945,24 @@ WebPageData *MediaWebPage::webpage() const { return _page; } +bool MediaWebPage::hasReplyPreview() const { + if (const auto document = _page->document) { + return !document->thumb->isNull(); + } else if (const auto photo = _page->photo) { + return !photo->thumb->isNull(); + } + return false; +} + +ImagePtr MediaWebPage::replyPreview() const { + if (const auto document = _page->document) { + return document->makeReplyPreview(); + } else if (const auto photo = _page->photo) { + return photo->makeReplyPreview(); + } + return ImagePtr(); +} + QString MediaWebPage::chatsListText() const { return notificationText(); } @@ -974,6 +1008,24 @@ std::unique_ptr MediaGame::clone(not_null parent) { return std::make_unique(parent, _game); } +bool MediaGame::hasReplyPreview() const { + if (const auto document = _game->document) { + return !document->thumb->isNull(); + } else if (const auto photo = _game->photo) { + return !photo->thumb->isNull(); + } + return false; +} + +ImagePtr MediaGame::replyPreview() const { + if (const auto document = _game->document) { + return document->makeReplyPreview(); + } else if (const auto photo = _game->photo) { + return photo->makeReplyPreview(); + } + return ImagePtr(); +} + QString MediaGame::notificationText() const { // Add a game controller emoji before game title. auto result = QString(); @@ -1054,6 +1106,20 @@ const Invoice *MediaInvoice::invoice() const { return &_invoice; } +bool MediaInvoice::hasReplyPreview() const { + if (const auto photo = _invoice.photo) { + return !photo->thumb->isNull(); + } + return false; +} + +ImagePtr MediaInvoice::replyPreview() const { + if (const auto photo = _invoice.photo) { + return photo->makeReplyPreview(); + } + return ImagePtr(); +} + QString MediaInvoice::notificationText() const { return _invoice.title; } diff --git a/Telegram/SourceFiles/data/data_media_types.h b/Telegram/SourceFiles/data/data_media_types.h index dce8d0c41..e60aeece4 100644 --- a/Telegram/SourceFiles/data/data_media_types.h +++ b/Telegram/SourceFiles/data/data_media_types.h @@ -134,6 +134,8 @@ public: bool uploading() const override; Storage::SharedMediaTypesMask sharedMediaTypes() const override; bool canBeGrouped() const override; + bool hasReplyPreview() const override; + ImagePtr replyPreview() const override; QString chatsListText() const override; QString notificationText() const override; QString pinnedTextSubstring() const override; @@ -168,6 +170,8 @@ public: bool uploading() const override; Storage::SharedMediaTypesMask sharedMediaTypes() const override; bool canBeGrouped() const override; + bool hasReplyPreview() const override; + ImagePtr replyPreview() const override; QString chatsListText() const override; QString notificationText() const override; QString pinnedTextSubstring() const override; @@ -289,6 +293,9 @@ public: std::unique_ptr clone(not_null parent) override; WebPageData *webpage() const override; + + bool hasReplyPreview() const override; + ImagePtr replyPreview() const override; QString chatsListText() const override; QString notificationText() const override; QString pinnedTextSubstring() const override; @@ -316,6 +323,8 @@ public: GameData *game() const override; + bool hasReplyPreview() const override; + ImagePtr replyPreview() const override; QString notificationText() const override; QString pinnedTextSubstring() const override; TextWithEntities clipboardText() const override; @@ -349,6 +358,8 @@ public: const Invoice *invoice() const override; + bool hasReplyPreview() const override; + ImagePtr replyPreview() const override; QString notificationText() const override; QString pinnedTextSubstring() const override; TextWithEntities clipboardText() const override; diff --git a/Telegram/SourceFiles/history/history_media.h b/Telegram/SourceFiles/history/history_media.h index 5330857af..2f2a6b662 100644 --- a/Telegram/SourceFiles/history/history_media.h +++ b/Telegram/SourceFiles/history/history_media.h @@ -168,12 +168,6 @@ public: return false; } - virtual bool hasReplyPreview() const { - return false; - } - virtual ImagePtr replyPreview() { - return ImagePtr(); - } virtual TextWithEntities getCaption() const { return TextWithEntities(); } diff --git a/Telegram/SourceFiles/history/history_media_grouped.cpp b/Telegram/SourceFiles/history/history_media_grouped.cpp index 30ba0b0ce..8856712a2 100644 --- a/Telegram/SourceFiles/history/history_media_grouped.cpp +++ b/Telegram/SourceFiles/history/history_media_grouped.cpp @@ -350,14 +350,6 @@ not_null HistoryGroupedMedia::main() const { return _parts.back().content.get(); } -bool HistoryGroupedMedia::hasReplyPreview() const { - return main()->hasReplyPreview(); -} - -ImagePtr HistoryGroupedMedia::replyPreview() { - return main()->replyPreview(); -} - TextWithEntities HistoryGroupedMedia::getCaption() const { return main()->getCaption(); } diff --git a/Telegram/SourceFiles/history/history_media_grouped.h b/Telegram/SourceFiles/history/history_media_grouped.h index bc0061602..69e47ca44 100644 --- a/Telegram/SourceFiles/history/history_media_grouped.h +++ b/Telegram/SourceFiles/history/history_media_grouped.h @@ -59,8 +59,6 @@ public: const ClickHandlerPtr &p, bool pressed) override; - bool hasReplyPreview() const override; - ImagePtr replyPreview() override; TextWithEntities getCaption() const override; Storage::SharedMediaTypesMask sharedMediaTypes() const override; diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index e612fe6d3..316982e6e 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -681,10 +681,6 @@ bool HistoryPhoto::needsBubble() const { return false; } -ImagePtr HistoryPhoto::replyPreview() { - return _data->makeReplyPreview(); -} - HistoryVideo::HistoryVideo( not_null parent, not_null realParent, @@ -1136,21 +1132,6 @@ void HistoryVideo::updateStatusText() const { } } -ImagePtr HistoryVideo::replyPreview() { - if (_data->replyPreview->isNull() && !_data->thumb->isNull()) { - if (_data->thumb->loaded()) { - auto w = convertScale(_data->thumb->width()); - auto h = convertScale(_data->thumb->height()); - if (w <= 0) w = 1; - if (h <= 0) h = 1; - _data->replyPreview = ImagePtr(w > h ? _data->thumb->pix(w * st::msgReplyBarSize.height() / h, st::msgReplyBarSize.height()) : _data->thumb->pix(st::msgReplyBarSize.height()), "PNG"); - } else { - _data->thumb->load(); - } - } - return _data->replyPreview; -} - HistoryDocument::HistoryDocument( not_null parent, not_null document) @@ -1856,10 +1837,6 @@ TextWithEntities HistoryDocument::getCaption() const { return TextWithEntities(); } -ImagePtr HistoryDocument::replyPreview() { - return _data->makeReplyPreview(); -} - HistoryGif::HistoryGif( not_null parent, not_null document) @@ -2564,10 +2541,6 @@ QString HistoryGif::additionalInfoString() const { return QString(); } -ImagePtr HistoryGif::replyPreview() { - return _data->makeReplyPreview(); -} - int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const { int result = 0; if (forwarded) { @@ -2930,10 +2903,6 @@ TextState HistorySticker::textState(QPoint point, StateRequest request) const { return result; } -ImagePtr HistorySticker::replyPreview() { - return _data->makeReplyPreview(); -} - int HistorySticker::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply) const { int result = 0; if (via) { @@ -3784,14 +3753,6 @@ TextWithEntities HistoryWebPage::selectedText(TextSelection selection) const { return titleResult; } -bool HistoryWebPage::hasReplyPreview() const { - return _attach ? _attach->hasReplyPreview() : (_data->photo ? true : false); -} - -ImagePtr HistoryWebPage::replyPreview() { - return _attach ? _attach->replyPreview() : (_data->photo ? _data->photo->makeReplyPreview() : ImagePtr()); -} - QMargins HistoryWebPage::inBubblePadding() const { auto lshift = st::msgPadding.left() + st::webPageLeft; auto rshift = st::msgPadding.right(); @@ -4181,10 +4142,6 @@ TextWithEntities HistoryGame::selectedText(TextSelection selection) const { return titleResult; } -ImagePtr HistoryGame::replyPreview() { - return _attach ? _attach->replyPreview() : (_data->photo ? _data->photo->makeReplyPreview() : ImagePtr()); -} - void HistoryGame::playAnimation(bool autoplay) { if (_attach) { if (autoplay) { diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index 63d1916e7..55f7f7264 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -176,11 +176,6 @@ public: QPoint point, StateRequest request) const override; - bool hasReplyPreview() const override { - return !_data->thumb->isNull(); - } - ImagePtr replyPreview() override; - TextWithEntities getCaption() const override { return _caption.originalTextWithEntities(); } @@ -272,11 +267,6 @@ public: return _data->uploading(); } - bool hasReplyPreview() const override { - return !_data->thumb->isNull(); - } - ImagePtr replyPreview() override; - TextWithEntities getCaption() const override { return _caption.originalTextWithEntities(); } @@ -347,11 +337,6 @@ public: return _data; } - bool hasReplyPreview() const override { - return !_data->thumb->isNull(); - } - ImagePtr replyPreview() override; - TextWithEntities getCaption() const override; bool needsBubble() const override { return true; @@ -426,11 +411,6 @@ public: void stopAnimation() override; - bool hasReplyPreview() const override { - return !_data->thumb->isNull(); - } - ImagePtr replyPreview() override; - TextWithEntities getCaption() const override { return _caption.originalTextWithEntities(); } @@ -517,11 +497,6 @@ public: return _data; } - bool hasReplyPreview() const override { - return !_data->thumb->isNull(); - } - ImagePtr replyPreview() override; - bool needsBubble() const override { return false; } @@ -704,9 +679,6 @@ public: if (_attach) _attach->stopAnimation(); } - bool hasReplyPreview() const override; - ImagePtr replyPreview() override; - not_null webpage() { return _data; } @@ -806,11 +778,6 @@ public: if (_attach) _attach->stopAnimation(); } - bool hasReplyPreview() const override { - return (_data->photo && !_data->photo->thumb->isNull()) || (_data->document && !_data->document->thumb->isNull()); - } - ImagePtr replyPreview() override; - not_null game() { return _data; } @@ -902,13 +869,6 @@ public: void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; - bool hasReplyPreview() const override { - return _attach && _attach->hasReplyPreview(); - } - ImagePtr replyPreview() override { - return _attach ? _attach->replyPreview() : ImagePtr(); - } - bool needsBubble() const override { return true; }