diff --git a/Telegram/SourceFiles/api/api_chat_filters.cpp b/Telegram/SourceFiles/api/api_chat_filters.cpp index 8af6a2fa5..68b0dbebe 100644 --- a/Telegram/SourceFiles/api/api_chat_filters.cpp +++ b/Telegram/SourceFiles/api/api_chat_filters.cpp @@ -32,20 +32,4 @@ void SaveNewFilterPinned( } -void SaveNewOrder( - not_null session, - const std::vector &order) { - auto &filters = session->data().chatsFilters(); - auto ids = QVector(); - ids.reserve(order.size()); - for (const auto id : order) { - ids.push_back(MTP_int(id)); - } - const auto wrapped = MTP_vector(ids); - filters.apply(MTP_updateDialogFilterOrder(wrapped)); - session->api().request(MTPmessages_UpdateDialogFiltersOrder( - wrapped - )).send(); -} - } // namespace Api diff --git a/Telegram/SourceFiles/api/api_chat_filters.h b/Telegram/SourceFiles/api/api_chat_filters.h index 893002586..59c29f72b 100644 --- a/Telegram/SourceFiles/api/api_chat_filters.h +++ b/Telegram/SourceFiles/api/api_chat_filters.h @@ -17,8 +17,4 @@ void SaveNewFilterPinned( not_null session, FilterId filterId); -void SaveNewOrder( - not_null session, - const std::vector &order); - } // namespace Api diff --git a/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp b/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp index 2a60c9873..102976472 100644 --- a/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp @@ -501,7 +501,8 @@ void ManageFiltersPrepare::SetupBox( auto addRequests = Requests(), removeRequests = Requests(); auto &realFilters = session->data().chatsFilters(); const auto &list = realFilters.list(); - auto order = QVector(); + auto order = std::vector(); + order.reserve(rows->size()); for (const auto &row : *rows) { const auto id = row.filter.id(); const auto removed = row.removed; @@ -509,7 +510,7 @@ void ManageFiltersPrepare::SetupBox( if (removed && i == end(list)) { continue; } else if (!removed && i != end(list) && *i == row.filter) { - order.push_back(MTP_int(id)); + order.push_back(id); continue; } const auto newId = ids.take(row.button).value_or(id); @@ -526,7 +527,7 @@ void ManageFiltersPrepare::SetupBox( removeRequests.push_back(request); } else { addRequests.push_back(request); - order.push_back(MTP_int(newId)); + order.push_back(newId); } realFilters.apply(MTP_updateDialogFilter( MTP_flags(removed @@ -542,12 +543,8 @@ void ManageFiltersPrepare::SetupBox( std::move(request) ).afterRequest(previousId).send(); } - if (!order.isEmpty() && !addRequests.empty()) { - realFilters.apply( - MTP_updateDialogFilterOrder(MTP_vector(order))); - session->api().request(MTPmessages_UpdateDialogFiltersOrder( - MTP_vector(order) - )).afterRequest(previousId).send(); + if (!order.empty() && !addRequests.empty()) { + realFilters.saveOrder(order, previousId); } box->closeBox(); }; diff --git a/Telegram/SourceFiles/data/data_chat_filters.cpp b/Telegram/SourceFiles/data/data_chat_filters.cpp index e4f28f2c6..f14a5e0a7 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.cpp +++ b/Telegram/SourceFiles/data/data_chat_filters.cpp @@ -451,6 +451,28 @@ const ChatFilter &ChatFilters::applyUpdatedPinned( return *i; } +void ChatFilters::saveOrder( + const std::vector &order, + mtpRequestId after) { + if (after) { + _saveOrderAfterId = after; + } + const auto api = &_owner->session().api(); + api->request(_saveOrderRequestId).cancel(); + + auto ids = QVector(); + ids.reserve(order.size()); + for (const auto id : order) { + ids.push_back(MTP_int(id)); + } + const auto wrapped = MTP_vector(ids); + + apply(MTP_updateDialogFilterOrder(wrapped)); + _saveOrderRequestId = api->request(MTPmessages_UpdateDialogFiltersOrder( + wrapped + )).afterRequest(_saveOrderAfterId).send(); +} + bool ChatFilters::archiveNeeded() const { for (const auto &filter : _list) { if (!(filter.flags() & ChatFilter::Flag::NoArchived)) { diff --git a/Telegram/SourceFiles/data/data_chat_filters.h b/Telegram/SourceFiles/data/data_chat_filters.h index 8e4cd95cd..c6e15d7f1 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.h +++ b/Telegram/SourceFiles/data/data_chat_filters.h @@ -106,6 +106,9 @@ public: const ChatFilter &applyUpdatedPinned( FilterId id, const std::vector &dialogs); + void saveOrder( + const std::vector &order, + mtpRequestId after = 0); [[nodiscard]] bool archiveNeeded() const; @@ -123,6 +126,8 @@ private: rpl::event_stream<> _listChanged; rpl::event_stream> _refreshHistoryRequests; mtpRequestId _loadRequestId = 0; + mtpRequestId _saveOrderRequestId = 0; + mtpRequestId _saveOrderAfterId = 0; bool _loaded = false; }; diff --git a/Telegram/SourceFiles/window/window_filters_menu.cpp b/Telegram/SourceFiles/window/window_filters_menu.cpp index 795169e52..e035c1b4a 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.cpp +++ b/Telegram/SourceFiles/window/window_filters_menu.cpp @@ -99,7 +99,7 @@ void FiltersMenu::setup() { void FiltersMenu::refresh() { const auto filters = &_session->session().data().chatsFilters(); - if (filters->list().empty()) { + if (filters->list().empty() || _ignoreRefresh) { return; } @@ -220,7 +220,10 @@ void FiltersMenu::applyReorder( &Data::ChatFilter::id ) | ranges::to_vector; base::reorder(order, oldPosition, newPosition); - Api::SaveNewOrder(&_session->session(), order); + + _ignoreRefresh = true; + filters->saveOrder(order); + _ignoreRefresh = false; } } // namespace Window diff --git a/Telegram/SourceFiles/window/window_filters_menu.h b/Telegram/SourceFiles/window/window_filters_menu.h index 9ebbaec5b..eceb23ff0 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.h +++ b/Telegram/SourceFiles/window/window_filters_menu.h @@ -57,6 +57,7 @@ private: base::flat_map> _filters; FilterId _activeFilterId = 0; int _reordering = 0; + bool _ignoreRefresh = false; }; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index b051948e6..eaab3f9a8 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit b051948e6947b97394df9f0f8b24e8bf407e596c +Subproject commit eaab3f9a8a5a1bc429449a9a40c0798f2203947b