Single entry point to search in chat.

This commit is contained in:
John Preston 2023-01-18 15:17:32 +04:00
parent 2c75fe033c
commit f8e76f1b84
6 changed files with 23 additions and 39 deletions

View file

@ -1481,9 +1481,7 @@ void Widget::showMainMenu() {
controller()->widget()->showMainMenu(); controller()->widget()->showMainMenu();
} }
void Widget::searchMessages( void Widget::searchMessages(const QString &query, Key inChat) {
const QString &query,
Key inChat) {
if (_childList) { if (_childList) {
const auto forum = controller()->shownForum().current(); const auto forum = controller()->shownForum().current();
const auto topic = inChat.topic(); const auto topic = inChat.topic();
@ -1494,18 +1492,27 @@ void Widget::searchMessages(
} }
hideChildList(); hideChildList();
} }
if (_openedFolder) {
controller()->closeFolder();
}
const auto inChatChanged = [&] { const auto inChatChanged = [&] {
const auto inPeer = inChat.peer(); const auto inPeer = inChat.peer();
const auto inTopic = inChat.topic(); const auto inTopic = inChat.topic();
if (!inTopic && _openedForum && inPeer == _openedForum->channel()) { if (!inTopic
&& _openedForum
&& inPeer == _openedForum->channel()
&& _subsectionTopBar
&& _subsectionTopBar->searchMode()) {
return false; return false;
} else if ((inTopic || (inPeer && !inPeer->isForum())) } else if ((inTopic || (inPeer && !inPeer->isForum()))
&& (inChat == _searchInChat)) { && (inChat == _searchInChat)) {
return false; return false;
} else if (const auto inPeer = inChat.peer()) { } else if (const auto inPeer = inChat.peer()) {
if (inPeer->migrateTo() == _searchInChat.peer() if (const auto to = inPeer->migrateTo()) {
&& !_searchInChat.topic()) { if (to == _searchInChat.peer() && !_searchInChat.topic()) {
return false; return false;
}
} }
} }
return true; return true;
@ -2130,18 +2137,7 @@ void Widget::closeChildList(anim::type animated) {
} }
void Widget::searchInChat(Key chat) { void Widget::searchInChat(Key chat) {
if (_openedForum && !chat.peer()->forum()) { searchMessages(QString(), chat);
controller()->closeForum();
}
if (_openedFolder) {
if (_childList && _childList->setSearchInChat(chat)) {
return;
}
controller()->closeFolder();
}
cancelSearch();
setSearchInChat(chat);
applyFilterUpdate(true);
} }
bool Widget::setSearchInChat(Key chat, PeerData *from) { bool Widget::setSearchInChat(Key chat, PeerData *from) {

View file

@ -4536,12 +4536,8 @@ bool HistoryWidget::updateCmdStartShown() {
} }
void HistoryWidget::searchInChat() { void HistoryWidget::searchInChat() {
if (!_history) { if (_history) {
return;
} else if (controller()->isPrimary()) {
controller()->content()->searchInChat(_history); controller()->content()->searchInChat(_history);
} else {
searchInChatEmbedded();
} }
} }

View file

@ -2598,12 +2598,8 @@ void RepliesWidget::setupShortcuts() {
} }
void RepliesWidget::searchInTopic() { void RepliesWidget::searchInTopic() {
if (!_topic) { if (_topic) {
return;
} else if (controller()->isPrimary()) {
controller()->content()->searchInChat(_topic); controller()->content()->searchInChat(_topic);
} else {
// #TODO forum window
} }
} }

View file

@ -1318,6 +1318,10 @@ bool TopBarWidget::searchSetFocus() {
return true; return true;
} }
bool TopBarWidget::searchMode() const {
return _searchMode;
}
bool TopBarWidget::searchHasFocus() const { bool TopBarWidget::searchHasFocus() const {
return _searchMode && _searchField->hasFocus(); return _searchMode && _searchField->hasFocus();
} }

View file

@ -82,6 +82,7 @@ public:
void searchEnableJumpToDate(bool enable); void searchEnableJumpToDate(bool enable);
void searchEnableChooseFromUser(bool enable, bool visible); void searchEnableChooseFromUser(bool enable, bool visible);
bool searchSetFocus(); bool searchSetFocus();
[[nodiscard]] bool searchMode() const;
[[nodiscard]] bool searchHasFocus() const; [[nodiscard]] bool searchHasFocus() const;
[[nodiscard]] rpl::producer<> searchCancelled() const; [[nodiscard]] rpl::producer<> searchCancelled() const;
[[nodiscard]] rpl::producer<> searchSubmitted() const; [[nodiscard]] rpl::producer<> searchSubmitted() const;

View file

@ -2652,16 +2652,7 @@ int MainWidget::backgroundFromY() const {
} }
void MainWidget::searchInChat(Dialogs::Key chat) { void MainWidget::searchInChat(Dialogs::Key chat) {
// #TODO windows searchMessages(QString(), chat);
if (!_dialogs) {
return;
}
_dialogs->searchInChat(chat);
if (isOneColumn()) {
_controller->clearSectionStack();
} else {
_dialogs->setInnerFocus();
}
} }
bool MainWidget::contentOverlapped(const QRect &globalRect) { bool MainWidget::contentOverlapped(const QRect &globalRect) {