diff --git a/Telegram/SourceFiles/countries/countries_instance.cpp b/Telegram/SourceFiles/countries/countries_instance.cpp index 91805a707..69deb65b1 100644 --- a/Telegram/SourceFiles/countries/countries_instance.cpp +++ b/Telegram/SourceFiles/countries/countries_instance.cpp @@ -262,6 +262,7 @@ void CountriesInstance::setList(std::vector &&infos) { _list = std::move(infos); _byCode.clear(); _byISO2.clear(); + _updated.fire({}); } const CountriesInstance::Map &CountriesInstance::byCode() { @@ -454,6 +455,10 @@ FormatResult CountriesInstance::format(FormatArgs args) { }; } +rpl::producer<> CountriesInstance::updated() const { + return _updated.events(); +} + CountriesInstance &Instance() { return SingleInstance; } diff --git a/Telegram/SourceFiles/countries/countries_instance.h b/Telegram/SourceFiles/countries/countries_instance.h index b57b172fc..6052377b2 100644 --- a/Telegram/SourceFiles/countries/countries_instance.h +++ b/Telegram/SourceFiles/countries/countries_instance.h @@ -55,12 +55,16 @@ public: [[nodiscard]] FormatResult format(FormatArgs args); + [[nodiscard]] rpl::producer<> updated() const; + private: std::vector _list; Map _byCode; Map _byISO2; + rpl::event_stream<> _updated; + }; CountriesInstance &Instance(); diff --git a/Telegram/SourceFiles/ui/boxes/country_select_box.cpp b/Telegram/SourceFiles/ui/boxes/country_select_box.cpp index cf4bd93e8..e122b50ee 100644 --- a/Telegram/SourceFiles/ui/boxes/country_select_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/country_select_box.cpp @@ -26,7 +26,7 @@ QString LastValidISO; } // namespace -class CountrySelectBox::Inner : public TWidget { +class CountrySelectBox::Inner : public RpWidget { public: Inner(QWidget *parent, const QString &iso, Type type); ~Inner(); @@ -57,6 +57,7 @@ protected: void mouseReleaseEvent(QMouseEvent *e) override; private: + void init(); void updateSelected() { updateSelected(mapFromGlobal(QCursor::pos())); } @@ -179,7 +180,7 @@ CountrySelectBox::Inner::Inner( QWidget *parent, const QString &iso, Type type) -: TWidget(parent) +: RpWidget(parent) , _type(type) , _rowHeight(st::countryRowHeight) { setAttribute(Qt::WA_OpaquePaintEvent); @@ -190,6 +191,23 @@ CountrySelectBox::Inner::Inner( LastValidISO = iso; } + rpl::single( + ) | rpl::then( + Countries::Instance().updated() + ) | rpl::start_with_next([=] { + _mustScrollTo.fire(ScrollToRequest(0, 0)); + _list.clear(); + _namesList.clear(); + init(); + const auto filter = _filter; + _filter = u"a"_q; + updateFilter(filter); + }, lifetime()); +} + +void CountrySelectBox::Inner::init() { + const auto &byISO2 = Countries::Instance().byISO2(); + const auto extractEntries = [&](const Countries::Info &info) { for (const auto &code : info.codes) { _list.push_back(Entry{ @@ -241,9 +259,6 @@ CountrySelectBox::Inner::Inner( } ++index; } - - _filter = u"a"_q; - updateFilter(); } void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) {