2022-02-08 19:19:01 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "ui/effects/message_sending_animation_controller.h"
|
|
|
|
|
2022-03-14 10:10:14 +00:00
|
|
|
#include "data/data_document.h"
|
2022-02-10 19:34:50 +00:00
|
|
|
#include "data/data_session.h"
|
2022-02-08 19:19:01 +00:00
|
|
|
#include "history/history_item.h"
|
|
|
|
#include "history/view/history_view_element.h"
|
|
|
|
#include "history/view/history_view_list_widget.h" // kItemRevealDuration
|
|
|
|
#include "history/view/media/history_view_media.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "ui/chat/chat_style.h"
|
|
|
|
#include "ui/chat/chat_theme.h"
|
|
|
|
#include "ui/effects/animation_value.h"
|
|
|
|
#include "ui/effects/animation_value_f.h"
|
|
|
|
#include "ui/effects/animations.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2022-02-08 19:19:01 +00:00
|
|
|
#include "ui/rp_widget.h"
|
|
|
|
#include "window/window_session_controller.h"
|
2022-02-13 22:40:34 +00:00
|
|
|
#include "styles/style_chat.h"
|
2022-02-08 19:19:01 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
namespace {
|
|
|
|
|
2022-02-08 23:16:17 +00:00
|
|
|
constexpr auto kSurroundingProgress = 0.5;
|
|
|
|
|
|
|
|
inline float64 OffsetMid(int value, float64 min, float64 max = 1.) {
|
|
|
|
return ((value * max) - (value * min)) / 2.;
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:19:01 +00:00
|
|
|
class Content final : public RpWidget {
|
|
|
|
public:
|
|
|
|
Content(
|
|
|
|
not_null<RpWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
2022-02-13 22:40:34 +00:00
|
|
|
const MessageSendingAnimationFrom &fromInfo,
|
2022-02-08 19:19:01 +00:00
|
|
|
MessageSendingAnimationController::SendingInfoTo &&to);
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<> destroyRequests() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2022-02-08 23:16:17 +00:00
|
|
|
using Context = Ui::ChatPaintContext;
|
|
|
|
|
2022-02-10 19:18:07 +00:00
|
|
|
void createSurrounding();
|
2022-02-13 22:40:34 +00:00
|
|
|
void createBubble();
|
2022-03-05 14:19:38 +00:00
|
|
|
HistoryView::Element *maybeView() const;
|
|
|
|
bool checkView(HistoryView::Element *currentView) const;
|
2022-02-13 22:40:34 +00:00
|
|
|
void drawContent(Painter &p, float64 progress) const;
|
2022-02-08 19:19:01 +00:00
|
|
|
|
|
|
|
const not_null<Window::SessionController*> _controller;
|
2022-02-13 22:40:34 +00:00
|
|
|
const bool _crop;
|
2022-02-11 06:38:44 +00:00
|
|
|
MessageSendingAnimationController::SendingInfoTo _toInfo;
|
2022-02-08 19:19:01 +00:00
|
|
|
QRect _from;
|
2022-02-14 00:25:04 +00:00
|
|
|
QPoint _to;
|
2022-02-10 19:34:50 +00:00
|
|
|
QRect _innerContentRect;
|
2022-02-08 19:19:01 +00:00
|
|
|
|
|
|
|
Animations::Simple _animation;
|
|
|
|
float64 _minScale = 0;
|
|
|
|
|
2022-02-13 22:40:34 +00:00
|
|
|
struct {
|
|
|
|
base::unique_qptr<Ui::RpWidget> widget;
|
|
|
|
QPoint offsetFromContent;
|
|
|
|
} _bubble;
|
2022-02-10 19:18:07 +00:00
|
|
|
base::unique_qptr<Ui::RpWidget> _surrounding;
|
2022-02-08 23:16:17 +00:00
|
|
|
|
2022-02-08 19:19:01 +00:00
|
|
|
rpl::event_stream<> _destroyRequests;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Content::Content(
|
|
|
|
not_null<RpWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
2022-02-13 22:40:34 +00:00
|
|
|
const MessageSendingAnimationFrom &fromInfo,
|
2022-02-08 19:19:01 +00:00
|
|
|
MessageSendingAnimationController::SendingInfoTo &&to)
|
|
|
|
: RpWidget(parent)
|
|
|
|
, _controller(controller)
|
2022-02-13 22:40:34 +00:00
|
|
|
, _crop(fromInfo.crop)
|
2022-02-11 06:38:44 +00:00
|
|
|
, _toInfo(std::move(to))
|
2022-02-13 22:40:34 +00:00
|
|
|
, _from(parent->mapFromGlobal(fromInfo.globalStartGeometry))
|
2022-03-05 14:19:38 +00:00
|
|
|
, _innerContentRect(maybeView()->media()->contentRectForReactions())
|
2022-02-14 00:25:04 +00:00
|
|
|
, _minScale(float64(_from.height()) / _innerContentRect.height()) {
|
2022-02-11 06:38:44 +00:00
|
|
|
Expects(_toInfo.view != nullptr);
|
|
|
|
Expects(_toInfo.paintContext != nullptr);
|
2022-02-08 19:19:01 +00:00
|
|
|
|
|
|
|
show();
|
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
raise();
|
|
|
|
|
|
|
|
base::take(
|
2022-02-14 00:25:04 +00:00
|
|
|
_toInfo.globalEndTopLeft
|
2022-02-08 19:19:01 +00:00
|
|
|
) | rpl::distinct_until_changed(
|
2022-02-14 00:25:04 +00:00
|
|
|
) | rpl::start_with_next([=](const QPoint &p) {
|
|
|
|
_to = parent->mapFromGlobal(p);
|
2022-02-08 19:19:01 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_controller->session().downloaderTaskFinished(
|
|
|
|
) | rpl::start_with_next([=] {
|
2022-02-10 19:34:50 +00:00
|
|
|
update();
|
2022-02-08 19:19:01 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2022-02-10 19:34:50 +00:00
|
|
|
resize(_innerContentRect.size());
|
|
|
|
|
2022-03-05 14:19:38 +00:00
|
|
|
const auto innerGeometry = maybeView()->innerGeometry();
|
2022-02-14 00:25:04 +00:00
|
|
|
|
2022-02-08 19:19:01 +00:00
|
|
|
auto animationCallback = [=](float64 value) {
|
2022-02-10 19:34:50 +00:00
|
|
|
auto resultFrom = rect();
|
2022-02-08 19:19:01 +00:00
|
|
|
resultFrom.moveCenter(_from.center());
|
|
|
|
|
2022-02-14 00:25:04 +00:00
|
|
|
const auto resultTo = _to
|
|
|
|
+ innerGeometry.topLeft()
|
|
|
|
+ _innerContentRect.topLeft();
|
2022-02-08 23:16:17 +00:00
|
|
|
const auto x = anim::interpolate(resultFrom.x(), resultTo.x(), value);
|
|
|
|
const auto y = anim::interpolate(resultFrom.y(), resultTo.y(), value);
|
|
|
|
moveToLeft(x, y);
|
2022-02-08 19:19:01 +00:00
|
|
|
update();
|
|
|
|
|
2022-02-13 22:40:34 +00:00
|
|
|
if ((value > kSurroundingProgress)
|
|
|
|
&& !_surrounding
|
|
|
|
&& !_bubble.widget) {
|
2022-03-05 14:19:38 +00:00
|
|
|
const auto currentView = maybeView();
|
|
|
|
if (!checkView(currentView)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentView->hasBubble()) {
|
2022-02-13 22:40:34 +00:00
|
|
|
createBubble();
|
|
|
|
} else {
|
|
|
|
createSurrounding();
|
|
|
|
}
|
2022-02-08 23:16:17 +00:00
|
|
|
}
|
|
|
|
if (_surrounding) {
|
|
|
|
_surrounding->moveToLeft(
|
2022-02-10 19:34:50 +00:00
|
|
|
x - _innerContentRect.x(),
|
|
|
|
y - _innerContentRect.y());
|
2022-02-08 23:16:17 +00:00
|
|
|
}
|
2022-02-13 22:40:34 +00:00
|
|
|
if (_bubble.widget) {
|
|
|
|
_bubble.widget->moveToLeft(
|
|
|
|
x - _bubble.offsetFromContent.x(),
|
|
|
|
y - _bubble.offsetFromContent.y());
|
|
|
|
}
|
2022-02-08 23:16:17 +00:00
|
|
|
|
2022-02-08 19:19:01 +00:00
|
|
|
if (value == 1.) {
|
2022-03-05 14:19:38 +00:00
|
|
|
const auto currentView = maybeView();
|
|
|
|
if (!checkView(currentView)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-10 19:34:50 +00:00
|
|
|
const auto controller = _controller;
|
2022-02-08 19:19:01 +00:00
|
|
|
_destroyRequests.fire({});
|
2022-02-11 06:38:44 +00:00
|
|
|
controller->session().data().requestViewRepaint(currentView);
|
2022-02-08 19:19:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
animationCallback(0.);
|
|
|
|
_animation.start(
|
|
|
|
std::move(animationCallback),
|
|
|
|
0.,
|
|
|
|
1.,
|
|
|
|
HistoryView::ListWidget::kItemRevealDuration);
|
|
|
|
}
|
|
|
|
|
2022-03-05 14:19:38 +00:00
|
|
|
HistoryView::Element *Content::maybeView() const {
|
2022-02-11 06:38:44 +00:00
|
|
|
return _toInfo.view();
|
|
|
|
}
|
|
|
|
|
2022-03-05 14:19:38 +00:00
|
|
|
bool Content::checkView(HistoryView::Element *currentView) const {
|
|
|
|
if (!currentView) {
|
|
|
|
_destroyRequests.fire({});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:19:01 +00:00
|
|
|
void Content::paintEvent(QPaintEvent *e) {
|
2022-02-13 22:40:34 +00:00
|
|
|
const auto progress = _animation.value(_animation.animating() ? 0. : 1.);
|
2022-02-08 19:19:01 +00:00
|
|
|
|
2022-02-13 22:40:34 +00:00
|
|
|
if (!_crop) {
|
|
|
|
Painter p(this);
|
|
|
|
p.fillRect(e->rect(), Qt::transparent);
|
|
|
|
drawContent(p, progress);
|
|
|
|
} else {
|
|
|
|
// Use QImage to make CompositionMode_Clear work.
|
|
|
|
auto image = QImage(
|
|
|
|
size() * style::DevicePixelRatio(),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.setDevicePixelRatio(style::DevicePixelRatio());
|
|
|
|
image.fill(Qt::transparent);
|
|
|
|
|
|
|
|
const auto scaledFromSize = _from.size().scaled(
|
|
|
|
_innerContentRect.size(),
|
|
|
|
Qt::KeepAspectRatio);
|
|
|
|
const auto cropW = std::ceil(
|
|
|
|
(_innerContentRect.width() - scaledFromSize.width())
|
|
|
|
/ 2.
|
|
|
|
* (1. - std::clamp(progress / kSurroundingProgress, 0., 1.)));
|
|
|
|
|
|
|
|
{
|
|
|
|
Painter p(&image);
|
|
|
|
drawContent(p, progress);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Clear);
|
|
|
|
p.fillRect(
|
|
|
|
QRect(0, 0, cropW, _innerContentRect.height()),
|
|
|
|
Qt::black);
|
|
|
|
p.fillRect(
|
|
|
|
QRect(
|
|
|
|
_innerContentRect.width() - cropW,
|
|
|
|
0,
|
|
|
|
cropW,
|
|
|
|
_innerContentRect.height()),
|
|
|
|
Qt::black);
|
|
|
|
}
|
2022-02-08 19:19:01 +00:00
|
|
|
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(this);
|
2022-02-13 22:40:34 +00:00
|
|
|
p.drawImage(QPoint(), std::move(image));
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 19:19:01 +00:00
|
|
|
|
2022-02-13 22:40:34 +00:00
|
|
|
void Content::drawContent(Painter &p, float64 progress) const {
|
2022-02-08 19:19:01 +00:00
|
|
|
const auto scale = anim::interpolateF(_minScale, 1., progress);
|
|
|
|
|
|
|
|
p.translate(
|
2022-02-10 19:34:50 +00:00
|
|
|
(1 - progress) * OffsetMid(width(), _minScale),
|
|
|
|
(1 - progress) * OffsetMid(height(), _minScale));
|
2022-02-08 19:19:01 +00:00
|
|
|
p.scale(scale, scale);
|
2022-02-10 19:34:50 +00:00
|
|
|
|
2022-03-05 14:19:38 +00:00
|
|
|
const auto currentView = maybeView();
|
|
|
|
if (!checkView(currentView)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-11 06:38:44 +00:00
|
|
|
|
|
|
|
auto context = _toInfo.paintContext();
|
2022-02-10 19:34:50 +00:00
|
|
|
context.skipDrawingParts = Context::SkipDrawingParts::Surrounding;
|
2022-02-11 06:38:44 +00:00
|
|
|
context.outbg = currentView->hasOutLayout();
|
2022-02-10 19:34:50 +00:00
|
|
|
p.translate(-_innerContentRect.topLeft());
|
2022-02-11 06:38:44 +00:00
|
|
|
currentView->media()->draw(p, context);
|
2022-02-08 19:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Content::destroyRequests() const {
|
|
|
|
return _destroyRequests.events();
|
|
|
|
}
|
|
|
|
|
2022-02-10 19:18:07 +00:00
|
|
|
void Content::createSurrounding() {
|
|
|
|
_surrounding = base::make_unique_q<Ui::RpWidget>(parentWidget());
|
|
|
|
_surrounding->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
2022-03-05 14:19:38 +00:00
|
|
|
const auto currentView = maybeView();
|
|
|
|
if (!checkView(currentView)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-11 06:38:44 +00:00
|
|
|
const auto surroundingSize = currentView->innerGeometry().size();
|
2022-02-10 19:34:50 +00:00
|
|
|
const auto offset = _innerContentRect.topLeft();
|
2022-02-10 19:18:07 +00:00
|
|
|
|
|
|
|
_surrounding->resize(surroundingSize);
|
|
|
|
_surrounding->show();
|
|
|
|
|
|
|
|
// Do not raise.
|
|
|
|
_surrounding->stackUnder(this);
|
|
|
|
stackUnder(_surrounding.get());
|
|
|
|
|
|
|
|
_surrounding->paintRequest(
|
|
|
|
) | rpl::start_with_next([=, size = surroundingSize](const QRect &r) {
|
|
|
|
Painter p(_surrounding);
|
|
|
|
|
|
|
|
p.fillRect(r, Qt::transparent);
|
|
|
|
|
|
|
|
const auto progress = _animation.value(0.);
|
|
|
|
const auto revProgress = 1. - progress;
|
|
|
|
|
|
|
|
const auto divider = 1. - kSurroundingProgress;
|
|
|
|
const auto alpha = (divider - revProgress) / divider;
|
|
|
|
p.setOpacity(alpha);
|
|
|
|
|
|
|
|
const auto scale = anim::interpolateF(_minScale, 1., progress);
|
|
|
|
|
|
|
|
p.translate(
|
|
|
|
revProgress * OffsetMid(size.width() + offset.x(), _minScale),
|
|
|
|
revProgress * OffsetMid(size.height() + offset.y(), _minScale));
|
|
|
|
p.scale(scale, scale);
|
|
|
|
|
2022-03-05 14:19:38 +00:00
|
|
|
const auto currentView = maybeView();
|
|
|
|
if (!checkView(currentView)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-10 19:18:07 +00:00
|
|
|
|
2022-02-11 06:38:44 +00:00
|
|
|
auto context = _toInfo.paintContext();
|
2022-02-10 19:18:07 +00:00
|
|
|
context.skipDrawingParts = Context::SkipDrawingParts::Content;
|
2022-02-11 06:38:44 +00:00
|
|
|
context.outbg = currentView->hasOutLayout();
|
2022-02-10 19:18:07 +00:00
|
|
|
|
2022-02-11 06:38:44 +00:00
|
|
|
currentView->media()->draw(p, context);
|
2022-02-10 19:18:07 +00:00
|
|
|
}, _surrounding->lifetime());
|
|
|
|
}
|
|
|
|
|
2022-02-13 22:40:34 +00:00
|
|
|
void Content::createBubble() {
|
|
|
|
_bubble.widget = base::make_unique_q<Ui::RpWidget>(parentWidget());
|
|
|
|
_bubble.widget->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
2022-03-05 14:19:38 +00:00
|
|
|
const auto currentView = maybeView();
|
|
|
|
if (!checkView(currentView)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-13 22:40:34 +00:00
|
|
|
const auto innerGeometry = currentView->innerGeometry();
|
|
|
|
|
|
|
|
const auto tailWidth = st::historyBubbleTailOutLeft.width();
|
|
|
|
_bubble.offsetFromContent = QPoint(
|
|
|
|
currentView->hasOutLayout() ? 0 : tailWidth,
|
|
|
|
innerGeometry.y());
|
|
|
|
|
|
|
|
const auto scaleOffset = QPoint(0, innerGeometry.y());
|
|
|
|
const auto paintOffsetLeft = innerGeometry.x()
|
|
|
|
- _bubble.offsetFromContent.x();
|
|
|
|
|
|
|
|
const auto hasCommentsButton = currentView->data()->repliesAreComments()
|
|
|
|
|| currentView->data()->externalReply();
|
|
|
|
_bubble.widget->resize(innerGeometry.size()
|
|
|
|
+ QSize(
|
|
|
|
currentView->hasOutLayout() ? tailWidth : 0,
|
|
|
|
hasCommentsButton ? innerGeometry.y() : 0));
|
|
|
|
_bubble.widget->show();
|
|
|
|
|
|
|
|
_bubble.widget->stackUnder(this);
|
|
|
|
|
|
|
|
_bubble.widget->paintRequest(
|
|
|
|
) | rpl::start_with_next([=](const QRect &r) {
|
|
|
|
Painter p(_bubble.widget);
|
|
|
|
|
|
|
|
p.fillRect(r, Qt::transparent);
|
|
|
|
|
|
|
|
const auto progress = _animation.value(0.);
|
|
|
|
const auto revProgress = 1. - progress;
|
|
|
|
|
|
|
|
const auto divider = 1. - kSurroundingProgress;
|
|
|
|
const auto alpha = (divider - revProgress) / divider;
|
|
|
|
p.setOpacity(alpha);
|
|
|
|
|
|
|
|
const auto scale = anim::interpolateF(_minScale, 1., progress);
|
|
|
|
|
|
|
|
p.translate(
|
|
|
|
revProgress * OffsetMid(width() + scaleOffset.x(), _minScale),
|
|
|
|
revProgress * OffsetMid(height() + scaleOffset.y(), _minScale));
|
|
|
|
p.scale(scale, scale);
|
|
|
|
|
2022-03-05 14:19:38 +00:00
|
|
|
const auto currentView = maybeView();
|
|
|
|
if (!checkView(currentView)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-13 22:40:34 +00:00
|
|
|
|
|
|
|
auto context = _toInfo.paintContext();
|
|
|
|
context.skipDrawingParts = Context::SkipDrawingParts::Content;
|
|
|
|
context.outbg = currentView->hasOutLayout();
|
|
|
|
|
|
|
|
context.translate(paintOffsetLeft, 0);
|
|
|
|
p.translate(-paintOffsetLeft, 0);
|
|
|
|
|
|
|
|
currentView->draw(p, context);
|
|
|
|
}, _bubble.widget->lifetime());
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:19:01 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
MessageSendingAnimationController::MessageSendingAnimationController(
|
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: _controller(controller) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageSendingAnimationController::appendSending(
|
|
|
|
MessageSendingAnimationFrom from) {
|
|
|
|
if (anim::Disabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from.localId) {
|
2022-02-13 22:40:34 +00:00
|
|
|
_itemSendPending[*from.localId] = std::move(from);
|
2022-02-08 19:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageSendingAnimationController::startAnimation(SendingInfoTo &&to) {
|
|
|
|
if (anim::Disabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto container = _controller->content();
|
2022-02-10 18:53:51 +00:00
|
|
|
const auto item = to.view()->data();
|
2022-02-08 19:19:01 +00:00
|
|
|
|
|
|
|
const auto it = _itemSendPending.find(item->fullId().msg);
|
|
|
|
if (it == end(_itemSendPending)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto msg = it->first;
|
|
|
|
|
|
|
|
auto content = base::make_unique_q<Content>(
|
|
|
|
container,
|
|
|
|
_controller,
|
|
|
|
it->second,
|
|
|
|
std::move(to));
|
|
|
|
content->destroyRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_itemSendPending.erase(msg);
|
|
|
|
_processing.erase(item);
|
|
|
|
}, content->lifetime());
|
|
|
|
|
|
|
|
_processing.emplace(item, std::move(content));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MessageSendingAnimationController::hasLocalMessage(MsgId msgId) const {
|
|
|
|
return _itemSendPending.contains(msgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MessageSendingAnimationController::hasAnimatedMessage(
|
|
|
|
not_null<HistoryItem*> item) const {
|
|
|
|
return _processing.contains(item);
|
|
|
|
}
|
|
|
|
|
2022-02-10 23:57:13 +00:00
|
|
|
void MessageSendingAnimationController::clear() {
|
|
|
|
_itemSendPending.clear();
|
|
|
|
_processing.clear();
|
|
|
|
}
|
|
|
|
|
2022-03-14 10:10:14 +00:00
|
|
|
bool MessageSendingAnimationController::checkExpectedType(
|
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
const auto it = _itemSendPending.find(item->fullId().msg);
|
|
|
|
if (it == end(_itemSendPending)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto type = it->second.type;
|
|
|
|
const auto isSticker = type == MessageSendingAnimationFrom::Type::Sticker;
|
|
|
|
const auto isGif = type == MessageSendingAnimationFrom::Type::Gif;
|
|
|
|
if (isSticker || isGif) {
|
|
|
|
if (item->emptyText()) {
|
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto document = media->document()) {
|
|
|
|
if ((isGif && document->isGifv())
|
|
|
|
|| (isSticker && document->sticker())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_itemSendPending.erase(it);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:19:01 +00:00
|
|
|
} // namespace Ui
|