2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Update API: support "All Chats" reordering.

This commit is contained in:
John Preston
2022-05-17 13:24:35 +04:00
parent 73bacfc650
commit fe91887ea2
13 changed files with 113 additions and 36 deletions

View File

@@ -107,6 +107,8 @@ ChatFilter ChatFilter::FromTL(
std::move(list),
std::move(pinned),
{ never.begin(), never.end() });
}, [](const MTPDdialogFilterDefault &d) {
return ChatFilter();
});
}
@@ -220,6 +222,7 @@ bool ChatFilter::contains(not_null<History*> history) const {
}
ChatFilters::ChatFilters(not_null<Session*> owner) : _owner(owner) {
_list.emplace_back();
crl::on_main(&owner->session(), [=] { load(); });
}
@@ -295,6 +298,9 @@ void ChatFilters::received(const QVector<MTPDialogFilter> &list) {
applyRemove(position);
changed = true;
}
if (!ranges::contains(begin(_list), end(_list), 0, &ChatFilter::id)) {
_list.insert(begin(_list), ChatFilter());
}
if (changed || !_loaded) {
_loaded = true;
_listChanged.fire({});
@@ -352,6 +358,16 @@ void ChatFilters::remove(FilterId id) {
_listChanged.fire({});
}
void ChatFilters::moveAllToFront() {
const auto i = ranges::find(_list, FilterId(), &ChatFilter::id);
if (!_list.empty() && i == begin(_list)) {
return;
} else if (i != end(_list)) {
_list.erase(i);
}
_list.insert(begin(_list), ChatFilter());
}
void ChatFilters::applyRemove(int position) {
Expects(position >= 0 && position < _list.size());
@@ -518,6 +534,10 @@ const std::vector<ChatFilter> &ChatFilters::list() const {
return _list;
}
bool ChatFilters::has() const {
return _list.size() > 1;
}
rpl::producer<> ChatFilters::changed() const {
return _listChanged.events();
}

View File

@@ -99,8 +99,10 @@ public:
void apply(const MTPUpdate &update);
void set(ChatFilter filter);
void remove(FilterId id);
void moveAllToFront();
[[nodiscard]] const std::vector<ChatFilter> &list() const;
[[nodiscard]] rpl::producer<> changed() const;
[[nodiscard]] bool has() const;
bool loadNextExceptions(bool chatsListLoaded);

View File

@@ -268,7 +268,7 @@ Session::Session(not_null<Main::Session*> session)
_chatsFilters->changed(
) | rpl::start_with_next([=] {
const auto enabled = !_chatsFilters->list().empty();
const auto enabled = _chatsFilters->has();
if (enabled != session->settings().dialogsFiltersEnabled()) {
session->settings().setDialogsFiltersEnabled(enabled);
session->saveSettingsDelayed();