From 30e8f17b37568c5b9e52b867ec1485e7676293c1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 30 Dec 2018 12:40:25 +0400 Subject: [PATCH] [all] / [one from chat] in support search results. --- Telegram/SourceFiles/auth_session.cpp | 18 ++++ Telegram/SourceFiles/auth_session.h | 4 + .../dialogs/dialogs_inner_widget.cpp | 91 ++++++++++++------- .../dialogs/dialogs_inner_widget.h | 5 +- .../SourceFiles/dialogs/dialogs_widget.cpp | 18 +++- Telegram/SourceFiles/dialogs/dialogs_widget.h | 2 +- 6 files changed, 100 insertions(+), 38 deletions(-) diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 6b544ee9c7..d5cd2811b6 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -91,6 +91,7 @@ QByteArray AuthSessionSettings::serialize() const { stream << qint32(_variables.countUnreadMessages ? 1 : 0); stream << qint32(_variables.exeLaunchWarning ? 1 : 0); stream << autoDownload; + stream << qint32(_variables.supportAllSearchResults.current() ? 1 : 0); } return result; } @@ -126,6 +127,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) qint32 countUnreadMessages = _variables.countUnreadMessages ? 1 : 0; qint32 exeLaunchWarning = _variables.exeLaunchWarning ? 1 : 0; QByteArray autoDownload; + qint32 supportAllSearchResults = _variables.supportAllSearchResults.current() ? 1 : 0; stream >> selectorTab; stream >> lastSeenWarningSeen; @@ -202,6 +204,9 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) if (!stream.atEnd()) { stream >> autoDownload; } + if (!stream.atEnd()) { + stream >> supportAllSearchResults; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for AuthSessionSettings::constructFromSerialized()")); @@ -270,6 +275,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) _variables.includeMutedCounter = (includeMutedCounter == 1); _variables.countUnreadMessages = (countUnreadMessages == 1); _variables.exeLaunchWarning = (exeLaunchWarning == 1); + _variables.supportAllSearchResults = (supportAllSearchResults == 1); } void AuthSessionSettings::setSupportChatsTimeSlice(int slice) { @@ -284,6 +290,18 @@ rpl::producer AuthSessionSettings::supportChatsTimeSliceValue() const { return _variables.supportChatsTimeSlice.value(); } +void AuthSessionSettings::setSupportAllSearchResults(bool all) { + _variables.supportAllSearchResults = all; +} + +bool AuthSessionSettings::supportAllSearchResults() const { + return _variables.supportAllSearchResults.current(); +} + +rpl::producer AuthSessionSettings::supportAllSearchResultsValue() const { + return _variables.supportAllSearchResults.value(); +} + void AuthSessionSettings::setTabbedSelectorSectionEnabled(bool enabled) { _variables.tabbedSelectorSectionEnabled = enabled; if (enabled) { diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index fe3509072e..411aa72b3e 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -103,6 +103,9 @@ public: void setSupportChatsTimeSlice(int slice); int supportChatsTimeSlice() const; rpl::producer supportChatsTimeSliceValue() const; + void setSupportAllSearchResults(bool all); + bool supportAllSearchResults() const; + rpl::producer supportAllSearchResultsValue() const; ChatHelpers::SelectorTab selectorTab() const { return _variables.selectorTab; @@ -252,6 +255,7 @@ private: bool supportTemplatesAutocomplete = true; rpl::variable supportChatsTimeSlice = kDefaultSupportChatsLimitSlice; + rpl::variable supportAllSearchResults = false; }; rpl::event_stream _thirdSectionInfoEnabledValue; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 3a3251bad8..0554a80511 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -146,9 +146,7 @@ DialogsInner::DialogsInner(QWidget *parent, not_null contro })); Auth().data().feedUpdated( ) | rpl::start_with_next([=](const Data::FeedUpdate &update) { - updateDialogRow( - Dialogs::RowDescriptor(update.feed, FullMsgId()), - QRect(0, 0, getFullWidth(), st::dialogsRowHeight)); + updateDialogRow({ update.feed, FullMsgId() }); }, lifetime()); _controller->activeChatEntryValue( @@ -156,9 +154,8 @@ DialogsInner::DialogsInner(QWidget *parent, not_null contro ) | rpl::start_with_next([=]( Dialogs::RowDescriptor previous, Dialogs::RowDescriptor next) { - const auto rect = QRect(0, 0, getFullWidth(), st::dialogsRowHeight); - updateDialogRow(previous, rect); - updateDialogRow(next, rect); + updateDialogRow(previous); + updateDialogRow(next); }, lifetime()); refresh(); @@ -237,8 +234,8 @@ void DialogsInner::paintRegion(Painter &p, const QRegion ®ion, bool paintingO } auto otherStart = rows->size() * st::dialogsRowHeight; const auto active = activeEntry.key; - const auto selected = _menuKey - ? _menuKey + const auto selected = _menuRow.key + ? _menuRow.key : (isPressed() ? (_pressed ? _pressed->key() @@ -383,8 +380,8 @@ void DialogsInner::paintRegion(Painter &p, const QRegion ®ion, bool paintingO const auto key = row->key(); const auto active = (activeEntry.key == key) && !activeEntry.fullId; - const auto selected = _menuKey - ? (key == _menuKey) + const auto selected = _menuRow.key + ? (key == _menuRow.key) : (from == (isPressed() ? _filteredPressed : _filteredSelected)); @@ -480,9 +477,11 @@ void DialogsInner::paintRegion(Painter &p, const QRegion ®ion, bool paintingO for (; from < to; ++from) { const auto &result = _searchResults[from]; const auto active = isSearchResultActive(result.get(), activeEntry); - const auto selected = (from == (isPressed() - ? _searchedPressed - : _searchedSelected)); + const auto selected = _menuRow.key + ? isSearchResultActive(result.get(), _menuRow) + : (from == (isPressed() + ? _searchedPressed + : _searchedSelected)); Dialogs::Layout::RowPainter::paint( p, result.get(), @@ -1277,8 +1276,8 @@ void DialogsInner::createDialog(Dialogs::Key key) { } void DialogsInner::removeDialog(Dialogs::Key key) { - if (key == _menuKey && _menu) { - InvokeQueued(this, [this] { _menu = nullptr; }); + if (key == _menuRow.key && _menu) { + InvokeQueued(this, [=] { _menu = nullptr; }); } if (_selected && _selected->key() == key) { _selected = nullptr; @@ -1304,6 +1303,15 @@ void DialogsInner::removeDialog(Dialogs::Key key) { _contactsNoDialogs->addByName(key); } } + const auto i = ranges::find(_filterResults, key, &Dialogs::Row::key); + if (i != _filterResults.end()) { + if (_filteredSelected == (i - _filterResults.begin()) + && (i + 1) == _filterResults.end()) { + _filteredSelected = -1; + } + _filterResults.erase(i); + refresh(); + } emit App::main()->dialogsUpdated(); @@ -1341,11 +1349,10 @@ void DialogsInner::repaintDialogRow( void DialogsInner::repaintDialogRow( not_null history, MsgId messageId) { - updateDialogRow( - Dialogs::RowDescriptor( - history, - FullMsgId(history->channelId(), messageId)), - QRect(0, 0, getFullWidth(), st::dialogsRowHeight)); + updateDialogRow({ + history, + FullMsgId(history->channelId(), messageId) + }); } void DialogsInner::updateSearchResult(not_null peer) { @@ -1367,6 +1374,9 @@ void DialogsInner::updateDialogRow( Dialogs::RowDescriptor row, QRect updateRect, UpdateRowSections sections) { + if (updateRect.isEmpty()) { + updateRect = QRect(0, 0, getFullWidth(), st::dialogsRowHeight); + } if (IsServerMsgId(-row.fullId.msg)) { if (const auto peer = row.key.peer()) { if (const auto from = peer->migrateFrom()) { @@ -1515,6 +1525,15 @@ void DialogsInner::clearSelection() { } } +void DialogsInner::fillSupportSearchMenu(not_null menu) { + const auto all = Auth().settings().supportAllSearchResults(); + const auto text = all ? "Only one from chat" : "Show all messages"; + menu->addAction(text, [=] { + Auth().settings().setSupportAllSearchResults(!all); + Auth().saveSettingsDelayed(); + }); +} + void DialogsInner::contextMenuEvent(QContextMenuEvent *e) { _menu = nullptr; @@ -1522,27 +1541,35 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) { selectByMouse(e->globalPos()); } - const auto key = [&]() -> Dialogs::Key { + const auto row = [&]() -> Dialogs::RowDescriptor { if (_state == State::Default) { if (_selected) { - return _selected->key(); + return { _selected->key(), FullMsgId() }; } } else if (_state == State::Filtered) { if (base::in_range(_filteredSelected, 0, _filterResults.size())) { - return _filterResults[_filteredSelected]->key(); + return { _filterResults[_filteredSelected]->key(), FullMsgId() }; + } else if (Auth().supportMode() + && base::in_range(_searchedSelected, 0, _searchResults.size())) { + return { + _searchResults[_searchedSelected]->item()->history(), + _searchResults[_searchedSelected]->item()->fullId() + }; } } - return Dialogs::Key(); + return Dialogs::RowDescriptor(); }(); - if (!key) return; + if (!row.key) return; - _menuKey = key; + _menuRow = row; if (_pressButton != Qt::LeftButton) { mousePressReleased(e->globalPos(), _pressButton); } _menu = base::make_unique_q(this); - if (const auto history = key.history()) { + if (Auth().supportMode() && row.fullId) { + fillSupportSearchMenu(_menu.get()); + } else if (const auto history = row.key.history()) { Window::FillPeerMenu( _controller, history->peer, @@ -1550,7 +1577,7 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) { return _menu->addAction(text, std::move(callback)); }, Window::PeerMenuSource::ChatsList); - } else if (const auto feed = key.feed()) { + } else if (const auto feed = row.key.feed()) { Window::FillFeedMenu( _controller, feed, @@ -1559,9 +1586,9 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) { }, Window::PeerMenuSource::ChatsList); } - connect(_menu.get(), &QObject::destroyed, [this] { - if (_menuKey) { - updateSelectedRow(base::take(_menuKey)); + connect(_menu.get(), &QObject::destroyed, [=] { + if (_menuRow.key) { + updateDialogRow(base::take(_menuRow)); } const auto globalPosition = QCursor::pos(); if (rect().contains(mapFromGlobal(globalPosition))) { @@ -1868,7 +1895,7 @@ void DialogsInner::addAllSavedPeers() { bool DialogsInner::uniqueSearchResults() const { return Auth().supportMode() - && _filter.startsWith('#') + && !Auth().settings().supportAllSearchResults() && !_searchInChat; } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 468028c1f2..9c3c04ed90 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -222,8 +222,9 @@ private: void updateSearchResult(not_null peer); void updateDialogRow( Dialogs::RowDescriptor row, - QRect updateRect, + QRect updateRect = QRect(), UpdateRowSections sections = UpdateRowSection::All); + void fillSupportSearchMenu(not_null menu); int dialogsOffset() const; int proxyPromotedCount() const; @@ -368,7 +369,7 @@ private: UserData *_searchFromUser = nullptr; Text _searchInChatText; Text _searchFromUserText; - Dialogs::Key _menuKey; + Dialogs::RowDescriptor _menuRow; Fn _loadMoreCallback; rpl::event_stream<> _listBottomReached; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 323ac7bafb..4ec637ae92 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -237,7 +237,7 @@ DialogsWidget::DialogsWidget(QWidget *parent, not_null cont updateJumpToDateVisibility(true); updateSearchFromVisibility(true); setupConnectingWidget(); - setupSupportLoadingLimit(); + setupSupportMode(); } void DialogsWidget::setupConnectingWidget() { @@ -246,15 +246,28 @@ void DialogsWidget::setupConnectingWidget() { Window::AdaptiveIsOneColumn()); } -void DialogsWidget::setupSupportLoadingLimit() { +void DialogsWidget::setupSupportMode() { if (!Auth().supportMode()) { return; } + Auth().settings().supportChatsTimeSliceValue( ) | rpl::start_with_next([=](int seconds) { _dialogsLoadTill = seconds ? std::max(unixtime() - seconds, 0) : 0; refreshLoadMoreButton(); }, lifetime()); + + Auth().settings().supportAllSearchResultsValue( + ) | rpl::filter([=] { + return !_searchQuery.isEmpty(); + }) | rpl::start_with_next([=] { + _searchTimer.stop(); + _searchCache.clear(); + _searchQueries.clear(); + _searchQuery = QString(); + _scroll->scrollToY(0); + onSearchMessages(); + }, lifetime()); } void DialogsWidget::checkUpdateStatus() { @@ -1474,7 +1487,6 @@ void DialogsWidget::scrollToEntry(const Dialogs::RowDescriptor &entry) { void DialogsWidget::removeDialog(Dialogs::Key key) { _inner->removeDialog(key); - applyFilterUpdate(true); } Dialogs::IndexedList *DialogsWidget::contactsList() { diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index 61306dfef6..085c4c05f7 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -146,7 +146,7 @@ private: const QVector &dialogs, const QVector &messages); - void setupSupportLoadingLimit(); + void setupSupportMode(); void setupConnectingWidget(); bool searchForPeersRequired(const QString &query) const; void setSearchInChat(Dialogs::Key chat, UserData *from = nullptr);