From db121c083996b47a0f7582f2bed3ed9971ce4bb3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 22 Mar 2019 14:22:32 +0400 Subject: [PATCH] Take album caption from any album item. --- .../history/media/history_media_grouped.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/history/media/history_media_grouped.cpp b/Telegram/SourceFiles/history/media/history_media_grouped.cpp index ac44af5f1..517a3f579 100644 --- a/Telegram/SourceFiles/history/media/history_media_grouped.cpp +++ b/Telegram/SourceFiles/history/media/history_media_grouped.cpp @@ -390,19 +390,21 @@ HistoryMessageEdited *HistoryGroupedMedia::displayedEditBadge() const { } void HistoryGroupedMedia::updateNeedBubbleState() { - const auto hasCaption = [&] { - if (_parts.front().item->emptyText()) { - return false; - } - for (auto i = 1, count = int(_parts.size()); i != count; ++i) { - if (!_parts[i].item->emptyText()) { - return false; + const auto captionItem = [&]() -> HistoryItem* { + auto result = (HistoryItem*)nullptr; + for (const auto &part : _parts) { + if (!part.item->emptyText()) { + if (result) { + return nullptr; + } else { + result = part.item; + } } } - return true; + return result; }(); - if (hasCaption) { - _caption = createCaption(_parts.front().item); + if (captionItem) { + _caption = createCaption(captionItem); } _needBubble = computeNeedBubble(); }