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:
@@ -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();
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user