Skip to content

Commit

Permalink
Fix crash in ttl video, track editions.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jan 16, 2024
1 parent 605b255 commit 5033b9e
Showing 1 changed file with 70 additions and 27 deletions.
97 changes: 70 additions & 27 deletions Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class PreviewWrap final : public Ui::RpWidget {

private:
void paintEvent(QPaintEvent *e) override;
void createView();
[[nodiscard]] bool goodItem() const;
void clear();

const not_null<HistoryItem*> _item;
const std::unique_ptr<Ui::ChatStyle> _style;
Expand Down Expand Up @@ -162,6 +165,30 @@ PreviewWrap::PreviewWrap(
update(_elementGeometry);
}
}, lifetime());
session->data().itemViewRefreshRequest(
) | rpl::start_with_next([=](not_null<HistoryItem*> item) {
if (item == _item) {
if (goodItem()) {
createView();
update();
} else {
clear();
_closeRequests.fire({});
}
}
}, lifetime());
session->data().itemDataChanges(
) | rpl::start_with_next([=](not_null<HistoryItem*> item) {
if (item == _item) {
_element->itemDataChanged();
}
}, lifetime());
session->data().itemRemoved(
) | rpl::start_with_next([=](not_null<const HistoryItem*> item) {
if (item == _item) {
_closeRequests.fire({});
}
}, lifetime());

{
const auto close = Ui::CreateChild<Ui::RoundButton>(
Expand All @@ -187,32 +214,7 @@ PreviewWrap::PreviewWrap(
}

QWidget::setAttribute(Qt::WA_OpaquePaintEvent, false);
_element = _item->createView(_delegate.get());

{
_element->initDimensions();
rpl::combine(
sizeValue(),
_globalViewport.value()
) | rpl::start_with_next([=](QSize outer, QRect globalViewport) {
_viewport = globalViewport.isEmpty()
? rect()
: mapFromGlobal(globalViewport);
if (_viewport.width() < st::msgMinWidth) {
return;
}
_element->resizeGetHeight(_viewport.width());
_elementGeometry = QRect(
(_viewport.width() - _element->width()) / 2,
(_viewport.height() - _element->height()) / 2,
_element->width(),
_element->height()
).translated(_viewport.topLeft());
_elementInner = _element->innerGeometry().translated(
_elementGeometry.topLeft());
update();
}, _elementLifetime);
}
createView();

{
auto text = item->out()
Expand Down Expand Up @@ -260,11 +262,52 @@ rpl::producer<> PreviewWrap::closeRequests() const {
return _closeRequests.events();
}

PreviewWrap::~PreviewWrap() {
bool PreviewWrap::goodItem() const {
const auto media = _item->media();
if (!media || !media->ttlSeconds()) {
return false;
}
const auto document = media->document();
return document
&& (document->isVoiceMessage() || document->isVideoMessage());
}

void PreviewWrap::createView() {
clear();
_element = _item->createView(_delegate.get());
_element->initDimensions();
rpl::combine(
sizeValue(),
_globalViewport.value()
) | rpl::start_with_next([=](QSize outer, QRect globalViewport) {
_viewport = globalViewport.isEmpty()
? rect()
: mapFromGlobal(globalViewport);
if (_viewport.width() < st::msgMinWidth) {
return;
}
_element->resizeGetHeight(_viewport.width());
_elementGeometry = QRect(
(_viewport.width() - _element->width()) / 2,
(_viewport.height() - _element->height()) / 2,
_element->width(),
_element->height()
).translated(_viewport.topLeft());
_elementInner = _element->innerGeometry().translated(
_elementGeometry.topLeft());
update();
}, _elementLifetime);
}

void PreviewWrap::clear() {
_elementLifetime.destroy();
_element = nullptr;
}

PreviewWrap::~PreviewWrap() {
clear();
}

void PreviewWrap::paintEvent(QPaintEvent *e) {
if (!_element || _elementGeometry.isEmpty()) {
return;
Expand Down

0 comments on commit 5033b9e

Please sign in to comment.