diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index fd3661625..a1c2f73fa 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1323,10 +1323,8 @@ void HistoryInner::mouseActionFinish( && inSelectionMode() && button != Qt::RightButton) { if (const auto view = _mouseActionItem->mainView()) { - if (const auto media = view->media()) { - if (media->toggleSelectionByHandlerClick(activated)) { - activated = nullptr; - } + if (view->toggleSelectionByHandlerClick(activated)) { + activated = nullptr; } } } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 9574b6696..b35e0880d 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1753,9 +1753,6 @@ void HistoryWidget::showHistory( if (startBot) { showAtMsgId = ShowAtTheEndMsgId; } - if (showAtMsgId != ShowForChooseMessagesMsgId) { - _chooseForReport = nullptr; - } clearHighlightMessages(); hideInfoTooltip(anim::type::instant); @@ -1768,6 +1765,7 @@ void HistoryWidget::showHistory( showAtMsgId = ShowAtTheEndMsgId; } else if (showAtMsgId == ShowForChooseMessagesMsgId) { if (_chooseForReport) { + clearSelected(); _chooseForReport->active = true; _list->setChooseReportReason(_chooseForReport->reason); updateControlsVisibility(); @@ -1776,7 +1774,6 @@ void HistoryWidget::showHistory( } return; } - _list->clearChooseReportReason(); if (!IsServerMsgId(showAtMsgId) && !IsServerMsgId(-showAtMsgId)) { // To end or to unread. @@ -1939,14 +1936,16 @@ void HistoryWidget::showHistory( } _history->setFakeUnreadWhileOpened(true); - refreshTopBarActiveChat(); - updateTopBarSelection(); - if (showAtMsgId == ShowForChooseMessagesMsgId) { - showAtMsgId = ShowAtUnreadMsgId; + if (_showAtMsgId == ShowForChooseMessagesMsgId) { + _showAtMsgId = ShowAtUnreadMsgId; if (_chooseForReport) { _chooseForReport->active = true; } + } else { + _chooseForReport = nullptr; } + refreshTopBarActiveChat(); + updateTopBarSelection(); if (_channel) { updateNotifyControls(); @@ -2034,6 +2033,7 @@ void HistoryWidget::showHistory( unreadCountUpdated(); // set _historyDown badge. showAboutTopPromotion(); } else { + _chooseForReport = nullptr; refreshTopBarActiveChat(); updateTopBarSelection(); checkMessagesTTL(); @@ -3325,9 +3325,13 @@ void HistoryWidget::reportSelectedMessages() { const auto peer = _peer; const auto reason = _chooseForReport->reason; const auto box = std::make_shared>(); + const auto weak = Ui::MakeWeak(_list.data()); const auto send = [=](const QString &text) { + if (weak) { + clearSelected(); + controller()->clearChooseReportMessages(); + } HistoryView::SendReport(peer, reason, text, ids); - controller()->clearChooseReportMessages(); if (*box) { (*box)->closeBox(); } @@ -5514,6 +5518,7 @@ void HistoryWidget::setChooseReportMessagesDetails( _list->clearChooseReportReason(); } if (refresh) { + clearSelected(); updateControlsVisibility(); updateControlsGeometry(); updateTopBarChooseForReport(); @@ -6260,7 +6265,9 @@ void HistoryWidget::confirmDeleteSelected() { } void HistoryWidget::escape() { - if (_nonEmptySelection && _list) { + if (_chooseForReport) { + controller()->clearChooseReportMessages(); + } else if (_nonEmptySelection && _list) { clearSelected(); } else if (_isInlineBot) { cancelInlineBot(); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 3d4d0303f..c84818a53 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -736,6 +736,11 @@ HistoryMessageReply *Element::displayedReply() const { return nullptr; } +bool Element::toggleSelectionByHandlerClick( + const ClickHandlerPtr &handler) const { + return false; +} + bool Element::hasVisibleText() const { return false; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 54b4b4ad4..a9b414875 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -292,6 +292,8 @@ public: virtual void applyGroupAdminChanges( const base::flat_set &changes) { } + [[nodiscard]] virtual bool toggleSelectionByHandlerClick( + const ClickHandlerPtr &handler) const; struct VerticalRepaintRange { int top = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 08c77e2ae..d8d8c8e2b 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2184,16 +2184,10 @@ void ListWidget::mouseActionFinish( repaintItem(pressState.itemId); const auto toggleByHandler = [&](const ClickHandlerPtr &handler) { - if (_overElement) { - // If we are in selecting items mode perhaps we want to - // toggle selection instead of activating the pressed link. - if (const auto media = _overElement->media()) { - if (media->toggleSelectionByHandlerClick(handler)) { - return true; - } - } - } - return false; + // If we are in selecting items mode perhaps we want to + // toggle selection instead of activating the pressed link. + return _overElement + && _overElement->toggleSelectionByHandlerClick(handler); }; auto activated = ClickHandler::unpressed(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index ea03bb705..687deade6 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -2059,6 +2059,18 @@ HistoryMessageReply *Message::displayedReply() const { return nullptr; } +bool Message::toggleSelectionByHandlerClick( + const ClickHandlerPtr &handler) const { + if (_comments && _comments->link == handler) { + return true; + } else if (const auto media = this->media()) { + if (media->toggleSelectionByHandlerClick(handler)) { + return true; + } + } + return false; +} + bool Message::displayPinIcon() const { return data()->isPinned() && !isPinnedContext(); } diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 132c3420f..0d61e61d7 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -105,6 +105,8 @@ public: bool displayEditedBadge() const override; TimeId displayedEditDate() const override; HistoryMessageReply *displayedReply() const override; + bool toggleSelectionByHandlerClick( + const ClickHandlerPtr &handler) const override; int infoWidth() const override; VerticalRepaintRange verticalRepaintRange() const override; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 0798670d5..d4dc84d4b 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1419,7 +1419,10 @@ void MainWidget::showChooseReportMessages( Ui::ReportReason reason, Fn done) { _history->setChooseReportMessagesDetails(reason, std::move(done)); - ui_showPeerHistory(peer->id, SectionShow(), ShowForChooseMessagesMsgId); + ui_showPeerHistory( + peer->id, + SectionShow::Way::Forward, + ShowForChooseMessagesMsgId); } void MainWidget::clearChooseReportMessages() { diff --git a/Telegram/SourceFiles/ui/boxes/report_box.cpp b/Telegram/SourceFiles/ui/boxes/report_box.cpp index 539d6a97d..32f2dec74 100644 --- a/Telegram/SourceFiles/ui/boxes/report_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/report_box.cpp @@ -42,7 +42,7 @@ void ReportReasonBox( const auto add = [&](Reason reason, tr::phrase<> text) { const auto layout = box->verticalLayout(); const auto button = layout->add( - object_ptr(layout, text())); + object_ptr(layout, text())); button->setClickedCallback([=] { done(reason); }); @@ -63,7 +63,7 @@ void ReportDetailsBox( not_null box, Fn done) { box->addRow( - object_ptr( + object_ptr( box, // #TODO reports tr::lng_report_details_about(), st::boxLabel), @@ -73,20 +73,23 @@ void ReportDetailsBox( st::boxRowPadding.right(), st::boxPadding.bottom() }); const auto details = box->addRow( - object_ptr( + object_ptr( box, st::newGroupDescription, - Ui::InputField::Mode::MultiLine, + InputField::Mode::MultiLine, tr::lng_report_details(), QString())); details->setMaxLength(kReportReasonLengthMax); box->setFocusCallback([=] { details->setFocusFast(); }); - box->addButton(tr::lng_report_button(), [=] { + + const auto submit = [=] { const auto text = details->getLastText(); done(text); - }); + }; + QObject::connect(details, &InputField::submitted, submit); + box->addButton(tr::lng_report_button(), submit); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }