From 313872dacc14cc4cc0715087735aab59dfd676f4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 24 Nov 2025 12:23:13 +0400 Subject: [PATCH] Fix crash in live location message destruction. --- .../history/view/history_view_element.cpp | 5 +-- .../history/view/history_view_element.h | 2 +- .../history/view/history_view_message.h | 7 ++--- .../view/media/history_view_contact.cpp | 31 ------------------- .../history/view/media/history_view_contact.h | 1 - .../view/media/history_view_location.cpp | 4 +++ .../view/media/history_view_todo_list.cpp | 5 +++ 7 files changed, 16 insertions(+), 39 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 5c47a873f0..f830c6e15e 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -1914,11 +1914,12 @@ auto Element::verticalRepaintRange() const -> VerticalRepaintRange { } bool Element::hasHeavyPart() const { - return (_flags & Flag::HeavyCustomEmoji); + return (_flags & Flag::HeavyCustomEmoji) + || (_media && _media->hasHeavyPart()); } void Element::checkHeavyPart() { - if (!hasHeavyPart() && (!_media || !_media->hasHeavyPart())) { + if (!hasHeavyPart()) { history()->owner().unregisterHeavyViewPart(this); } } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index ab2d0195f7..74541332c0 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -594,7 +594,6 @@ public: void itemTextUpdated(); void blockquoteExpandChanged(); - [[nodiscard]] virtual bool hasHeavyPart() const; virtual void unloadHeavyPart(); void checkHeavyPart(); @@ -687,6 +686,7 @@ protected: [[nodiscard]] ClickHandlerPtr fromLink() const; + [[nodiscard]] virtual bool hasHeavyPart() const; virtual void refreshDataIdHook(); [[nodiscard]] const Ui::Text::String &text() const; diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 66b1ea0da3..cb6ae9d389 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -113,7 +113,6 @@ public: const TextState &reactionState) const override; int reactionsOptimalWidth() const override; - bool hasHeavyPart() const override; void unloadHeavyPart() override; // hasFromPhoto() returns true even if we don't display the photo @@ -165,14 +164,14 @@ public: QRect innerGeometry() const override; [[nodiscard]] BottomRippleMask bottomRippleMask(int buttonHeight) const; -protected: - void refreshDataIdHook() override; - private: struct CommentsButton; struct FromNameStatus; struct RightAction; + void refreshDataIdHook() override; + bool hasHeavyPart() const override; + bool updateBottomInfo(); void initPaidInformation(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp index 82d61b73e2..6474f908bb 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp @@ -227,13 +227,6 @@ Contact::Contact( st::webPageDescriptionStyle, Ui::FormatPhone(data.phoneNumber), Ui::WebpageTextTitleOptions()); - -#if 0 // No info. - _infoLine.setText( - st::webPageDescriptionStyle, - phone, - Ui::WebpageTextTitleOptions()); -#endif } Contact::~Contact() { @@ -322,10 +315,6 @@ QSize Contact::countOptimalSize() { accumulate_max(maxWidth, lineLeft + _phoneLine.maxWidth()); textMinHeight += 1 * lineHeight; } - if (!_infoLine.isEmpty()) { - accumulate_max(maxWidth, lineLeft + _infoLine.maxWidth()); - textMinHeight += std::min(_infoLine.minHeight(), 1 * lineHeight); - } minHeight = std::max(textMinHeight, st::contactsPhotoSize); if (!_buttons.empty()) { @@ -500,26 +489,6 @@ void Contact::draw(Painter &p, const PaintContext &context) const { toTitleSelection(context.selection)); tshift += 1 * lineHeight; } - if (!_infoLine.isEmpty()) { - tshift += st::lineWidth * 3; // Additional skip. - const auto endskip = _infoLine.hasSkipBlock() - ? _parent->skipBlockWidth() - : 0; - _parent->prepareCustomEmojiPaint(p, context, _infoLine); - _infoLine.draw(p, { - .position = { lineLeft, tshift }, - .outerWidth = width(), - .availableWidth = lineWidth, - .spoiler = Ui::Text::DefaultSpoilerCache(), - .now = context.now, - .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), - .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), - .selection = toDescriptionSelection(context.selection), - .elisionHeight = (1 * lineHeight), - .elisionRemoveFromEnd = endskip, - }); - tshift += (1 * lineHeight); - } if (!_buttons.empty()) { p.setFont(st::semiboldFont); diff --git a/Telegram/SourceFiles/history/view/media/history_view_contact.h b/Telegram/SourceFiles/history/view/media/history_view_contact.h index 83c10aa2c4..87110112ec 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_contact.h +++ b/Telegram/SourceFiles/history/view/media/history_view_contact.h @@ -78,7 +78,6 @@ private: Ui::Text::String _nameLine; Ui::Text::String _phoneLine; - Ui::Text::String _infoLine; Fn)> _vcardBoxFactory; diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp index 5b8b18e61b..94c877f672 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp @@ -160,7 +160,11 @@ void Location::checkLiveFinish() { const auto item = _parent->data(); const auto start = item->date(); if (_live->period != kUntilOffPeriod && now - start >= _live->period) { + const auto had = hasHeavyPart(); _live = nullptr; + if (had && !hasHeavyPart()) { + _parent->checkHeavyPart(); + } item->history()->owner().requestViewResize(_parent); } else { _parent->repaint(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_todo_list.cpp b/Telegram/SourceFiles/history/view/media/history_view_todo_list.cpp index 4754e80c51..fd31d07e4f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_todo_list.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_todo_list.cpp @@ -317,6 +317,7 @@ void TodoList::updateTasks(bool skipAnimations) { } return; } + const auto has = hasHeavyPart(); _tasks = ranges::views::all( _todolist->items ) | ranges::views::transform([&](const TodoListItem &item) { @@ -331,6 +332,10 @@ void TodoList::updateTasks(bool skipAnimations) { } updateCompletionStatus(); + + if (has && !hasHeavyPart()) { + _parent->checkHeavyPart(); + } } ClickHandlerPtr TodoList::createTaskClickHandler(