[all] / [one from chat] in support search results.

This commit is contained in:
John Preston 2018-12-30 12:40:25 +04:00
parent 2c3190ce2a
commit 30e8f17b37
6 changed files with 100 additions and 38 deletions

View File

@ -91,6 +91,7 @@ QByteArray AuthSessionSettings::serialize() const {
stream << qint32(_variables.countUnreadMessages ? 1 : 0); stream << qint32(_variables.countUnreadMessages ? 1 : 0);
stream << qint32(_variables.exeLaunchWarning ? 1 : 0); stream << qint32(_variables.exeLaunchWarning ? 1 : 0);
stream << autoDownload; stream << autoDownload;
stream << qint32(_variables.supportAllSearchResults.current() ? 1 : 0);
} }
return result; return result;
} }
@ -126,6 +127,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized)
qint32 countUnreadMessages = _variables.countUnreadMessages ? 1 : 0; qint32 countUnreadMessages = _variables.countUnreadMessages ? 1 : 0;
qint32 exeLaunchWarning = _variables.exeLaunchWarning ? 1 : 0; qint32 exeLaunchWarning = _variables.exeLaunchWarning ? 1 : 0;
QByteArray autoDownload; QByteArray autoDownload;
qint32 supportAllSearchResults = _variables.supportAllSearchResults.current() ? 1 : 0;
stream >> selectorTab; stream >> selectorTab;
stream >> lastSeenWarningSeen; stream >> lastSeenWarningSeen;
@ -202,6 +204,9 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized)
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> autoDownload; stream >> autoDownload;
} }
if (!stream.atEnd()) {
stream >> supportAllSearchResults;
}
if (stream.status() != QDataStream::Ok) { if (stream.status() != QDataStream::Ok) {
LOG(("App Error: " LOG(("App Error: "
"Bad data for AuthSessionSettings::constructFromSerialized()")); "Bad data for AuthSessionSettings::constructFromSerialized()"));
@ -270,6 +275,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized)
_variables.includeMutedCounter = (includeMutedCounter == 1); _variables.includeMutedCounter = (includeMutedCounter == 1);
_variables.countUnreadMessages = (countUnreadMessages == 1); _variables.countUnreadMessages = (countUnreadMessages == 1);
_variables.exeLaunchWarning = (exeLaunchWarning == 1); _variables.exeLaunchWarning = (exeLaunchWarning == 1);
_variables.supportAllSearchResults = (supportAllSearchResults == 1);
} }
void AuthSessionSettings::setSupportChatsTimeSlice(int slice) { void AuthSessionSettings::setSupportChatsTimeSlice(int slice) {
@ -284,6 +290,18 @@ rpl::producer<int> AuthSessionSettings::supportChatsTimeSliceValue() const {
return _variables.supportChatsTimeSlice.value(); return _variables.supportChatsTimeSlice.value();
} }
void AuthSessionSettings::setSupportAllSearchResults(bool all) {
_variables.supportAllSearchResults = all;
}
bool AuthSessionSettings::supportAllSearchResults() const {
return _variables.supportAllSearchResults.current();
}
rpl::producer<bool> AuthSessionSettings::supportAllSearchResultsValue() const {
return _variables.supportAllSearchResults.value();
}
void AuthSessionSettings::setTabbedSelectorSectionEnabled(bool enabled) { void AuthSessionSettings::setTabbedSelectorSectionEnabled(bool enabled) {
_variables.tabbedSelectorSectionEnabled = enabled; _variables.tabbedSelectorSectionEnabled = enabled;
if (enabled) { if (enabled) {

View File

@ -103,6 +103,9 @@ public:
void setSupportChatsTimeSlice(int slice); void setSupportChatsTimeSlice(int slice);
int supportChatsTimeSlice() const; int supportChatsTimeSlice() const;
rpl::producer<int> supportChatsTimeSliceValue() const; rpl::producer<int> supportChatsTimeSliceValue() const;
void setSupportAllSearchResults(bool all);
bool supportAllSearchResults() const;
rpl::producer<bool> supportAllSearchResultsValue() const;
ChatHelpers::SelectorTab selectorTab() const { ChatHelpers::SelectorTab selectorTab() const {
return _variables.selectorTab; return _variables.selectorTab;
@ -252,6 +255,7 @@ private:
bool supportTemplatesAutocomplete = true; bool supportTemplatesAutocomplete = true;
rpl::variable<int> supportChatsTimeSlice rpl::variable<int> supportChatsTimeSlice
= kDefaultSupportChatsLimitSlice; = kDefaultSupportChatsLimitSlice;
rpl::variable<bool> supportAllSearchResults = false;
}; };
rpl::event_stream<bool> _thirdSectionInfoEnabledValue; rpl::event_stream<bool> _thirdSectionInfoEnabledValue;

View File

@ -146,9 +146,7 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
})); }));
Auth().data().feedUpdated( Auth().data().feedUpdated(
) | rpl::start_with_next([=](const Data::FeedUpdate &update) { ) | rpl::start_with_next([=](const Data::FeedUpdate &update) {
updateDialogRow( updateDialogRow({ update.feed, FullMsgId() });
Dialogs::RowDescriptor(update.feed, FullMsgId()),
QRect(0, 0, getFullWidth(), st::dialogsRowHeight));
}, lifetime()); }, lifetime());
_controller->activeChatEntryValue( _controller->activeChatEntryValue(
@ -156,9 +154,8 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
) | rpl::start_with_next([=]( ) | rpl::start_with_next([=](
Dialogs::RowDescriptor previous, Dialogs::RowDescriptor previous,
Dialogs::RowDescriptor next) { Dialogs::RowDescriptor next) {
const auto rect = QRect(0, 0, getFullWidth(), st::dialogsRowHeight); updateDialogRow(previous);
updateDialogRow(previous, rect); updateDialogRow(next);
updateDialogRow(next, rect);
}, lifetime()); }, lifetime());
refresh(); refresh();
@ -237,8 +234,8 @@ void DialogsInner::paintRegion(Painter &p, const QRegion &region, bool paintingO
} }
auto otherStart = rows->size() * st::dialogsRowHeight; auto otherStart = rows->size() * st::dialogsRowHeight;
const auto active = activeEntry.key; const auto active = activeEntry.key;
const auto selected = _menuKey const auto selected = _menuRow.key
? _menuKey ? _menuRow.key
: (isPressed() : (isPressed()
? (_pressed ? (_pressed
? _pressed->key() ? _pressed->key()
@ -383,8 +380,8 @@ void DialogsInner::paintRegion(Painter &p, const QRegion &region, bool paintingO
const auto key = row->key(); const auto key = row->key();
const auto active = (activeEntry.key == key) const auto active = (activeEntry.key == key)
&& !activeEntry.fullId; && !activeEntry.fullId;
const auto selected = _menuKey const auto selected = _menuRow.key
? (key == _menuKey) ? (key == _menuRow.key)
: (from == (isPressed() : (from == (isPressed()
? _filteredPressed ? _filteredPressed
: _filteredSelected)); : _filteredSelected));
@ -480,9 +477,11 @@ void DialogsInner::paintRegion(Painter &p, const QRegion &region, bool paintingO
for (; from < to; ++from) { for (; from < to; ++from) {
const auto &result = _searchResults[from]; const auto &result = _searchResults[from];
const auto active = isSearchResultActive(result.get(), activeEntry); const auto active = isSearchResultActive(result.get(), activeEntry);
const auto selected = (from == (isPressed() const auto selected = _menuRow.key
? _searchedPressed ? isSearchResultActive(result.get(), _menuRow)
: _searchedSelected)); : (from == (isPressed()
? _searchedPressed
: _searchedSelected));
Dialogs::Layout::RowPainter::paint( Dialogs::Layout::RowPainter::paint(
p, p,
result.get(), result.get(),
@ -1277,8 +1276,8 @@ void DialogsInner::createDialog(Dialogs::Key key) {
} }
void DialogsInner::removeDialog(Dialogs::Key key) { void DialogsInner::removeDialog(Dialogs::Key key) {
if (key == _menuKey && _menu) { if (key == _menuRow.key && _menu) {
InvokeQueued(this, [this] { _menu = nullptr; }); InvokeQueued(this, [=] { _menu = nullptr; });
} }
if (_selected && _selected->key() == key) { if (_selected && _selected->key() == key) {
_selected = nullptr; _selected = nullptr;
@ -1304,6 +1303,15 @@ void DialogsInner::removeDialog(Dialogs::Key key) {
_contactsNoDialogs->addByName(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(); emit App::main()->dialogsUpdated();
@ -1341,11 +1349,10 @@ void DialogsInner::repaintDialogRow(
void DialogsInner::repaintDialogRow( void DialogsInner::repaintDialogRow(
not_null<History*> history, not_null<History*> history,
MsgId messageId) { MsgId messageId) {
updateDialogRow( updateDialogRow({
Dialogs::RowDescriptor( history,
history, FullMsgId(history->channelId(), messageId)
FullMsgId(history->channelId(), messageId)), });
QRect(0, 0, getFullWidth(), st::dialogsRowHeight));
} }
void DialogsInner::updateSearchResult(not_null<PeerData*> peer) { void DialogsInner::updateSearchResult(not_null<PeerData*> peer) {
@ -1367,6 +1374,9 @@ void DialogsInner::updateDialogRow(
Dialogs::RowDescriptor row, Dialogs::RowDescriptor row,
QRect updateRect, QRect updateRect,
UpdateRowSections sections) { UpdateRowSections sections) {
if (updateRect.isEmpty()) {
updateRect = QRect(0, 0, getFullWidth(), st::dialogsRowHeight);
}
if (IsServerMsgId(-row.fullId.msg)) { if (IsServerMsgId(-row.fullId.msg)) {
if (const auto peer = row.key.peer()) { if (const auto peer = row.key.peer()) {
if (const auto from = peer->migrateFrom()) { if (const auto from = peer->migrateFrom()) {
@ -1515,6 +1525,15 @@ void DialogsInner::clearSelection() {
} }
} }
void DialogsInner::fillSupportSearchMenu(not_null<Ui::PopupMenu*> 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) { void DialogsInner::contextMenuEvent(QContextMenuEvent *e) {
_menu = nullptr; _menu = nullptr;
@ -1522,27 +1541,35 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) {
selectByMouse(e->globalPos()); selectByMouse(e->globalPos());
} }
const auto key = [&]() -> Dialogs::Key { const auto row = [&]() -> Dialogs::RowDescriptor {
if (_state == State::Default) { if (_state == State::Default) {
if (_selected) { if (_selected) {
return _selected->key(); return { _selected->key(), FullMsgId() };
} }
} else if (_state == State::Filtered) { } else if (_state == State::Filtered) {
if (base::in_range(_filteredSelected, 0, _filterResults.size())) { 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) { if (_pressButton != Qt::LeftButton) {
mousePressReleased(e->globalPos(), _pressButton); mousePressReleased(e->globalPos(), _pressButton);
} }
_menu = base::make_unique_q<Ui::PopupMenu>(this); _menu = base::make_unique_q<Ui::PopupMenu>(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( Window::FillPeerMenu(
_controller, _controller,
history->peer, history->peer,
@ -1550,7 +1577,7 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) {
return _menu->addAction(text, std::move(callback)); return _menu->addAction(text, std::move(callback));
}, },
Window::PeerMenuSource::ChatsList); Window::PeerMenuSource::ChatsList);
} else if (const auto feed = key.feed()) { } else if (const auto feed = row.key.feed()) {
Window::FillFeedMenu( Window::FillFeedMenu(
_controller, _controller,
feed, feed,
@ -1559,9 +1586,9 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) {
}, },
Window::PeerMenuSource::ChatsList); Window::PeerMenuSource::ChatsList);
} }
connect(_menu.get(), &QObject::destroyed, [this] { connect(_menu.get(), &QObject::destroyed, [=] {
if (_menuKey) { if (_menuRow.key) {
updateSelectedRow(base::take(_menuKey)); updateDialogRow(base::take(_menuRow));
} }
const auto globalPosition = QCursor::pos(); const auto globalPosition = QCursor::pos();
if (rect().contains(mapFromGlobal(globalPosition))) { if (rect().contains(mapFromGlobal(globalPosition))) {
@ -1868,7 +1895,7 @@ void DialogsInner::addAllSavedPeers() {
bool DialogsInner::uniqueSearchResults() const { bool DialogsInner::uniqueSearchResults() const {
return Auth().supportMode() return Auth().supportMode()
&& _filter.startsWith('#') && !Auth().settings().supportAllSearchResults()
&& !_searchInChat; && !_searchInChat;
} }

View File

@ -222,8 +222,9 @@ private:
void updateSearchResult(not_null<PeerData*> peer); void updateSearchResult(not_null<PeerData*> peer);
void updateDialogRow( void updateDialogRow(
Dialogs::RowDescriptor row, Dialogs::RowDescriptor row,
QRect updateRect, QRect updateRect = QRect(),
UpdateRowSections sections = UpdateRowSection::All); UpdateRowSections sections = UpdateRowSection::All);
void fillSupportSearchMenu(not_null<Ui::PopupMenu*> menu);
int dialogsOffset() const; int dialogsOffset() const;
int proxyPromotedCount() const; int proxyPromotedCount() const;
@ -368,7 +369,7 @@ private:
UserData *_searchFromUser = nullptr; UserData *_searchFromUser = nullptr;
Text _searchInChatText; Text _searchInChatText;
Text _searchFromUserText; Text _searchFromUserText;
Dialogs::Key _menuKey; Dialogs::RowDescriptor _menuRow;
Fn<void()> _loadMoreCallback; Fn<void()> _loadMoreCallback;
rpl::event_stream<> _listBottomReached; rpl::event_stream<> _listBottomReached;

View File

@ -237,7 +237,7 @@ DialogsWidget::DialogsWidget(QWidget *parent, not_null<Window::Controller*> cont
updateJumpToDateVisibility(true); updateJumpToDateVisibility(true);
updateSearchFromVisibility(true); updateSearchFromVisibility(true);
setupConnectingWidget(); setupConnectingWidget();
setupSupportLoadingLimit(); setupSupportMode();
} }
void DialogsWidget::setupConnectingWidget() { void DialogsWidget::setupConnectingWidget() {
@ -246,15 +246,28 @@ void DialogsWidget::setupConnectingWidget() {
Window::AdaptiveIsOneColumn()); Window::AdaptiveIsOneColumn());
} }
void DialogsWidget::setupSupportLoadingLimit() { void DialogsWidget::setupSupportMode() {
if (!Auth().supportMode()) { if (!Auth().supportMode()) {
return; return;
} }
Auth().settings().supportChatsTimeSliceValue( Auth().settings().supportChatsTimeSliceValue(
) | rpl::start_with_next([=](int seconds) { ) | rpl::start_with_next([=](int seconds) {
_dialogsLoadTill = seconds ? std::max(unixtime() - seconds, 0) : 0; _dialogsLoadTill = seconds ? std::max(unixtime() - seconds, 0) : 0;
refreshLoadMoreButton(); refreshLoadMoreButton();
}, lifetime()); }, 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() { void DialogsWidget::checkUpdateStatus() {
@ -1474,7 +1487,6 @@ void DialogsWidget::scrollToEntry(const Dialogs::RowDescriptor &entry) {
void DialogsWidget::removeDialog(Dialogs::Key key) { void DialogsWidget::removeDialog(Dialogs::Key key) {
_inner->removeDialog(key); _inner->removeDialog(key);
applyFilterUpdate(true);
} }
Dialogs::IndexedList *DialogsWidget::contactsList() { Dialogs::IndexedList *DialogsWidget::contactsList() {

View File

@ -146,7 +146,7 @@ private:
const QVector<MTPDialog> &dialogs, const QVector<MTPDialog> &dialogs,
const QVector<MTPMessage> &messages); const QVector<MTPMessage> &messages);
void setupSupportLoadingLimit(); void setupSupportMode();
void setupConnectingWidget(); void setupConnectingWidget();
bool searchForPeersRequired(const QString &query) const; bool searchForPeersRequired(const QString &query) const;
void setSearchInChat(Dialogs::Key chat, UserData *from = nullptr); void setSearchInChat(Dialogs::Key chat, UserData *from = nullptr);