diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 9344d3486d..48d58322b9 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -269,10 +269,6 @@ void showChatsList(not_null session) { } } -void showPeerHistoryAtItem(not_null item) { - showPeerHistory(item->history()->peer, item->id); -} - void showPeerHistory(not_null history, MsgId msgId) { showPeerHistory(history->peer, msgId); } diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index e100343e42..b3f53c72a6 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -58,7 +58,6 @@ namespace Ui { void showPeerProfile(not_null peer); void showPeerProfile(not_null history); -void showPeerHistoryAtItem(not_null item); void showPeerHistory(not_null peer, MsgId msgId); void showPeerHistory(not_null history, MsgId msgId); void showChatsList(not_null session); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 920429a3e7..41ac9269b3 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -5263,14 +5263,14 @@ bool HistoryWidget::replyToPreviousMessage() { if (const auto view = item->mainView()) { if (const auto previousView = view->previousDisplayedInBlocks()) { const auto previous = previousView->data(); - Ui::showPeerHistoryAtItem(previous); + controller()->showPeerHistoryAtItem(previous); replyToMessage(previous); return true; } } } else if (const auto previousView = _history->findLastDisplayed()) { const auto previous = previousView->data(); - Ui::showPeerHistoryAtItem(previous); + controller()->showPeerHistoryAtItem(previous); replyToMessage(previous); return true; } @@ -5288,7 +5288,7 @@ bool HistoryWidget::replyToNextMessage() { if (const auto view = item->mainView()) { if (const auto nextView = view->nextDisplayedInBlocks()) { const auto next = nextView->data(); - Ui::showPeerHistoryAtItem(next); + controller()->showPeerHistoryAtItem(next); replyToMessage(next); } else { clearHighlightMessages(); diff --git a/Telegram/SourceFiles/info/info_layer_widget.cpp b/Telegram/SourceFiles/info/info_layer_widget.cpp index 750e30856c..4c2178a2ae 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.cpp +++ b/Telegram/SourceFiles/info/info_layer_widget.cpp @@ -73,6 +73,11 @@ bool LayerWidget::floatPlayerIsVisible(not_null item) { return false; } +void LayerWidget::floatPlayerDoubleClickEvent( + not_null item) { + _controller->showPeerHistoryAtItem(item); +} + void LayerWidget::setupHeightConsumers() { Expects(_content != nullptr); diff --git a/Telegram/SourceFiles/info/info_layer_widget.h b/Telegram/SourceFiles/info/info_layer_widget.h index 79b4d247f5..4499a8d22e 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.h +++ b/Telegram/SourceFiles/info/info_layer_widget.h @@ -64,6 +64,8 @@ private: not_null<::Media::Player::FloatSectionDelegate*> widget, Window::Column widgetColumn)> callback) override; bool floatPlayerIsVisible(not_null item) override; + void floatPlayerDoubleClickEvent( + not_null item) override; void setupHeightConsumers(); diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index c46d3d5f9d..a2afe49fd3 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1445,7 +1445,7 @@ void ListWidget::showContextMenu( tr::lng_context_to_msg(tr::now), [=] { if (const auto item = owner->message(itemFullId)) { - Ui::showPeerHistoryAtItem(item); + _controller->parentController()->showPeerHistoryAtItem(item); } }); diff --git a/Telegram/SourceFiles/intro/intro_widget.cpp b/Telegram/SourceFiles/intro/intro_widget.cpp index 8b7024a965..f1e012e765 100644 --- a/Telegram/SourceFiles/intro/intro_widget.cpp +++ b/Telegram/SourceFiles/intro/intro_widget.cpp @@ -21,6 +21,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_domain.h" #include "main/main_session.h" #include "mainwindow.h" +#include "history/history.h" +#include "history/history_item.h" #include "data/data_user.h" #include "data/data_countries.h" #include "boxes/confirm_box.h" @@ -33,6 +35,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/mtproto_dc_options.h" #include "window/window_slide_animation.h" #include "window/window_connecting_widget.h" +#include "window/window_controller.h" +#include "window/window_session_controller.h" #include "window/section_widget.h" #include "base/platform/base_platform_info.h" #include "api/api_text_entities.h" @@ -186,6 +190,14 @@ bool Widget::floatPlayerIsVisible(not_null item) { return false; } +void Widget::floatPlayerDoubleClickEvent(not_null item) { + getData()->controller->invokeForSessionController( + &item->history()->peer->session().account(), + [=](not_null controller) { + controller->showPeerHistoryAtItem(item); + }); +} + QRect Widget::floatPlayerAvailableRect() { return mapToGlobal(rect()); } diff --git a/Telegram/SourceFiles/intro/intro_widget.h b/Telegram/SourceFiles/intro/intro_widget.h index 74840ea3de..5f30c22061 100644 --- a/Telegram/SourceFiles/intro/intro_widget.h +++ b/Telegram/SourceFiles/intro/intro_widget.h @@ -166,6 +166,8 @@ private: not_null widget, Window::Column widgetColumn)> callback) override; bool floatPlayerIsVisible(not_null item) override; + void floatPlayerDoubleClickEvent( + not_null item) override; // FloatSectionDelegate QRect floatPlayerAvailableRect() override; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 1d7fc40e9a..1c87159a2d 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -511,6 +511,11 @@ void MainWidget::floatPlayerClosed(FullMsgId itemId) { } } +void MainWidget::floatPlayerDoubleClickEvent( + not_null item) { + _controller->showPeerHistoryAtItem(item); +} + bool MainWidget::setForwardDraft(PeerId peerId, MessageIdsList &&items) { Expects(peerId != 0); @@ -939,6 +944,10 @@ void MainWidget::createPlayer() { [this] { playerHeightUpdated(); }, _player->lifetime()); _player->entity()->setCloseCallback([=] { closeBothPlayers(); }); + _player->entity()->setShowItemCallback([=]( + not_null item) { + _controller->showPeerHistoryAtItem(item); + }); _playerVolume.create(this, _controller); _player->entity()->volumeWidgetCreated(_playerVolume); orderWidgets(); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index bdd705aa5c..54d22a635f 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -319,6 +319,8 @@ private: Window::Column widgetColumn)> callback) override; bool floatPlayerIsVisible(not_null item) override; void floatPlayerClosed(FullMsgId itemId); + void floatPlayerDoubleClickEvent( + not_null item) override; void viewsIncrementDone( QVector ids, diff --git a/Telegram/SourceFiles/media/player/media_player_float.cpp b/Telegram/SourceFiles/media/player/media_player_float.cpp index 79de6f2420..fea2b90120 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.cpp +++ b/Telegram/SourceFiles/media/player/media_player_float.cpp @@ -35,15 +35,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Media { namespace Player { +using DoubleClickedCallback = Fn)>; + Float::Float( QWidget *parent, not_null item, Fn toggleCallback, - Fn draggedCallback) + Fn draggedCallback, + DoubleClickedCallback doubleClickedCallback) : RpWidget(parent) , _item(item) , _toggleCallback(std::move(toggleCallback)) -, _draggedCallback(std::move(draggedCallback)) { +, _draggedCallback(std::move(draggedCallback)) +, _doubleClickedCallback(std::move(doubleClickedCallback)) { auto media = _item->media(); Assert(media != nullptr); @@ -131,10 +135,10 @@ void Float::finishDrag(bool closed) { } void Float::mouseDoubleClickEvent(QMouseEvent *e) { - if (_item) { + if (_item && _doubleClickedCallback) { // Handle second click. pauseResume(); - Ui::showPeerHistoryAtItem(_item); + _doubleClickedCallback(_item); } } @@ -275,7 +279,8 @@ FloatController::Item::Item( not_null parent, not_null item, ToggleCallback toggle, - DraggedCallback dragged) + DraggedCallback dragged, + DoubleClickedCallback doubleClicked) : animationSide(RectPart::Right) , column(Window::Column::Second) , corner(RectPart::TopRight) @@ -287,7 +292,8 @@ FloatController::Item::Item( }, [=, dragged = std::move(dragged)](bool closed) { dragged(this, closed); - }) { + }, + std::move(doubleClicked)) { } FloatController::FloatController(not_null delegate) @@ -394,6 +400,9 @@ void FloatController::create(not_null item) { }, [=](not_null instance, bool closed) { finishDrag(instance, closed); + }, + [=](not_null item) { + _delegate->floatPlayerDoubleClickEvent(item); })); current()->column = Core::App().settings().floatPlayerColumn(); current()->corner = Core::App().settings().floatPlayerCorner(); diff --git a/Telegram/SourceFiles/media/player/media_player_float.h b/Telegram/SourceFiles/media/player/media_player_float.h index 731e54bb7d..9edb4af416 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.h +++ b/Telegram/SourceFiles/media/player/media_player_float.h @@ -38,7 +38,8 @@ public: QWidget *parent, not_null item, Fn toggleCallback, - Fn draggedCallback); + Fn draggedCallback, + Fn)> doubleClickedCallback); [[nodiscard]] HistoryItem *item() const { return _item; @@ -101,6 +102,7 @@ private: bool _drag = false; QPoint _dragLocalPoint; Fn _draggedCallback; + Fn)> _doubleClickedCallback; }; @@ -138,6 +140,9 @@ public: virtual rpl::producer<> floatPlayerAreaUpdates() { return _areaUpdates.events(); } + virtual void floatPlayerDoubleClickEvent( + not_null item) { + } struct FloatPlayerFilterWheelEventRequest { not_null object; @@ -205,7 +210,8 @@ private: not_null parent, not_null item, ToggleCallback toggle, - DraggedCallback dragged); + DraggedCallback dragged, + Fn)> doubleClicked); bool hiddenByWidget = false; bool hiddenByHistory = false; diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 020ddb064d..f95653626c 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -206,6 +206,11 @@ void Widget::setCloseCallback(Fn callback) { _close->setClickedCallback([this] { stopAndClose(); }); } +void Widget::setShowItemCallback( + Fn)> callback) { + _showItemCallback = std::move(callback); +} + void Widget::stopAndClose() { _voiceIsActive = false; if (_type == AudioMsgId::Type::Voice) { @@ -311,15 +316,16 @@ void Widget::mousePressEvent(QMouseEvent *e) { void Widget::mouseReleaseEvent(QMouseEvent *e) { if (auto downLabels = base::take(_labelsDown)) { - if (_labelsOver == downLabels) { - if (_type == AudioMsgId::Type::Voice) { - const auto current = instance()->current(_type); - const auto document = current.audio(); - const auto context = current.contextId(); - if (document && context) { - if (const auto item = document->owner().message(context)) { - Ui::showPeerHistoryAtItem(item); - } + if (_labelsOver != downLabels) { + return; + } + if (_type == AudioMsgId::Type::Voice) { + const auto current = instance()->current(_type); + const auto document = current.audio(); + const auto context = current.contextId(); + if (document && context && _showItemCallback) { + if (const auto item = document->owner().message(context)) { + _showItemCallback(item); } } } diff --git a/Telegram/SourceFiles/media/player/media_player_widget.h b/Telegram/SourceFiles/media/player/media_player_widget.h index 7e5dc8b8d1..80f67cf6a9 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.h +++ b/Telegram/SourceFiles/media/player/media_player_widget.h @@ -42,6 +42,7 @@ public: Widget(QWidget *parent, not_null session); void setCloseCallback(Fn callback); + void setShowItemCallback(Fn)> callback); void stopAndClose(); void setShadowGeometryToLeft(int x, int y, int w, int h); void showShadow(); @@ -103,6 +104,7 @@ private: AudioMsgId _lastSongId; bool _voiceIsActive = false; Fn _closeCallback; + Fn)> _showItemCallback; bool _labelsOver = false; bool _labelsDown = false; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 0bd808dbd5..e181075280 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1426,12 +1426,12 @@ void OverlayWidget::subscribeToScreenGeometry() { } void OverlayWidget::toMessage() { - if (!_session) { + if (!_session || !_controller) { return; } if (const auto item = _session->data().message(_msgid)) { close(); - Ui::showPeerHistoryAtItem(item); + _controller->showPeerHistoryAtItem(item); } } diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index ec2bb50a15..dd09b1c4eb 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -333,6 +333,15 @@ void Controller::preventOrInvoke(Fn &&callback) { _widget.preventOrInvoke(std::move(callback)); } +void Controller::invokeForSessionController( + not_null account, + Fn)> &&callback) { + _account->domain().activate(std::move(account)); + if (_sessionController) { + callback(_sessionController.get()); + } +} + QPoint Controller::getPointForCallPanelCenter() const { Expects(_widget.windowHandle() != nullptr); diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 9852e61e63..bdf8ade842 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -83,6 +83,10 @@ public: void preventOrInvoke(Fn &&callback); + void invokeForSessionController( + not_null account, + Fn)> &&callback); + void openInMediaView(Media::View::OpenRequest &&request); [[nodiscard]] auto openInMediaViewRequests() const -> rpl::producer; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 32d36724a6..49d5417822 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -50,6 +50,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "mainwidget.h" #include "mainwindow.h" +#include "main/main_domain.h" #include "main/main_session.h" #include "main/main_session_settings.h" #include "apiwrap.h" @@ -1136,6 +1137,18 @@ void SessionController::showPeerHistory( msgId); } +void SessionController::showPeerHistoryAtItem( + not_null item) { + _window->invokeForSessionController( + &item->history()->peer->session().account(), + [=](not_null controller) { + controller->showPeerHistory( + item->history()->peer, + SectionShow::Way::ClearStack, + item->id); + }); +} + void SessionController::showSection( std::shared_ptr memento, const SectionShow ¶ms) { diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index d33526c7da..49fe33ddbf 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -327,6 +327,8 @@ public: const SectionShow ¶ms = SectionShow::Way::ClearStack, MsgId msgId = ShowAtUnreadMsgId) override; + void showPeerHistoryAtItem(not_null item); + void showSpecialLayer( object_ptr &&layer, anim::type animated = anim::type::normal);