Added simple animation of static stickers sending to replies section.

This commit is contained in:
23rd 2022-02-10 23:08:46 +03:00 committed by John Preston
parent e72be4abfc
commit 40875ac8ff
4 changed files with 50 additions and 10 deletions

View file

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/toast/toast.h"
#include "ui/toasts/common_toasts.h"
#include "ui/inactive_press.h"
#include "ui/effects/message_sending_animation_controller.h"
#include "ui/effects/path_shift_gradient.h"
#include "ui/chat/chat_theme.h"
#include "ui/chat/chat_style.h"
@ -1555,6 +1556,7 @@ void ListWidget::resizeToWidth(int newWidth, int minHeight) {
void ListWidget::startItemRevealAnimations() {
for (const auto &view : base::take(_itemRevealPending)) {
if (const auto height = view->height()) {
startMessageSendingAnimation(view->data());
if (!_itemRevealAnimations.contains(view)) {
auto &animation = _itemRevealAnimations[view];
animation.startHeight = height;
@ -1573,6 +1575,30 @@ void ListWidget::startItemRevealAnimations() {
}
}
void ListWidget::startMessageSendingAnimation(
not_null<HistoryItem*> item) {
auto &sendingAnimation = controller()->sendingAnimation();
if (!sendingAnimation.hasLocalMessage(item->fullId().msg)) {
return;
}
auto globalEndGeometry = rpl::merge(
session().data().newItemAdded() | rpl::to_empty,
geometryValue() | rpl::to_empty
) | rpl::map([=] {
const auto view = viewForItem(item);
const auto additional = !_visibleTop ? view->height() : 0;
return mapToGlobal(
view->innerGeometry().translated(0, itemTop(view) - additional));
});
sendingAnimation.startAnimation({
.globalEndGeometry = std::move(globalEndGeometry),
.view = [=] { return viewForItem(item); },
.theme = _delegate->listChatTheme(),
});
}
void ListWidget::revealItemsCallback() {
auto revealHeight = 0;
for (auto i = begin(_itemRevealAnimations)
@ -1744,13 +1770,16 @@ void ListWidget::paintEvent(QPaintEvent *e) {
.clip = clip,
}).translated(0, -top);
p.translate(0, top);
const auto &sendingAnimation = _controller->sendingAnimation();
for (auto i = from; i != to; ++i) {
const auto view = *i;
context.reactionInfo
= _reactionsManager->currentReactionPaintInfo();
context.outbg = view->hasOutLayout();
context.selection = itemRenderSelection(view);
view->draw(p, context);
if (!sendingAnimation.hasAnimatedMessage(view->data())) {
context.reactionInfo
= _reactionsManager->currentReactionPaintInfo();
context.outbg = view->hasOutLayout();
context.selection = itemRenderSelection(view);
view->draw(p, context);
}
_reactionsManager->recordCurrentReactionEffect(
view->data()->fullId(),
QPoint(0, top));

View file

@ -504,6 +504,8 @@ private:
void startItemRevealAnimations();
void revealItemsCallback();
void startMessageSendingAnimation(not_null<HistoryItem*> item);
void updateHighlightedMessage();
void clearHighlightedMessage();

View file

@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_utilities.h"
#include "ui/chat/attach/attach_prepare.h"
#include "ui/chat/attach/attach_send_files_way.h"
#include "ui/effects/message_sending_animation_controller.h"
#include "ui/special_buttons.h"
#include "ui/ui_utility.h"
#include "ui/toasts/common_toasts.h"
@ -546,7 +547,12 @@ void RepliesWidget::setupComposeControls() {
_composeControls->fileChosen(
) | rpl::start_with_next([=](Selector::FileChosen chosen) {
sendExistingDocument(chosen.document, chosen.options);
controller()->sendingAnimation().appendSending(
chosen.messageSendingFrom);
sendExistingDocument(
chosen.document,
chosen.options,
chosen.messageSendingFrom.localId);
}, lifetime());
_composeControls->photoChosen(
@ -1060,7 +1066,7 @@ void RepliesWidget::edit(
void RepliesWidget::sendExistingDocument(
not_null<DocumentData*> document) {
sendExistingDocument(document, {});
sendExistingDocument(document, {}, std::nullopt);
// #TODO replies schedule
//const auto callback = [=](Api::SendOptions options) {
// sendExistingDocument(document, options);
@ -1072,7 +1078,8 @@ void RepliesWidget::sendExistingDocument(
bool RepliesWidget::sendExistingDocument(
not_null<DocumentData*> document,
Api::SendOptions options) {
Api::SendOptions options,
std::optional<MsgId> localId) {
const auto error = Data::RestrictionError(
_history->peer,
ChatRestriction::SendStickers);
@ -1087,7 +1094,8 @@ bool RepliesWidget::sendExistingDocument(
Api::SendExistingDocument(
Api::MessageToSend(prepareSendAction(options)),
document);
document,
localId);
_composeControls->cancelReplyMessage();
finishSending();

View file

@ -245,7 +245,8 @@ private:
void sendExistingDocument(not_null<DocumentData*> document);
bool sendExistingDocument(
not_null<DocumentData*> document,
Api::SendOptions options);
Api::SendOptions options,
std::optional<MsgId> localId);
void sendExistingPhoto(not_null<PhotoData*> photo);
bool sendExistingPhoto(
not_null<PhotoData*> photo,