diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h index b68d212e4..6bdb282f9 100644 --- a/Telegram/SourceFiles/core/click_handler_types.h +++ b/Telegram/SourceFiles/core/click_handler_types.h @@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/basic_click_handlers.h" +constexpr auto kPeerLinkPeerIdProperty = 0x01; + namespace Main { class Session; } // namespace Main diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index c8abcbb6e..a18057ca0 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -163,6 +163,7 @@ bool UpdateBotCommands( PeerClickHandler::PeerClickHandler(not_null peer) : _peer(peer) { + setProperty(kPeerLinkPeerIdProperty, peer->id.value); } void PeerClickHandler::onClick(ClickContext context) const { 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 3ecd53f4e..8b773e73c 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1156,10 +1156,11 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { : App::hoveredLinkItem(); auto lnkPhoto = dynamic_cast(link.get()); auto lnkDocument = dynamic_cast(link.get()); - auto lnkPeer = dynamic_cast(link.get()); auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideoFile() : false; auto lnkIsVoice = lnkDocument ? lnkDocument->document()->isVoiceMessage() : false; auto lnkIsAudio = lnkDocument ? lnkDocument->document()->isAudioFile() : false; + const auto fromId = PeerId( + link->property(kPeerLinkPeerIdProperty).toULongLong()); if (lnkPhoto || lnkDocument) { if (isUponSelected > 0) { _menu->addAction(tr::lng_context_copy_selected(tr::now), [=] { @@ -1231,9 +1232,11 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } } } - } else if (lnkPeer) { // suggest to block - if (auto user = lnkPeer->peer()->asUser()) { - suggestRestrictUser(user); + } else if (fromId) { // suggest to block + if (const auto userId = peerToUser(fromId)) { + if (const auto user = session().data().user(userId)) { + suggestRestrictUser(user); + } } } else { // maybe cursor on some text history item? const auto item = view ? view->data().get() : nullptr; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 2e2c2412a..3fe06f426 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -19,7 +19,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "core/application.h" #include "core/core_settings.h" +#include "core/click_handler_types.h" #include "main/main_session.h" +#include "main/main_domain.h" #include "chat_helpers/stickers_emoji_pack.h" #include "window/window_session_controller.h" #include "ui/effects/path_shift_gradient.h" @@ -572,10 +574,37 @@ bool Element::computeIsAttachToPrevious(not_null previous) { } ClickHandlerPtr Element::fromLink() const { + if (_fromLink) { + return _fromLink; + } const auto item = data(); - const auto from = item->displayFrom(); - if (from) { - return from->openLink(); + if (const auto from = item->displayFrom()) { + _fromLink = std::make_shared([=]( + ClickContext context) { + if (context.button != Qt::LeftButton) { + return; + } + const auto my = context.other.value(); + const auto window = [&]() -> Window::SessionController* { + if (const auto controller = my.sessionWindow.get()) { + return controller; + } + const auto session = &from->session(); + const auto &windows = session->windows(); + if (windows.empty()) { + session->domain().activate(&session->account()); + if (windows.empty()) { + return nullptr; + } + } + return windows.front(); + }(); + if (window) { + window->showPeerInfo(from); + } + }); + _fromLink->setProperty(kPeerLinkPeerIdProperty, from->id.value); + return _fromLink; } if (const auto forwarded = item->Get()) { if (forwarded->imported) { @@ -590,7 +619,8 @@ ClickHandlerPtr Element::fromLink() const { static const auto hidden = std::make_shared([] { Ui::Toast::Show(tr::lng_forwarded_hidden(tr::now)); }); - return hidden; + _fromLink = hidden; + return _fromLink; } void Element::createUnreadBar(rpl::producer text) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 22cbdeebc..1522ac402 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -421,6 +421,7 @@ private: const not_null _delegate; const not_null _data; std::unique_ptr _media; + mutable ClickHandlerPtr _fromLink; bool _isScheduledUntilOnline = false; const QDateTime _dateTime; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 725654654..5cf6981bb 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 725654654d44554c7ce2ebd86d242f7c46b13591 +Subproject commit 5cf6981bbbc7098fab90d7a421e4599ec0013115