Refresh filtered results on more dialogs.

This commit is contained in:
John Preston 2018-12-29 12:11:54 +04:00
parent df389a365c
commit 219b824338
8 changed files with 50 additions and 30 deletions

View File

@ -215,7 +215,7 @@ void ShareBox::prepare() {
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
_select->setQueryChangedCallback([=](const QString &query) {
onFilterUpdate(query);
applyFilterUpdate(query);
});
_select->setItemRemovedCallback([=](uint64 itemId) {
if (const auto peer = App::peerLoaded(itemId)) {
@ -403,7 +403,7 @@ void ShareBox::createButtons() {
addButton(langFactory(lng_cancel), [=] { closeBox(); });
}
void ShareBox::onFilterUpdate(const QString &query) {
void ShareBox::applyFilterUpdate(const QString &query) {
onScrollToY(0);
_inner->updateFilter(query);
}

View File

@ -60,7 +60,7 @@ private:
void scrollTo(Ui::ScrollToRequest request);
void needSearchByUsername();
void onFilterUpdate(const QString &query);
void applyFilterUpdate(const QString &query);
void selectedChanged();
void createButtons();
int getTopScrollSkip() const;

View File

@ -1598,7 +1598,7 @@ void DialogsInner::handlePeerNameChange(
update();
}
void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
void DialogsInner::applyFilterUpdate(QString newFilter, bool force) {
const auto mentionsSearch = (newFilter == qstr("@"));
const auto words = mentionsSearch
? QStringList(newFilter)

View File

@ -88,7 +88,7 @@ public:
void searchInChat(Dialogs::Key key, UserData *from);
void onFilterUpdate(QString newFilter, bool force = false);
void applyFilterUpdate(QString newFilter, bool force = false);
void onHashtagFilterUpdate(QStringRef newFilter);
PeerData *updateFromParentDrag(QPoint globalPosition);

View File

@ -165,13 +165,20 @@ DialogsWidget::DialogsWidget(QWidget *parent, not_null<Window::Controller*> cont
connect(_inner, SIGNAL(cancelSearchInChat()), this, SLOT(onCancelSearchInChat()));
subscribe(_inner->searchFromUserChanged, [this](UserData *user) {
setSearchInChat(_searchInChat, user);
onFilterUpdate(true);
applyFilterUpdate(true);
});
connect(_scroll, SIGNAL(geometryChanged()), _inner, SLOT(onParentGeometryChanged()));
connect(_scroll, SIGNAL(scrolled()), this, SLOT(onListScroll()));
connect(_filter, SIGNAL(cancelled()), this, SLOT(onCancel()));
connect(_filter, SIGNAL(changed()), this, SLOT(onFilterUpdate()));
connect(_filter, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(onFilterCursorMoved(int,int)));
connect(_filter, &Ui::FlatInput::cancelled, [=] {
onCancel();
});
connect(_filter, &Ui::FlatInput::changed, [=] {
applyFilterUpdate();
});
connect(
_filter,
&Ui::FlatInput::cursorPositionChanged,
[=](int from, int to) { onFilterCursorMoved(from, to); });
if (!Core::UpdaterDisabled()) {
Core::UpdateChecker checker;
@ -395,7 +402,7 @@ void DialogsWidget::animationCallback() {
updateJumpToDateVisibility(true);
updateSearchFromVisibility(true);
onFilterUpdate();
applyFilterUpdate();
if (App::wnd()) App::wnd()->setInnerFocus();
}
}
@ -442,6 +449,7 @@ void DialogsWidget::dialogsReceived(
if (!_dialogsRequestId) {
refreshLoadMoreButton();
}
refreshSupportFilteredResults();
Auth().data().moreChatsLoaded().notify();
if (_dialogsFull && _pinnedDialogsReceived) {
@ -450,6 +458,15 @@ void DialogsWidget::dialogsReceived(
Auth().api().requestContacts();
}
void DialogsWidget::refreshSupportFilteredResults() {
if (!Auth().supportMode()) {
return;
}
const auto top = _scroll->scrollTop();
applyFilterUpdate(true);
_scroll->scrollToY(top);
}
void DialogsWidget::updateDialogsOffset(
const QVector<MTPDialog> &dialogs,
const QVector<MTPMessage> &messages) {
@ -741,7 +758,7 @@ void DialogsWidget::searchMessages(
}
_filter->setText(query);
_filter->updatePlaceholder();
onFilterUpdate(true);
applyFilterUpdate(true);
_searchTimer.stop();
onSearchMessages();
@ -1115,11 +1132,11 @@ void DialogsWidget::onListScroll() {
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
}
void DialogsWidget::onFilterUpdate(bool force) {
void DialogsWidget::applyFilterUpdate(bool force) {
if (_a_show.animating() && !force) return;
auto filterText = _filter->getLastText();
_inner->onFilterUpdate(filterText, force);
_inner->applyFilterUpdate(filterText, force);
if (filterText.isEmpty() && !_searchFromUser) {
clearSearchCache();
}
@ -1146,7 +1163,7 @@ void DialogsWidget::onFilterUpdate(bool force) {
void DialogsWidget::searchInChat(Dialogs::Key chat) {
onCancelSearch();
setSearchInChat(chat);
onFilterUpdate(true);
applyFilterUpdate(true);
}
void DialogsWidget::setSearchInChat(Dialogs::Key chat, UserData *from) {
@ -1202,7 +1219,7 @@ void DialogsWidget::showSearchFrom() {
crl::guard(this, [=](not_null<UserData*> user) {
Ui::hideLayer();
setSearchInChat(chat, user);
onFilterUpdate(true);
applyFilterUpdate(true);
}),
crl::guard(this, [=] { _filter->setFocus(); }));
}
@ -1239,7 +1256,7 @@ void DialogsWidget::onCompleteHashtag(QString tag) {
r = t.mid(0, start + 1) + tag + ' ' + t.mid(cur);
_filter->setText(r);
_filter->setCursorPosition(start + 1 + tag.size() + 1);
onFilterUpdate(true);
applyFilterUpdate(true);
return;
}
break;
@ -1248,7 +1265,7 @@ void DialogsWidget::onCompleteHashtag(QString tag) {
}
_filter->setText(t.mid(0, cur) + '#' + tag + ' ' + t.mid(cur));
_filter->setCursorPosition(cur + 1 + tag.size() + 1);
onFilterUpdate(true);
applyFilterUpdate(true);
}
void DialogsWidget::resizeEvent(QResizeEvent *e) {
@ -1451,7 +1468,7 @@ void DialogsWidget::scrollToEntry(const Dialogs::RowDescriptor &entry) {
void DialogsWidget::removeDialog(Dialogs::Key key) {
_inner->removeDialog(key);
onFilterUpdate();
applyFilterUpdate(true);
}
Dialogs::IndexedList *DialogsWidget::contactsList() {
@ -1488,7 +1505,7 @@ bool DialogsWidget::onCancelSearch() {
_inner->clearFilter();
_filter->clear();
_filter->updatePlaceholder();
onFilterUpdate();
applyFilterUpdate();
return clearing;
}
@ -1512,7 +1529,7 @@ void DialogsWidget::onCancelSearchInChat() {
_inner->clearFilter();
_filter->clear();
_filter->updatePlaceholder();
onFilterUpdate();
applyFilterUpdate();
if (!Adaptive::OneColumn() && !App::main()->selectingPeer()) {
emit cancelled();
}

View File

@ -100,7 +100,6 @@ public slots:
void onCancel();
void onListScroll();
void activate();
void onFilterUpdate(bool force = false);
bool onCancelSearch();
void onCancelSearchInChat();
@ -162,6 +161,8 @@ private:
void updateForwardBar();
void checkUpdateStatus();
void applyFilterUpdate(bool force = false);
void refreshSupportFilteredResults();
bool loadingBlockedByDate() const;
void refreshLoadMoreButton();

View File

@ -234,15 +234,19 @@ void CountrySelectBox::prepare() {
setTitle(langFactory(lng_country_select));
_select->resizeToWidth(st::boxWidth);
_select->setQueryChangedCallback([this](const QString &query) { onFilterUpdate(query); });
_select->setSubmittedCallback([this](Qt::KeyboardModifiers) { onSubmit(); });
_select->setQueryChangedCallback([=](const QString &query) {
applyFilterUpdate(query);
});
_select->setSubmittedCallback([=](Qt::KeyboardModifiers) {
submit();
});
_inner = setInnerWidget(
object_ptr<Inner>(this, _type),
st::countriesScroll,
_select->height());
addButton(langFactory(lng_close), [this] { closeBox(); });
addButton(langFactory(lng_close), [=] { closeBox(); });
setDimensions(st::boxWidth, st::boxMaxListHeight);
@ -250,7 +254,7 @@ void CountrySelectBox::prepare() {
connect(_inner, SIGNAL(countryChosen(const QString&)), this, SIGNAL(countryChosen(const QString&)));
}
void CountrySelectBox::onSubmit() {
void CountrySelectBox::submit() {
_inner->chooseCountry();
}
@ -277,7 +281,7 @@ void CountrySelectBox::resizeEvent(QResizeEvent *e) {
_inner->resizeToWidth(width());
}
void CountrySelectBox::onFilterUpdate(const QString &query) {
void CountrySelectBox::applyFilterUpdate(const QString &query) {
onScrollToY(0);
_inner->updateFilter(query);
}

View File

@ -77,11 +77,9 @@ protected:
void keyPressEvent(QKeyEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private slots:
void onSubmit();
private:
void onFilterUpdate(const QString &query);
void submit();
void applyFilterUpdate(const QString &query);
Type _type = Type::Phones;
object_ptr<Ui::MultiSelect> _select;