Added simple animation of stickers sending from inline bots.

This commit is contained in:
23rd 2022-02-11 07:40:11 +03:00 committed by John Preston
parent 2632ec45bd
commit 0a2fbb0d70
11 changed files with 66 additions and 10 deletions

View File

@ -3616,14 +3616,17 @@ void ApiWrap::sendBotStart(not_null<UserData*> bot, PeerData *chat) {
void ApiWrap::sendInlineResult(
not_null<UserData*> bot,
not_null<InlineBots::Result*> data,
const SendAction &action) {
const SendAction &action,
std::optional<MsgId> localMessageId) {
sendAction(action);
const auto history = action.history;
const auto peer = history->peer;
const auto newId = FullMsgId(
peer->id,
_session->data().nextLocalMessageId());
localMessageId
? (*localMessageId)
: _session->data().nextLocalMessageId());
const auto randomId = base::RandomValue<uint64>();
auto flags = NewMessageFlags(peer);

View File

@ -325,7 +325,8 @@ public:
void sendInlineResult(
not_null<UserData*> bot,
not_null<InlineBots::Result*> data,
const SendAction &action);
const SendAction &action,
std::optional<MsgId> localMessageId);
void sendMessageFail(
const MTP::Error &error,
not_null<PeerData*> peer,

View File

@ -6048,9 +6048,16 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) {
return;
}
controller()->sendingAnimation().appendSending(
result.messageSendingFrom);
auto action = prepareSendAction(result.options);
action.generateLocal = true;
session().api().sendInlineResult(result.bot, result.result, action);
session().api().sendInlineResult(
result.bot,
result.result,
action,
result.messageSendingFrom.localId);
clearFieldText();
_saveDraftText = true;

View File

@ -563,7 +563,10 @@ void RepliesWidget::setupComposeControls() {
_composeControls->inlineResultChosen(
) | rpl::start_with_next([=](Selector::InlineChosen chosen) {
sendInlineResult(chosen.result, chosen.bot, chosen.options);
controller()->sendingAnimation().appendSending(
chosen.messageSendingFrom);
const auto localId = chosen.messageSendingFrom.localId;
sendInlineResult(chosen.result, chosen.bot, chosen.options, localId);
}, lifetime());
_composeControls->scrollRequests(
@ -1146,7 +1149,7 @@ void RepliesWidget::sendInlineResult(
controller()->show(Box<Ui::InformBox>(errorText));
return;
}
sendInlineResult(result, bot, {});
sendInlineResult(result, bot, {}, std::nullopt);
//const auto callback = [=](Api::SendOptions options) {
// sendInlineResult(result, bot, options);
//};
@ -1158,10 +1161,11 @@ void RepliesWidget::sendInlineResult(
void RepliesWidget::sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot,
Api::SendOptions options) {
Api::SendOptions options,
std::optional<MsgId> localMessageId) {
auto action = prepareSendAction(options);
action.generateLocal = true;
session().api().sendInlineResult(bot, result, action);
session().api().sendInlineResult(bot, result, action, localMessageId);
_composeControls->clear();
//_saveDraftText = true;

View File

@ -257,7 +257,8 @@ private:
void sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot,
Api::SendOptions options);
Api::SendOptions options,
std::optional<MsgId> localMessageId);
[[nodiscard]] bool showSlowmodeError();
[[nodiscard]] std::optional<QString> writeRestriction() const;

View File

@ -752,7 +752,7 @@ void ScheduledWidget::sendInlineResult(
Api::SendOptions options) {
auto action = prepareSendAction(options);
action.generateLocal = true;
session().api().sendInlineResult(bot, result, action);
session().api().sendInlineResult(bot, result, action, std::nullopt);
_composeControls->clear();
//_saveDraftText = true;

View File

@ -465,6 +465,20 @@ void Sticker::unloadHeavyPart() {
_webm = nullptr;
}
QRect Sticker::innerContentRect() const {
ensureDataMediaCreated(getShownDocument());
const auto size = (_lottie && _lottie->ready())
? (_lottie->frame().size() / style::DevicePixelRatio())
: (!_thumb.isNull())
? (_thumb.size() / style::DevicePixelRatio())
: getThumbSize();
const auto pos = QPoint(
(st::stickerPanSize.width() - size.width()) / 2,
(st::stickerPanSize.height() - size.height()) / 2);
return QRect(pos, size);
}
void Sticker::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
ensureDataMediaCreated(getShownDocument());

View File

@ -201,6 +201,8 @@ public:
void unloadHeavyPart() override;
QRect innerContentRect() const override;
private:
void ensureDataMediaCreated(not_null<DocumentData*> document) const;
void setupLottie() const;

View File

@ -109,6 +109,11 @@ public:
update();
}
virtual QRect innerContentRect() const {
// Only stickers are supported for now.
Unexpected("Unsupported type to get a rect of inner content.");
}
static std::unique_ptr<ItemBase> createLayout(
not_null<Context*> context,
not_null<Result*> result,

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_cloud_file.h"
#include "api/api_common.h"
#include "media/view/media_view_open_common.h"
#include "ui/effects/message_sending_animation_common.h"
class FileLoader;
class History;
@ -132,6 +133,7 @@ struct ResultSelected {
not_null<Result*> result;
not_null<UserData*> bot;
Api::SendOptions options;
Ui::MessageSendingAnimationFrom messageSendingFrom;
// Open in OverlayWidget;
bool open = false;
};

View File

@ -11,10 +11,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/gifs_list_widget.h" // ChatHelpers::AddGifAction
#include "chat_helpers/send_context_menu.h" // SendMenu::FillSendMenu
#include "core/click_handler_types.h"
#include "data/data_document.h"
#include "data/data_file_origin.h"
#include "data/data_user.h"
#include "data/data_changes.h"
#include "data/data_chat_participant_status.h"
#include "data/data_session.h"
#include "inline_bots/inline_bot_result.h"
#include "inline_bots/inline_bot_layout_item.h"
#include "lang/lang_keys.h"
@ -264,6 +266,20 @@ void Inner::selectInlineResult(
if (!item) {
return;
}
const auto messageSendingFrom = [&]() -> Ui::MessageSendingAnimationFrom {
const auto document = item->getDocument()
? item->getDocument()
: item->getPreviewDocument();
if (options.scheduled || !document || !document->sticker()) {
return {};
}
const auto rect = item->innerContentRect().translated(
_mosaic.findRect(index).topLeft());
return {
.localId = _controller->session().data().nextLocalMessageId(),
.globalStartGeometry = mapToGlobal(rect),
};
};
if (const auto inlineResult = item->getResult()) {
if (inlineResult->onChoose(item)) {
@ -271,6 +287,7 @@ void Inner::selectInlineResult(
.result = inlineResult,
.bot = _inlineBot,
.options = std::move(options),
.messageSendingFrom = messageSendingFrom(),
.open = open,
});
}