2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-01 23:25:15 +00:00

Go through open history in support mode.

This commit is contained in:
John Preston
2018-12-30 16:50:23 +04:00
parent c11b977f1d
commit 2cd3cec478
6 changed files with 85 additions and 19 deletions

View File

@@ -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<MainWindow*> 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<Shortcuts::Request*> 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) {