From 71e3cd227c9cabb3b87f4c9a8a233c0b5fddc08c Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 3 Sep 2024 18:04:55 +0300 Subject: [PATCH] Added initial swipe-to-reply to section for replies. --- .../history/view/history_view_list_widget.cpp | 8 +++ .../view/history_view_replies_section.cpp | 66 +++++++++++++++++++ .../view/history_view_replies_section.h | 6 ++ 3 files changed, 80 insertions(+) diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index a07fcfd5b..4031a4f36 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2305,6 +2305,11 @@ void ListWidget::paintUserpics( // paint the userpic if it intersects the painted rect if (userpicTop + st::msgPhotoSize > clip.top()) { const auto item = view->data(); + const auto hasTranslation = context.gestureHorizontal.ratio + && (context.gestureHorizontal.msgBareId == item->fullId().msg.bare); + if (hasTranslation) { + p.translate(context.gestureHorizontal.translation, 0); + } if (const auto from = item->displayFrom()) { from->paintUserpicLeft( p, @@ -2337,6 +2342,9 @@ void ListWidget::paintUserpics( } else { Unexpected("Corrupt forwarded information in message."); } + if (hasTranslation) { + p.translate(-context.gestureHorizontal.translation, 0); + } } return true; }); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 07465b5b3..baf644137 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_drag_area.h" #include "history/history_item_components.h" #include "history/history_item_helpers.h" // GetErrorTextForSending. +#include "history/history_view_swipe.h" #include "ui/chat/pinned_bar.h" #include "ui/chat/chat_style.h" #include "ui/widgets/buttons.h" @@ -399,6 +400,7 @@ RepliesWidget::RepliesWidget( setupTopicViewer(); setupComposeControls(); + setupSwipeReply(); orderWidgets(); if (_pinnedBar) { @@ -865,6 +867,62 @@ void RepliesWidget::setupComposeControls() { } } +void RepliesWidget::setupSwipeReply() { + const auto can = [=](not_null still) { + const auto canSendReply = _topic + ? Data::CanSendAnything(_topic) + : Data::CanSendAnything(_history->peer); + const auto allowInAnotherChat = still && still->allowsForward(); + if (allowInAnotherChat && (_joinGroup || !canSendReply)) { + return true; + } else if (!_joinGroup && canSendReply) { + return true; + } + return false; + }; + HistoryView::SetupSwipeHandler(_inner, _scroll.get(), [=]( + HistoryView::ChatPaintGestureHorizontalData data) { + _gestureHorizontal = data; + const auto item = _history->peer->owner().message( + _history->peer->id, + MsgId{ data.msgBareId }); + if (item) { + _inner->update(); + // repaintItem(item); + } + }, [=, show = controller()->uiShow()](int cursorTop) { + auto result = HistoryView::SwipeHandlerFinishData(); + if (_inner->elementInSelectionMode()) { + return result; + } + const auto view = _inner->lookupItemByY(cursorTop); + if (!view->data()->isRegular() + || view->data()->isService()) { + return result; + } + if (!can(view->data())) { + return result; + } + + result.msgBareId = view->data()->fullId().msg.bare; + result.callback = [=, itemId = view->data()->fullId()] { + const auto still = show->session().data().message(itemId); + const auto view = _inner->viewByPosition(still->position()); + const auto selected = view->selectedQuote( + _inner->getSelectedTextRange(still)); + const auto replyToItemId = (selected.item + ? selected.item + : still)->fullId(); + _inner->replyToMessageRequestNotify({ + .messageId = replyToItemId, + .quote = selected.text, + .quoteOffset = selected.offset, + }); + }; + return result; + }); +} + void RepliesWidget::chooseAttach( std::optional overrideSendImagesAsPhotos) { _choosingAttach = false; @@ -2631,6 +2689,14 @@ void RepliesWidget::listAddTranslatedItems( } } +Ui::ChatPaintContext RepliesWidget::listPreparePaintContext( + Ui::ChatPaintContextArgs &&args) { + auto context = WindowListDelegate::listPreparePaintContext( + std::move(args)); + context.gestureHorizontal = _gestureHorizontal; + return context; +} + void RepliesWidget::setupEmptyPainter() { Expects(_topic != nullptr); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index be572f4ca..71321f14c 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/section_memento.h" #include "history/view/history_view_corner_buttons.h" #include "history/view/history_view_list_widget.h" +#include "history/history_view_swipe_data.h" #include "data/data_messages.h" #include "base/timer.h" @@ -180,6 +181,8 @@ public: History *listTranslateHistory() override; void listAddTranslatedItems( not_null tracker) override; + Ui::ChatPaintContext listPreparePaintContext( + Ui::ChatPaintContextArgs &&args) override; // CornerButtonsDelegate delegate. void cornerButtonsShowAtPosition( @@ -221,6 +224,7 @@ private: void finishSending(); void setupComposeControls(); + void setupSwipeReply(); void setupRoot(); void setupRootView(); @@ -369,6 +373,8 @@ private: HistoryView::CornerButtons _cornerButtons; rpl::lifetime _topicLifetime; + HistoryView::ChatPaintGestureHorizontalData _gestureHorizontal; + int _lastScrollTop = 0; int _topicReopenBarHeight = 0; int _scrollTopDelta = 0;