Improve chats search loading indication.

This commit is contained in:
John Preston
2024-06-16 10:27:00 +04:00
parent 032fe3e0fc
commit 5810149a77
4 changed files with 57 additions and 24 deletions
+21 -11
View File
@@ -95,6 +95,7 @@ namespace {
constexpr auto kSearchPerPage = 50;
constexpr auto kStoriesExpandDuration = crl::time(200);
constexpr auto kSearchRequestDelay = crl::time(900);
base::options::toggle OptionForumHideChatsList({
.id = kOptionForumHideChatsList,
@@ -324,9 +325,9 @@ Widget::Widget(
_scroll->scrollToY(st + _inner->st()->height);
}
}, lifetime());
_inner->searchMessages(
) | rpl::start_with_next([=] {
searchRequested();
_inner->searchRequests(
) | rpl::start_with_next([=](SearchRequestDelay delay) {
searchRequested(delay);
}, lifetime());
_inner->completeHashtagRequests(
) | rpl::start_with_next([=](const QString &tag) {
@@ -1921,7 +1922,7 @@ void Widget::loadMoreBlockedByDate() {
session().api().requestMoreBlockedByDateDialogs();
}
bool Widget::search(bool inCache) {
bool Widget::search(bool inCache, SearchRequestDelay delay) {
_processingSearch = true;
const auto guard = gsl::finally([&] {
_processingSearch = false;
@@ -1950,7 +1951,7 @@ bool Widget::search(bool inCache) {
return true;
} else if (inCache) {
const auto success = _singleMessageSearch.lookup(query, [=] {
searchRequested();
searchRequested(delay);
});
if (!success) {
return false;
@@ -2068,6 +2069,9 @@ bool Widget::search(bool inCache) {
}).send();
_searchQueries.emplace(_searchRequest, _searchQuery);
}
_inner->searchRequested(true);
} else {
_inner->searchRequested(false);
}
const auto peerQuery = Api::ConvertPeerSearchQuery(query);
if (searchForPeersRequired(peerQuery)) {
@@ -2130,9 +2134,14 @@ bool Widget::searchForTopicsRequired(const QString &query) const {
&& !_openedForum->topicsList()->loaded();
}
void Widget::searchRequested() {
if (!search(true)) {
_searchTimer.callOnce(AutoSearchTimeout);
void Widget::searchRequested(SearchRequestDelay delay) {
if (search(true, delay)) {
return;
} else if (delay == SearchRequestDelay::Instant) {
_searchTimer.cancel();
search();
} else {
_searchTimer.callOnce(kSearchRequestDelay);
}
}
@@ -2187,10 +2196,11 @@ void Widget::searchTopics() {
}
void Widget::searchMore() {
if (_searchRequest || _searchInHistoryRequest) {
if (_searchRequest
|| _searchInHistoryRequest
|| _searchTimer.isActive()) {
return;
}
if (!_searchFull) {
} else if (!_searchFull) {
if (const auto peer = searchInPeer()) {
auto &histories = session().data().histories();
const auto topic = searchInTopic();