From 1648c31a222f6574f74862358a21926bd00690df Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 3 Sep 2024 17:16:51 +0300 Subject: [PATCH] Moved out swipe-to-reply setup to inner method in HistoryInner. --- .../history/history_inner_widget.cpp | 120 +++++++++--------- .../history/history_inner_widget.h | 1 + 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 7f35315b81..e3662fc164 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -383,64 +383,6 @@ HistoryInner::HistoryInner( _migrated->delegateMixin()->setCurrent(this); _migrated->translateTo(_history->translatedTo()); } - HistoryView::SetupSwipeHandler(this, _scroll, [=, history = _history]( - HistoryView::ChatPaintGestureHorizontalData data) { - _gestureHorizontal = data; - const auto item = history->peer->owner().message( - history->peer->id, - MsgId{ data.msgBareId }); - if (item) { - repaintItem(item); - } - }, [=, show = controller->uiShow()](int cursorTop) { - auto result = HistoryView::SwipeHandlerFinishData(); - if (inSelectionMode()) { - return result; - } - enumerateItems([&]( - not_null view, - int itemtop, - int itembottom) { - if ((cursorTop < itemtop) - || (cursorTop > itembottom) - || !view->data()->isRegular() - || view->data()->isService()) { - return true; - } - const auto item = view->data(); - const auto canSendReply = CanSendReply(item); - const auto canReply = (canSendReply || item->allowsForward()); - if (!canReply) { - return true; - } - result.msgBareId = item->fullId().msg.bare; - result.callback = [=, itemId = item->fullId()] { - const auto still = show->session().data().message(itemId); - const auto selected = selectedQuote(still); - const auto replyToItemId = (selected.item - ? selected.item - : still)->fullId(); - if (canSendReply) { - _widget->replyToMessage({ - .messageId = replyToItemId, - .quote = selected.text, - .quoteOffset = selected.offset, - }); - if (!selected.text.empty()) { - _widget->clearSelected(); - } - } else { - HistoryView::Controls::ShowReplyToChatBox(show, { - .messageId = replyToItemId, - .quote = selected.text, - .quoteOffset = selected.offset, - }); - } - }; - return false; - }); - return result; - }); Window::ChatThemeValueFromPeer( controller, @@ -553,6 +495,7 @@ HistoryInner::HistoryInner( }, _scroll->lifetime()); setupSharingDisallowed(); + setupSwipeReply(); } void HistoryInner::reactionChosen(const ChosenReaction &reaction) { @@ -635,6 +578,67 @@ void HistoryInner::setupSharingDisallowed() { }, lifetime()); } +void HistoryInner::setupSwipeReply() { + HistoryView::SetupSwipeHandler(this, _scroll, [=, history = _history]( + HistoryView::ChatPaintGestureHorizontalData data) { + _gestureHorizontal = data; + const auto item = history->peer->owner().message( + history->peer->id, + MsgId{ data.msgBareId }); + if (item) { + repaintItem(item); + } + }, [=, show = _controller->uiShow()](int cursorTop) { + auto result = HistoryView::SwipeHandlerFinishData(); + if (inSelectionMode()) { + return result; + } + enumerateItems([&]( + not_null view, + int itemtop, + int itembottom) { + if ((cursorTop < itemtop) + || (cursorTop > itembottom) + || !view->data()->isRegular() + || view->data()->isService()) { + return true; + } + const auto item = view->data(); + const auto canSendReply = CanSendReply(item); + const auto canReply = (canSendReply || item->allowsForward()); + if (!canReply) { + return true; + } + result.msgBareId = item->fullId().msg.bare; + result.callback = [=, itemId = item->fullId()] { + const auto still = show->session().data().message(itemId); + const auto selected = selectedQuote(still); + const auto replyToItemId = (selected.item + ? selected.item + : still)->fullId(); + if (canSendReply) { + _widget->replyToMessage({ + .messageId = replyToItemId, + .quote = selected.text, + .quoteOffset = selected.offset, + }); + if (!selected.text.empty()) { + _widget->clearSelected(); + } + } else { + HistoryView::Controls::ShowReplyToChatBox(show, { + .messageId = replyToItemId, + .quote = selected.text, + .quoteOffset = selected.offset, + }); + } + }; + return false; + }); + return result; + }); +} + bool HistoryInner::hasSelectRestriction() const { if (!_sharingDisallowed.current()) { return false; diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 2507a09214..f4338a3ce0 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -420,6 +420,7 @@ private: void reactionChosen(const ChosenReaction &reaction); void setupSharingDisallowed(); + void setupSwipeReply(); [[nodiscard]] bool hasCopyRestriction(HistoryItem *item = nullptr) const; [[nodiscard]] bool hasCopyMediaRestriction( not_null item) const;