| 792 | } |
| 793 | |
| 794 | void MainWidget::searchMessages( |
| 795 | const QString &query, |
| 796 | Dialogs::Key inChat, |
| 797 | PeerData *searchFrom) { |
| 798 | const auto complex = Data::HashtagWithUsernameFromQuery(query); |
| 799 | if (!complex.username.isEmpty()) { |
| 800 | _controller->showPeerByLink(Window::PeerByLinkInfo{ |
| 801 | .usernameOrId = complex.username, |
| 802 | .text = complex.hashtag, |
| 803 | .resolveType = Window::ResolveType::HashtagSearch, |
| 804 | }); |
| 805 | return; |
| 806 | } |
| 807 | auto tags = Data::SearchTagsFromQuery(query); |
| 808 | const auto archiveWindow = (_controller->windowId().type |
| 809 | == Window::SeparateType::Archive); |
| 810 | if (_dialogs |
| 811 | && !archiveWindow |
| 812 | && (!ForceComposeSearchOneColumn.value() || !isOneColumn())) { |
| 813 | auto state = Dialogs::SearchState{ |
| 814 | .inChat = ((tags.empty() || inChat.sublist()) |
| 815 | ? inChat |
| 816 | : session().data().history(session().user())), |
| 817 | .fromPeer = inChat ? searchFrom : nullptr, |
| 818 | .tags = tags, |
| 819 | .query = tags.empty() ? query : QString(), |
| 820 | }; |
| 821 | state.tab = state.defaultTabForMe(); |
| 822 | _dialogs->searchMessages(std::move(state)); |
| 823 | if (isOneColumn()) { |
| 824 | _controller->clearSectionStack(); |
| 825 | } else { |
| 826 | _dialogs->setInnerFocus(); |
| 827 | } |
| 828 | } else { |
| 829 | if (const auto sublist = inChat.sublist()) { |
| 830 | using namespace HistoryView; |
| 831 | controller()->showSection( |
| 832 | std::make_shared<ChatMemento>(ChatViewId{ |
| 833 | .history = sublist->owningHistory(), |
| 834 | .sublist = sublist, |
| 835 | })); |
| 836 | } else if (!tags.empty()) { |
| 837 | inChat = controller()->session().data().history( |
| 838 | controller()->session().user()); |
| 839 | } |
| 840 | if ((!_mainSection |
| 841 | || !_mainSection->searchInChatEmbedded(query, inChat, searchFrom)) |
| 842 | && !_history->searchInChatEmbedded(query, inChat, searchFrom)) { |
| 843 | const auto account = not_null(&session().account()); |
| 844 | if (const auto window = Core::App().windowFor(account)) { |
| 845 | if (const auto controller = window->sessionController()) { |
| 846 | controller->widget()->activate(); |
| 847 | controller->content()->searchMessages( |
| 848 | query, |
| 849 | inChat, |
| 850 | searchFrom); |
| 851 | } |
no test coverage detected