[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.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<int> 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<bool> AuthSessionSettings::supportAllSearchResultsValue() const {
return _variables.supportAllSearchResults.value();
}
void AuthSessionSettings::setTabbedSelectorSectionEnabled(bool enabled) {
_variables.tabbedSelectorSectionEnabled = enabled;
if (enabled) {

View File

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

View File

@ -146,9 +146,7 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> 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<Window::Controller*> 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 &region, 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 &region, 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 &region, 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*> 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<PeerData*> 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<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) {
_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<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(
_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;
}

View File

@ -222,8 +222,9 @@ private:
void updateSearchResult(not_null<PeerData*> peer);
void updateDialogRow(
Dialogs::RowDescriptor row,
QRect updateRect,
QRect updateRect = QRect(),
UpdateRowSections sections = UpdateRowSection::All);
void fillSupportSearchMenu(not_null<Ui::PopupMenu*> 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<void()> _loadMoreCallback;
rpl::event_stream<> _listBottomReached;

View File

@ -237,7 +237,7 @@ DialogsWidget::DialogsWidget(QWidget *parent, not_null<Window::Controller*> 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() {

View File

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