diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 112e4c9dfa..343730d18b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -1495,6 +1495,8 @@ RowDescriptor InnerWidget::computeChatPreviewRow() const { : 0; if (const auto topic = peer->forumTopicFor(topicId)) { return { topic, FullMsgId() }; + } else if (peer->isForum() && !result.key.topic()) { + return {}; } } return { result.key, result.message.fullId }; diff --git a/Telegram/SourceFiles/history/view/history_view_chat_preview.cpp b/Telegram/SourceFiles/history/view/history_view_chat_preview.cpp index fdc7607f93..91540a7291 100644 --- a/Telegram/SourceFiles/history/view/history_view_chat_preview.cpp +++ b/Telegram/SourceFiles/history/view/history_view_chat_preview.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_list_widget.h" #include "history/history.h" #include "history/history_item.h" +#include "history/history_item_components.h" #include "info/profile/info_profile_cover.h" #include "info/profile/info_profile_values.h" #include "lang/lang_keys.h" @@ -369,7 +370,10 @@ void Item::setupMarkRead() { ) | rpl::start_with_next([=] { const auto state = _thread->chatListBadgesState(); const auto unread = (state.unreadCounter || state.unread); - if (_thread->asTopic() && !unread) { + const auto hidden = _thread->asTopic() + ? (!unread) + : _thread->peer()->isForum(); + if (hidden) { _markRead->hide(); return; } @@ -595,7 +599,11 @@ void Item::listUpdateDateLink( } bool Item::listElementHideReply(not_null view) { - return false; + if (!view->isTopicRootReply()) { + return false; + } + const auto reply = view->data()->Get(); + return reply && !reply->fields().manualQuote; } bool Item::listElementShownUnread(not_null view) { @@ -769,10 +777,6 @@ ChatPreview MakeChatPreview( const auto thread = entry->asThread(); if (!thread) { return {}; - } else if (const auto history = entry->asHistory()) { - if (history->peer->isForum()) { - return {}; - } } auto result = ChatPreview{ diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 133a19973a..38b89f061f 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1042,7 +1042,9 @@ QSize Message::performCountOptimalSize() { void Message::refreshTopicButton() { const auto item = data(); - if (isAttachedToPrevious() || context() != Context::History) { + if (isAttachedToPrevious() + || (context() != Context::History + && context() != Context::ChatPreview)) { _topicButton = nullptr; } else if (const auto topic = item->topic()) { if (!_topicButton) { diff --git a/Telegram/SourceFiles/window/window_chat_preview.cpp b/Telegram/SourceFiles/window/window_chat_preview.cpp index cee4671ddb..24a71c3bcf 100644 --- a/Telegram/SourceFiles/window/window_chat_preview.cpp +++ b/Telegram/SourceFiles/window/window_chat_preview.cpp @@ -33,16 +33,21 @@ ChatPreviewManager::ChatPreviewManager( bool ChatPreviewManager::show( Dialogs::RowDescriptor row, - Fn callback) { + Fn callback, + QPointer parentOverride) { cancelScheduled(); _topicLifetime.destroy(); if (const auto topic = row.key.topic()) { _topicLifetime = topic->destroyed() | rpl::start_with_next([=] { _menu = nullptr; }); + } else if (!row.key) { + return false; } - const auto parent = _controller->content(); + const auto parent = parentOverride + ? parentOverride + : _controller->content(); auto preview = HistoryView::MakeChatPreview(parent, row.key.entry()); if (!preview.menu) { return false; @@ -81,10 +86,14 @@ bool ChatPreviewManager::show( }, _menu->lifetime()); QObject::connect(_menu.get(), &QObject::destroyed, [=] { _topicLifetime.destroy(); - callback(false); + if (callback) { + callback(false); + } }); - callback(true); + if (callback) { + callback(true); + } _menu->popup(QCursor::pos()); return true; @@ -92,7 +101,8 @@ bool ChatPreviewManager::show( bool ChatPreviewManager::schedule( Dialogs::RowDescriptor row, - Fn callback) { + Fn callback, + QPointer parentOverride) { cancelScheduled(); _topicLifetime.destroy(); if (const auto topic = row.key.topic()) { @@ -100,15 +110,12 @@ bool ChatPreviewManager::schedule( cancelScheduled(); _menu = nullptr; }); - } else if (const auto history = row.key.history()) { - if (history->peer->isForum()) { - return false; - } } else { return false; } - _scheduled = row; + _scheduled = std::move(row); _scheduledCallback = std::move(callback); + _scheduledParentOverride = std::move(parentOverride); _timer.callOnce(kChatPreviewDelay); return true; } diff --git a/Telegram/SourceFiles/window/window_chat_preview.h b/Telegram/SourceFiles/window/window_chat_preview.h index c3744e6979..6101ac3e99 100644 --- a/Telegram/SourceFiles/window/window_chat_preview.h +++ b/Telegram/SourceFiles/window/window_chat_preview.h @@ -25,10 +25,12 @@ public: bool show( Dialogs::RowDescriptor row, - Fn callback = nullptr); + Fn callback = nullptr, + QPointer parentOverride = nullptr); bool schedule( Dialogs::RowDescriptor row, - Fn callback = nullptr); + Fn callback = nullptr, + QPointer parentOverride = nullptr); void cancelScheduled(); private: @@ -37,6 +39,7 @@ private: const not_null _controller; Dialogs::RowDescriptor _scheduled; Fn _scheduledCallback; + QPointer _scheduledParentOverride; base::Timer _timer; rpl::lifetime _topicLifetime; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index cea2896683..b1a37190f2 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/random.h" #include "base/options.h" #include "base/unixtime.h" +#include "base/qt/qt_key_modifiers.h" #include "boxes/delete_messages_box.h" #include "boxes/max_invite_box.h" #include "boxes/moderate_messages_box.h" @@ -94,7 +95,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_menu_icons.h" #include -#include +#include namespace Window { namespace { @@ -1239,12 +1240,36 @@ void Filler::addViewAsMessages() { } const auto peer = _peer; const auto controller = _controller; - _addAction(tr::lng_forum_view_as_messages(tr::now), [=] { + const auto parentHideRequests = std::make_shared>(); + const auto filterOutChatPreview = [=] { + if (base::IsAltPressed()) { + const auto callback = [=](bool shown) { + if (!shown) { + parentHideRequests->fire({}); + } + }; + controller->showChatPreview({ + peer->owner().history(peer), + FullMsgId(), + }, callback, QApplication::activePopupWidget()); + return true; + } + return false; + }; + const auto open = [=] { if (const auto forum = peer->forum()) { peer->owner().saveViewAsMessages(forum, true); } controller->showPeerHistory(peer->id); - }, &st::menuIconAsMessages); + }; + auto to_instant = rpl::map_to(anim::type::instant); + _addAction({ + .text = tr::lng_forum_view_as_messages(tr::now), + .handler = open, + .icon = &st::menuIconAsMessages, + .triggerFilter = filterOutChatPreview, + .hideRequests = parentHideRequests->events() | to_instant + }); } void Filler::addViewAsTopics() { diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index e673da20a0..4a004dce81 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -2978,16 +2978,22 @@ QString SessionController::premiumRef() const { bool SessionController::showChatPreview( Dialogs::RowDescriptor row, - Fn callback) { - return _chatPreviewManager->show(std::move(row), std::move(callback)); + Fn callback, + QPointer parentOverride) { + return _chatPreviewManager->show( + std::move(row), + std::move(callback), + std::move(parentOverride)); } bool SessionController::scheduleChatPreview( Dialogs::RowDescriptor row, - Fn callback) { + Fn callback, + QPointer parentOverride) { return _chatPreviewManager->schedule( std::move(row), - std::move(callback)); + std::move(callback), + std::move(parentOverride)); } void SessionController::cancelScheduledPreview() { diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 0cbaf0b9a7..37f45f86e7 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -603,10 +603,12 @@ public: bool showChatPreview( Dialogs::RowDescriptor row, - Fn callback = nullptr); + Fn callback = nullptr, + QPointer parentOverride = nullptr); bool scheduleChatPreview( Dialogs::RowDescriptor row, - Fn callback = nullptr); + Fn callback = nullptr, + QPointer parentOverride = nullptr); void cancelScheduledPreview(); [[nodiscard]] bool contentOverlapped(QWidget *w, QPaintEvent *e) const; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 33aac93b16..d0514b2b02 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 33aac93b160d4cd30119c8859de722e28512902b +Subproject commit d0514b2b022043b3777b06d6068232aa4cda7e80