From ccb41f778e04fe148e3868a014949e8e1d901f7f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 9 Nov 2024 15:18:29 +0300 Subject: [PATCH] Removed selection marks from unselectable messages. --- .../history/admin_log/history_admin_log_inner.cpp | 3 ++- .../SourceFiles/history/admin_log/history_admin_log_inner.h | 3 ++- Telegram/SourceFiles/history/history_inner_widget.cpp | 6 +++++- Telegram/SourceFiles/history/view/history_view_element.cpp | 3 ++- Telegram/SourceFiles/history/view/history_view_element.h | 5 +++-- .../SourceFiles/history/view/history_view_list_widget.cpp | 6 +++++- .../SourceFiles/history/view/history_view_list_widget.h | 2 +- Telegram/SourceFiles/history/view/history_view_message.cpp | 6 +++--- .../history/view/history_view_replies_section.cpp | 2 +- 9 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index b37da32c1..a7ea96d4c 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -666,7 +666,8 @@ bool InnerWidget::elementUnderCursor( return (Element::Hovered() == view); } -HistoryView::SelectionModeResult InnerWidget::elementInSelectionMode() { +HistoryView::SelectionModeResult InnerWidget::elementInSelectionMode( + const HistoryView::Element *) { return {}; } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index bdf9c0491..209cc0384 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -94,7 +94,8 @@ public: HistoryView::Context elementContext() override; bool elementUnderCursor( not_null view) override; - HistoryView::SelectionModeResult elementInSelectionMode() override; + HistoryView::SelectionModeResult elementInSelectionMode( + const HistoryView::Element *view) override; bool elementIntersectsRange( not_null view, int from, diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 9ccd9feb2..41e33a6b0 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -155,7 +155,11 @@ public: not_null view) override { return (Element::Moused() == view); } - HistoryView::SelectionModeResult elementInSelectionMode() override { + HistoryView::SelectionModeResult elementInSelectionMode( + const Element *view) override { + if (view && view->data()->isSponsored()) { + return HistoryView::SelectionModeResult(); + } return _widget ? _widget->inSelectionMode() : HistoryView::SelectionModeResult(); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 95d5e7a29..3b6dde0c8 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -111,7 +111,8 @@ bool DefaultElementDelegate::elementUnderCursor( return false; } -SelectionModeResult DefaultElementDelegate::elementInSelectionMode() { +SelectionModeResult DefaultElementDelegate::elementInSelectionMode( + const Element *view) { return {}; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index be41e07dc..e8a5a1c53 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -80,7 +80,8 @@ class ElementDelegate { public: virtual Context elementContext() = 0; virtual bool elementUnderCursor(not_null view) = 0; - virtual SelectionModeResult elementInSelectionMode() = 0; + virtual SelectionModeResult elementInSelectionMode( + const Element *view) = 0; virtual bool elementIntersectsRange( not_null view, int from, @@ -136,7 +137,7 @@ public: class DefaultElementDelegate : public ElementDelegate { public: bool elementUnderCursor(not_null view) override; - SelectionModeResult elementInSelectionMode() override; + SelectionModeResult elementInSelectionMode(const Element *view) override; bool elementIntersectsRange( not_null view, int from, diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index ca1e16327..68a28f1f8 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1782,7 +1782,11 @@ bool ListWidget::elementUnderCursor( return (_overElement == view); } -SelectionModeResult ListWidget::elementInSelectionMode() { +SelectionModeResult ListWidget::elementInSelectionMode( + const HistoryView::Element *view) { + if (view && !_delegate->listIsItemGoodForSelection(view->data())) { + return {}; + } return inSelectionMode(); } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 8fa1b1f52..056d6ce95 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -391,7 +391,7 @@ public: // ElementDelegate interface. Context elementContext() override; bool elementUnderCursor(not_null view) override; - SelectionModeResult elementInSelectionMode() override; + SelectionModeResult elementInSelectionMode(const Element *view) override; bool elementIntersectsRange( not_null view, int from, diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 3a84ee927..0dae7fbf0 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1100,7 +1100,7 @@ void Message::draw(Painter &p, const PaintContext &context) const { if (hasGesture) { p.translate(context.gestureHorizontal.translation, 0); } - const auto selectionModeResult = delegate()->elementInSelectionMode(); + const auto selectionModeResult = delegate()->elementInSelectionMode(this); const auto selectionTranslation = (selectionModeResult.progress > 0) ? (selectionModeResult.progress * AdditionalSpaceForSelectionCheckbox(this, g)) @@ -3868,7 +3868,7 @@ bool Message::displayFastReply() const { return hasFastReply() && data()->isRegular() && canSendAnything() - && !delegate()->elementInSelectionMode().inSelectionMode; + && !delegate()->elementInSelectionMode(this).inSelectionMode; } bool Message::displayRightActionComments() const { @@ -4032,7 +4032,7 @@ void Message::drawRightAction( ClickHandlerPtr Message::rightActionLink( std::optional pressPoint) const { - if (delegate()->elementInSelectionMode().progress > 0) { + if (delegate()->elementInSelectionMode(this).progress > 0) { return nullptr; } ensureRightAction(); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 107e4bf7f..081d01f44 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -898,7 +898,7 @@ void RepliesWidget::setupSwipeReply() { } }, [=, show = controller()->uiShow()](int cursorTop) { auto result = HistoryView::SwipeHandlerFinishData(); - if (_inner->elementInSelectionMode().inSelectionMode) { + if (_inner->elementInSelectionMode(nullptr).inSelectionMode) { return result; } const auto view = _inner->lookupItemByY(cursorTop);