2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Add some more shortcuts for Support.

This commit is contained in:
John Preston
2018-11-16 17:36:42 +04:00
parent b3ffbeb63e
commit 479a6d9ad2
13 changed files with 221 additions and 137 deletions

View File

@@ -13,9 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/feed/history_feed_section.h"
#include "history/history.h"
#include "history/history_item.h"
#include "styles/style_dialogs.h"
#include "styles/style_chat_helpers.h"
#include "styles/style_window.h"
#include "core/shortcuts.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/popup_menu.h"
#include "ui/text_options.h"
@@ -36,6 +34,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_peer_menu.h"
#include "ui/widgets/multi_select.h"
#include "ui/empty_userpic.h"
#include "styles/style_dialogs.h"
#include "styles/style_chat_helpers.h"
#include "styles/style_window.h"
namespace {
@@ -160,6 +161,8 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
updateDialogRow(next, rect);
}, lifetime());
refresh();
setupShortcuts();
}
int DialogsInner::dialogsOffset() const {
@@ -2288,16 +2291,16 @@ void DialogsInner::selectSkip(int32 direction) {
update();
}
void DialogsInner::scrollToPeer(not_null<History*> history, MsgId msgId) {
void DialogsInner::scrollToEntry(const Dialogs::RowDescriptor &entry) {
int32 fromY = -1;
if (_state == State::Default) {
if (auto row = shownDialogs()->getRow(history)) {
if (auto row = shownDialogs()->getRow(entry.key)) {
fromY = dialogsOffset() + row->pos() * st::dialogsRowHeight;
}
} else if (_state == State::Filtered) {
if (msgId) {
if (entry.fullId.msg) {
for (int32 i = 0, c = _searchResults.size(); i < c; ++i) {
if (_searchResults[i]->item()->history() == history && _searchResults[i]->item()->id == msgId) {
if (_searchResults[i]->item()->fullId() == entry.fullId) {
fromY = searchedOffset() + i * st::dialogsRowHeight;
break;
}
@@ -2305,7 +2308,7 @@ void DialogsInner::scrollToPeer(not_null<History*> history, MsgId msgId) {
}
if (fromY < 0) {
for (auto i = 0, c = _filterResults.size(); i != c; ++i) {
if (_filterResults[i]->history() == history) {
if (_filterResults[i]->key() == entry.key) {
fromY = filteredOffset() + (i * st::dialogsRowHeight);
break;
}
@@ -2551,7 +2554,6 @@ void DialogsInner::destroyData() {
}
}
Dialogs::RowDescriptor DialogsInner::chatListEntryBefore(
const Dialogs::RowDescriptor &which) const {
if (!which.key) {
@@ -2700,6 +2702,56 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryAfter(
return Dialogs::RowDescriptor();
}
Dialogs::RowDescriptor DialogsInner::chatListEntryFirst() const {
if (_state == State::Default) {
const auto i = shownDialogs()->cbegin();
if (i != shownDialogs()->cend()) {
return Dialogs::RowDescriptor(
(*i)->key(),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
}
return Dialogs::RowDescriptor();
} else if (!_filterResults.empty()) {
return Dialogs::RowDescriptor(
_filterResults.front()->key(),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_peerSearchResults.empty()) {
return Dialogs::RowDescriptor(
App::history(_peerSearchResults.front()->peer),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_searchResults.empty()) {
return Dialogs::RowDescriptor(
_searchResults.front()->item()->history(),
_searchResults.front()->item()->fullId());
}
return Dialogs::RowDescriptor();
}
Dialogs::RowDescriptor DialogsInner::chatListEntryLast() const {
if (_state == State::Default) {
const auto i = shownDialogs()->cend();
if (i != shownDialogs()->cbegin()) {
return Dialogs::RowDescriptor(
(*(i - 1))->key(),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
}
return Dialogs::RowDescriptor();
} else if (!_searchResults.empty()) {
return Dialogs::RowDescriptor(
_searchResults.back()->item()->history(),
_searchResults.back()->item()->fullId());
} else if (!_peerSearchResults.empty()) {
return Dialogs::RowDescriptor(
App::history(_peerSearchResults.back()->peer),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_filterResults.empty()) {
return Dialogs::RowDescriptor(
_filterResults.back()->key(),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
}
return Dialogs::RowDescriptor();
}
Dialogs::IndexedList *DialogsInner::contactsList() {
return _contacts.get();
}
@@ -2728,3 +2780,84 @@ MsgId DialogsInner::lastSearchMigratedId() const {
return _lastSearchMigratedId;
}
void DialogsInner::setupShortcuts() {
Shortcuts::Requests(
) | rpl::filter([=] {
return isActiveWindow() && !Ui::isLayerShown();
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
if (App::main()->selectingPeer()) {
return;
}
const auto row = _controller->activeChatEntryCurrent();
if (row.key) {
request->check(Command::ChatPrevious) && request->handle([=] {
return showPreviousChat(row);
});
request->check(Command::ChatNext) && request->handle([=] {
return showNextChat(row);
});
}
request->check(Command::ChatFirst) && request->handle([=] {
return showFirstChat();
});
request->check(Command::ChatLast) && request->handle([=] {
return showLastChat();
});
if (Auth().supportMode() && row.key.history()) {
request->check(
Command::SupportScrollToCurrent
) && request->handle([=] {
scrollToEntry(row);
return true;
});
}
}, lifetime());
}
bool DialogsInner::showNextChat(const Dialogs::RowDescriptor &current) {
return jumpToDialogRow(chatListEntryAfter(current), 1);
}
bool DialogsInner::showPreviousChat(const Dialogs::RowDescriptor &current) {
return jumpToDialogRow(chatListEntryBefore(current), -1);
}
bool DialogsInner::showFirstChat() {
return jumpToDialogRow(chatListEntryFirst(), 1);
}
bool DialogsInner::showLastChat() {
return jumpToDialogRow(chatListEntryLast(), -1);
}
bool DialogsInner::jumpToDialogRow(
const Dialogs::RowDescriptor &to,
int skipDirection) {
const auto entry = [&] {
auto result = to;
if (Auth().supportMode()) {
while (result.key
&& !result.key.entry()->chatListUnreadCount()
&& !result.key.entry()->chatListUnreadMark()) {
result = (skipDirection > 0)
? chatListEntryAfter(result)
: chatListEntryBefore(result);
}
}
return result;
}();
if (const auto history = entry.key.history()) {
Ui::showPeerHistory(history, entry.fullId.msg);
return true;
} else if (const auto feed = entry.key.feed()) {
if (const auto item = App::histItemById(entry.fullId)) {
_controller->showSection(
HistoryFeed::Memento(feed, item->position()));
} else {
_controller->showSection(HistoryFeed::Memento(feed));
}
}
return false;
}