mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix crash in caption spoiler opening.
This commit is contained in:
parent
8fc35e45e4
commit
d4a2c4a151
2 changed files with 16 additions and 42 deletions
|
@ -15,52 +15,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
namespace {
|
|
||||||
|
|
||||||
class AnimatedSpoilerClickHandler final : public ClickHandler {
|
|
||||||
public:
|
|
||||||
AnimatedSpoilerClickHandler(
|
|
||||||
not_null<Element*> view,
|
|
||||||
Ui::Text::String &text);
|
|
||||||
|
|
||||||
void onClick(ClickContext context) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
base::weak_ptr<Element> _weak;
|
|
||||||
Ui::Text::String &_text;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
AnimatedSpoilerClickHandler::AnimatedSpoilerClickHandler(
|
|
||||||
not_null<Element*> view,
|
|
||||||
Ui::Text::String &text)
|
|
||||||
: _weak(view)
|
|
||||||
, _text(text) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnimatedSpoilerClickHandler::onClick(ClickContext context) const {
|
|
||||||
const auto button = context.button;
|
|
||||||
const auto view = _weak.get();
|
|
||||||
if (button != Qt::LeftButton || !view) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto my = context.other.value<ClickHandlerContext>();
|
|
||||||
if (const auto d = my.elementDelegate ? my.elementDelegate() : nullptr) {
|
|
||||||
_text.setSpoilerRevealed(true, anim::type::normal);
|
|
||||||
if (const auto controller = my.sessionWindow.get()) {
|
|
||||||
controller->session().data().registerShownSpoiler(view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void FillTextWithAnimatedSpoilers(
|
void FillTextWithAnimatedSpoilers(
|
||||||
not_null<Element*> view,
|
not_null<Element*> view,
|
||||||
Ui::Text::String &text) {
|
Ui::Text::String &text) {
|
||||||
if (text.hasSpoilers()) {
|
if (text.hasSpoilers()) {
|
||||||
text.setSpoilerLink(
|
text.setSpoilerLinkFilter([weak = base::make_weak(view.get())](
|
||||||
std::make_shared<AnimatedSpoilerClickHandler>(view, text));
|
const ClickContext &context) {
|
||||||
|
const auto my = context.other.value<ClickHandlerContext>();
|
||||||
|
const auto button = context.button;
|
||||||
|
const auto view = weak.get();
|
||||||
|
if (button != Qt::LeftButton || !view || !my.elementDelegate) {
|
||||||
|
return false;
|
||||||
|
} else if (const auto d = my.elementDelegate()) {
|
||||||
|
if (const auto controller = my.sessionWindow.get()) {
|
||||||
|
controller->session().data().registerShownSpoiler(view);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit d57bf79ce0862fda1093d9b9acfeff94c80a96f8
|
Subproject commit 0f7714390552c4071ccdf3b1c34f8cd33f759b4d
|
Loading…
Add table
Reference in a new issue