From ea30e2fc0b4fc538455953556691364543f67437 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 17 May 2026 14:00:31 +0300 Subject: [PATCH] Added ability to open personal channel and "view channel" in window. --- .../info/profile/info_profile_actions.cpp | 84 +++++++++++++++++-- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 1ab55ad2df..d80b631b96 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/call_delayed.h" #include "base/event_filter.h" #include "base/options.h" +#include "base/qt/qt_key_modifiers.h" #include "base/timer_rpl.h" #include "base/unixtime.h" #include "boxes/peers/add_bot_to_chat_box.h" @@ -97,6 +98,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "window/window_controller.h" // Window::Controller::show. #include "window/window_peer_menu.h" +#include "window/window_separate_id.h" #include "window/window_session_controller.h" #include "styles/style_boxes.h" #include "styles/style_channel_earn.h" // st::channelEarnCurrencyCommonMargins @@ -1026,7 +1028,7 @@ auto AddActionButton( }; template -[[nodiscard]] auto AddMainButton( +auto AddMainButton( not_null parent, Text &&text, ToggleOn &&toggleOn, @@ -1045,6 +1047,7 @@ template if (buttonTracker) { buttonTracker->track(button); } + return button->entity(); } rpl::producer AddCurrencyAction( @@ -2120,11 +2123,47 @@ object_ptr DetailsFiller::setupPersonalChannel( ) | rpl::on_next([=](const QRect &rect) { button->setGeometry(rect); }, button->lifetime()); - button->setClickedCallback([=, msg = item->fullId().msg] { + const auto channelPeer = item->history()->peer; + const auto msg = item->fullId().msg; + const auto openInWindow = [=] { + window->showInNewWindow( + Window::SeparateId(channelPeer), + msg); + }; + const auto openInCurrent = [=] { window->showPeerHistory( - item->history()->peer, + channelPeer, Window::SectionShow::Way::Forward, msg); + }; + button->setAcceptBoth(); + struct State { + base::unique_qptr menu; + }; + const auto state + = button->lifetime().make_state(); + button->addClickHandler([=](Qt::MouseButton mouse) { + if (mouse == Qt::RightButton) { + state->menu = base::make_unique_q( + button, + st::popupMenuWithIcons); + state->menu->addAction( + tr::lng_context_new_window(tr::now), + [=] { + base::call_delayed( + st::popupMenuWithIcons.showDuration, + crl::guard(button, openInWindow)); + }, + &st::menuIconNewWindow); + state->menu->popup(QCursor::pos()); + return; + } + if (base::IsCtrlPressed() + || mouse == Qt::MiddleButton) { + openInWindow(); + } else { + openInCurrent(); + } }); button->lower(); inner->lifetime().make_state>( @@ -2380,19 +2419,54 @@ void DetailsFiller::addViewChannelButton( _controller->wrapValue(), std::move(activePeerValue), (_1 != Wrap::Side) || (_2 != channel)); - auto viewChannel = [=] { + const auto openInWindow = [=] { + window->showInNewWindow(Window::SeparateId(channel)); + }; + const auto openInCurrent = [=] { window->showPeerHistory( channel, Window::SectionShow::Way::Forward); }; + struct State { + base::unique_qptr menu; + }; + const auto state = wrap->lifetime().make_state(); + auto viewChannel = [=](Qt::MouseButton mouse) { + if (mouse == Qt::RightButton) { + return; + } + if (base::IsCtrlPressed() || mouse == Qt::MiddleButton) { + openInWindow(); + } else { + openInCurrent(); + } + }; wrap->toggleOn(rpl::duplicate(viewChannelVisible)); - AddMainButton( + const auto button = AddMainButton( wrap->entity(), tr::lng_profile_view_channel(), std::move(viewChannelVisible), std::move(viewChannel), tracker, buttonTracker); + button->setAcceptBoth(); + button->addClickHandler([=](Qt::MouseButton mouse) { + if (mouse != Qt::RightButton) { + return; + } + state->menu = base::make_unique_q( + button, + st::popupMenuWithIcons); + state->menu->addAction( + tr::lng_context_new_window(tr::now), + [=] { + base::call_delayed( + st::popupMenuWithIcons.showDuration, + crl::guard(button, openInWindow)); + }, + &st::menuIconNewWindow); + state->menu->popup(QCursor::pos()); + }); } void DetailsFiller::addShowTopicsListButton(