From 2cd3cec47841df944229fca2a94ac28d2a7f271d Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 30 Dec 2018 16:50:23 +0400 Subject: [PATCH] Go through open history in support mode. --- Telegram/SourceFiles/core/shortcuts.cpp | 4 ++ Telegram/SourceFiles/core/shortcuts.h | 2 + .../dialogs/dialogs_inner_widget.cpp | 21 ++---- .../dialogs/dialogs_inner_widget.h | 2 +- .../SourceFiles/window/window_controller.cpp | 67 ++++++++++++++++++- .../SourceFiles/window/window_controller.h | 8 +++ 6 files changed, 85 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/core/shortcuts.cpp b/Telegram/SourceFiles/core/shortcuts.cpp index f10a027bc3..697579f602 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -43,6 +43,8 @@ const auto SupportCommands = base::flat_set{ Command::SupportReloadTemplates, Command::SupportToggleMuted, Command::SupportScrollToCurrent, + Command::SupportHistoryBack, + Command::SupportHistoryForward, }; const auto CommandByName = base::flat_map{ @@ -310,6 +312,8 @@ void Manager::fillDefaults() { set(qsl("f5"), Command::SupportReloadTemplates); set(qsl("ctrl+delete"), Command::SupportToggleMuted); set(qsl("ctrl+insert"), Command::SupportScrollToCurrent); + set(qsl("ctrl+shift+x"), Command::SupportHistoryBack); + set(qsl("ctrl+shift+c"), Command::SupportHistoryForward); set(qsl("ctrl+1"), Command::ChatPinned1); set(qsl("ctrl+2"), Command::ChatPinned2); diff --git a/Telegram/SourceFiles/core/shortcuts.h b/Telegram/SourceFiles/core/shortcuts.h index a985b9e6ed..3029f218c7 100644 --- a/Telegram/SourceFiles/core/shortcuts.h +++ b/Telegram/SourceFiles/core/shortcuts.h @@ -37,6 +37,8 @@ enum class Command { SupportReloadTemplates, SupportToggleMuted, SupportScrollToCurrent, + SupportHistoryBack, + SupportHistoryForward, }; [[nodiscard]] FnMut RequestHandler(Command command); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 08603eeff0..8674ab2fd6 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -2921,25 +2921,12 @@ Dialogs::RowDescriptor DialogsInner::computeJump( return result; } -bool DialogsInner::jumpToDialogRow(const Dialogs::RowDescriptor &to) { +bool DialogsInner::jumpToDialogRow(Dialogs::RowDescriptor to) { if (to == chatListEntryLast()) { _listBottomReached.fire({}); } - - if (const auto history = to.key.history()) { - Ui::showPeerHistory( - history, - (uniqueSearchResults() - ? ShowAtUnreadMsgId - : to.fullId.msg)); - return true; - } else if (const auto feed = to.key.feed()) { - if (const auto item = App::histItemById(to.fullId)) { - _controller->showSection( - HistoryFeed::Memento(feed, item->position())); - } else { - _controller->showSection(HistoryFeed::Memento(feed)); - } + if (uniqueSearchResults()) { + to.fullId = FullMsgId(); } - return false; + return _controller->jumpToChatListEntry(to); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 4d2c49500e..6d03e55974 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -196,7 +196,7 @@ private: Dialogs::RowDescriptor computeJump( const Dialogs::RowDescriptor &to, JumpSkip skip); - bool jumpToDialogRow(const Dialogs::RowDescriptor &to); + bool jumpToDialogRow(Dialogs::RowDescriptor to); Dialogs::RowDescriptor chatListEntryBefore( const Dialogs::RowDescriptor &which) const; diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 42f5cfdcf3..fd650f37f0 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -13,10 +13,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "history/view/history_view_element.h" +#include "history/feed/history_feed_section.h" #include "media/player/media_player_round_controller.h" #include "data/data_session.h" #include "data/data_feed.h" #include "passport/passport_form_controller.h" +#include "core/shortcuts.h" #include "boxes/calendar_box.h" #include "mainwidget.h" #include "mainwindow.h" @@ -27,6 +29,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_dialogs.h" namespace Window { +namespace { + +constexpr auto kMaxChatEntryHistorySize = 50; + +} // namespace DateClickHandler::DateClickHandler(Dialogs::Key chat, QDate date) : _chat(chat) @@ -53,12 +60,70 @@ Controller::Controller(not_null window) }, lifetime()); if (Auth().supportMode()) { - Auth().supportHelper().registerWindow(this); + initSupportMode(); } } +void Controller::initSupportMode() { + Auth().supportHelper().registerWindow(this); + + Shortcuts::Requests( + ) | rpl::start_with_next([=](not_null request) { + using C = Shortcuts::Command; + + request->check(C::SupportHistoryBack) && request->handle([=] { + return chatEntryHistoryMove(-1); + }); + request->check(C::SupportHistoryForward) && request->handle([=] { + return chatEntryHistoryMove(1); + }); + }, lifetime()); +} + void Controller::setActiveChatEntry(Dialogs::RowDescriptor row) { _activeChatEntry = row; + if (Auth().supportMode()) { + pushToChatEntryHistory(row); + } +} + +bool Controller::chatEntryHistoryMove(int steps) { + if (_chatEntryHistory.empty()) { + return false; + } + const auto position = _chatEntryHistoryPosition + steps; + if (!base::in_range(position, 0, int(_chatEntryHistory.size()))) { + return false; + } + _chatEntryHistoryPosition = position; + return jumpToChatListEntry(_chatEntryHistory[position]); +} + +bool Controller::jumpToChatListEntry(Dialogs::RowDescriptor row) { + if (const auto history = row.key.history()) { + Ui::showPeerHistory(history, row.fullId.msg); + return true; + } else if (const auto feed = row.key.feed()) { + if (const auto item = App::histItemById(row.fullId)) { + showSection(HistoryFeed::Memento(feed, item->position())); + } else { + showSection(HistoryFeed::Memento(feed)); + } + } + return false; +} + +void Controller::pushToChatEntryHistory(Dialogs::RowDescriptor row) { + if (!_chatEntryHistory.empty() + && _chatEntryHistory[_chatEntryHistoryPosition] == row) { + return; + } + _chatEntryHistory.resize(++_chatEntryHistoryPosition); + _chatEntryHistory.push_back(row); + if (_chatEntryHistory.size() > kMaxChatEntryHistorySize) { + _chatEntryHistory.pop_front(); + --_chatEntryHistoryPosition; + } } void Controller::setActiveChatEntry(Dialogs::Key key) { diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index e71496ce31..754b797d03 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -149,6 +149,7 @@ public: rpl::producer activeChatChanges() const; rpl::producer activeChatEntryValue() const; rpl::producer activeChatValue() const; + bool jumpToChatListEntry(Dialogs::RowDescriptor row); void enableGifPauseReason(GifPauseReason reason); void disableGifPauseReason(GifPauseReason reason); @@ -259,6 +260,8 @@ public: ~Controller(); private: + void initSupportMode(); + int minimalThreeColumnWidth() const; not_null chats() const; int countDialogsWidthFromRatio(int bodyWidth) const; @@ -272,6 +275,9 @@ private: int thirdWidth, int bodyWidth) const; + void pushToChatEntryHistory(Dialogs::RowDescriptor row); + bool chatEntryHistoryMove(int steps); + not_null _window; std::unique_ptr _passportForm; @@ -283,6 +289,8 @@ private: rpl::variable _activeChatEntry; base::Variable _dialogsListFocused = { false }; base::Variable _dialogsListDisplayForced = { false }; + std::deque _chatEntryHistory; + int _chatEntryHistoryPosition = -1; std::unique_ptr _roundVideo; std::unique_ptr _floatPlayers;