Fixed sending animation from inline bots with unexpected result type.

This commit is contained in:
23rd 2022-03-14 13:10:14 +03:00
parent 34f6c6b23f
commit 0b336a2954
11 changed files with 51 additions and 12 deletions

View file

@ -1103,6 +1103,7 @@ bool FieldAutocomplete::Inner::chooseAtIndex(
stickerBoundingBox()));
contentRect.moveCenter(bounding.center());
return {
Ui::MessageSendingAnimationFrom::Type::Sticker,
_controller->session().data().nextLocalMessageId(),
mapToGlobal(std::move(contentRect)),
};

View file

@ -447,6 +447,7 @@ void GifsListWidget::selectInlineResult(
const auto rect = item->innerContentRect().translated(
_mosaic.findRect(index).topLeft());
return Ui::MessageSendingAnimationFrom{
.type = Ui::MessageSendingAnimationFrom::Type::Gif,
.localId = controller()->session().data().nextLocalMessageId(),
.globalStartGeometry = mapToGlobal(rect),
.crop = true,

View file

@ -2529,6 +2529,7 @@ Ui::MessageSendingAnimationFrom StickersListWidget::messageSentAnimationInfo(
(rect.height() - size.height()) / 2);
return {
.type = Ui::MessageSendingAnimationFrom::Type::Sticker,
.localId = session().data().nextLocalMessageId(),
.globalStartGeometry = mapToGlobal(
QRect(rect.topLeft() + innerPos, size)),

View file

@ -5391,7 +5391,8 @@ void HistoryWidget::startItemRevealAnimations() {
void HistoryWidget::startMessageSendingAnimation(
not_null<HistoryItem*> item) {
auto &sendingAnimation = controller()->sendingAnimation();
if (!sendingAnimation.hasLocalMessage(item->fullId().msg)) {
if (!sendingAnimation.hasLocalMessage(item->fullId().msg)
|| !sendingAnimation.checkExpectedType(item)) {
return;
}
Assert(item->mainView() != nullptr);

View file

@ -1581,7 +1581,8 @@ void ListWidget::startItemRevealAnimations() {
void ListWidget::startMessageSendingAnimation(
not_null<HistoryItem*> item) {
auto &sendingAnimation = controller()->sendingAnimation();
if (!sendingAnimation.hasLocalMessage(item->fullId().msg)) {
if (!sendingAnimation.hasLocalMessage(item->fullId().msg)
|| !sendingAnimation.checkExpectedType(item)) {
return;
}

View file

@ -73,9 +73,6 @@ public:
bool hasRightSkip() const override {
return true;
}
bool hasSendingAnimation() const override {
return true;
}
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
TextState getState(
@ -194,9 +191,6 @@ public:
bool hasRightSkip() const override {
return false;
}
bool hasSendingAnimation() const override {
return true;
}
void preload() const override;
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;

View file

@ -83,9 +83,6 @@ public:
virtual bool hasRightSkip() const {
return false;
}
virtual bool hasSendingAnimation() const {
return false;
}
Result *getResult() const;
DocumentData *getDocument() const;

View file

@ -270,12 +270,22 @@ void Inner::selectInlineResult(
const auto document = item->getDocument()
? item->getDocument()
: item->getPreviewDocument();
if (options.scheduled || !item->hasSendingAnimation()) {
if (options.scheduled
|| item->isFullLine()
|| !document
|| (!document->sticker() && !document->isGifv())) {
return {};
}
using Type = Ui::MessageSendingAnimationFrom::Type;
const auto type = document->sticker()
? Type::Sticker
: document->isGifv()
? Type::Gif
: Type::None;
const auto rect = item->innerContentRect().translated(
_mosaic.findRect(index).topLeft());
return {
.type = type,
.localId = _controller->session().data().nextLocalMessageId(),
.globalStartGeometry = mapToGlobal(rect),
.crop = document->isGifv(),

View file

@ -10,6 +10,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
struct MessageSendingAnimationFrom {
enum class Type {
None,
Sticker,
Gif,
};
Type type = Type::None;
std::optional<MsgId> localId;
QRect globalStartGeometry;
bool crop = false;

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/effects/message_sending_animation_controller.h"
#include "data/data_document.h"
#include "data/data_session.h"
#include "history/history_item.h"
#include "history/view/history_view_element.h"
@ -417,4 +418,29 @@ void MessageSendingAnimationController::clear() {
_processing.clear();
}
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;
}
} // namespace Ui

View file

@ -39,6 +39,7 @@ public:
[[nodiscard]] bool hasLocalMessage(MsgId msgId) const;
[[nodiscard]] bool hasAnimatedMessage(not_null<HistoryItem*> item) const;
[[nodiscard]] bool checkExpectedType(not_null<HistoryItem*> item);
void clear();