Fix crash in live location message destruction.

This commit is contained in:
John Preston
2025-11-24 12:23:13 +04:00
parent ef15136a3b
commit 313872dacc
7 changed files with 16 additions and 39 deletions
@@ -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);
}
}
@@ -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;
@@ -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();
@@ -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);
@@ -78,7 +78,6 @@ private:
Ui::Text::String _nameLine;
Ui::Text::String _phoneLine;
Ui::Text::String _infoLine;
Fn<void(not_null<Ui::GenericBox*>)> _vcardBoxFactory;
@@ -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();
@@ -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(