Refresh filter chats count in filter settings.

This commit is contained in:
John Preston 2020-03-25 17:28:59 +04:00
parent fe73251d8e
commit fdabdc3626
3 changed files with 60 additions and 6 deletions

View File

@ -67,7 +67,7 @@ Folder::Folder(not_null<Data::Session*> owner, FolderId id)
for (const auto history : _lastHistories) {
if (history->peer == update.peer) {
++_chatListViewVersion;
updateChatListEntry();
updateChatListEntryPostponed();
return;
}
}
@ -81,15 +81,26 @@ Folder::Folder(not_null<Data::Session*> owner, FolderId id)
}) | rpl::start_with_next([=](const Dialogs::UnreadState &old) {
++_chatListViewVersion;
notifyUnreadStateChange(old);
updateChatListEntry();
updateChatListEntryPostponed();
}, _lifetime);
_chatsList.fullSize().changes(
) | rpl::start_with_next([=] {
updateChatListEntry();
updateChatListEntryPostponed();
}, _lifetime);
}
void Folder::updateChatListEntryPostponed() {
if (_updateChatListEntryPostponed) {
return;
}
_updateChatListEntryPostponed = true;
Ui::PostponeCall(this, [=] {
updateChatListEntry();
_updateChatListEntryPostponed = false;
});
}
FolderId Folder::id() const {
return _id;
}

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_entry.h"
#include "dialogs/dialogs_main_list.h"
#include "data/data_messages.h"
#include "base/weak_ptr.h"
class ChannelData;
@ -24,7 +25,7 @@ class Folder;
//MessagePosition FeedPositionFromMTP(const MTPFeedPosition &position); // #feed
class Folder final : public Dialogs::Entry {
class Folder final : public Dialogs::Entry, public base::has_weak_ptr {
public:
static constexpr auto kId = 1;
@ -84,6 +85,7 @@ private:
void computeChatListMessage();
void reorderLastHistories();
void updateChatListEntryPostponed();
void paintUserpic(
Painter &p,
@ -103,6 +105,7 @@ private:
std::vector<not_null<History*>> _lastHistories;
HistoryItem *_chatListMessage = nullptr;
uint32 _chatListViewVersion = 0;
bool _updateChatListEntryPostponed = false;
//rpl::variable<MessagePosition> _unreadPosition;
rpl::lifetime _lifetime;

View File

@ -56,6 +56,7 @@ public:
void setRemoved(bool removed);
void updateData(const Data::ChatFilter &filter);
void updateCount(const Data::ChatFilter &filter);
[[nodiscard]] rpl::producer<> removeRequests() const;
[[nodiscard]] rpl::producer<> restoreRequests() const;
@ -100,6 +101,7 @@ struct FilterRow {
Data::ChatFilter filter;
bool removed = false;
bool added = false;
bool postponedCountUpdate = false;
};
[[nodiscard]] int CountFilterChats(
@ -193,8 +195,12 @@ void FilterRowButton::updateData(const Data::ChatFilter &filter) {
Expects(_session != nullptr);
_title.setText(st::contactsNameStyle, filter.title());
_status = ComputeCountString(_session, filter, true);
_icon = Ui::ComputeFilterIcon(filter);
updateCount(filter);
}
void FilterRowButton::updateCount(const Data::ChatFilter &filter) {
_status = ComputeCountString(_session, filter, true);
update();
}
@ -323,7 +329,8 @@ void FilterRowButton::paintEvent(QPaintEvent *e) {
controller->window().showToast(tr::lng_filters_limit(tr::now));
return true;
};
const auto wrap = container->add(object_ptr<Ui::VerticalLayout>(container));
const auto wrap = container->add(object_ptr<Ui::VerticalLayout>(
container));
const auto addFilter = [=](const Data::ChatFilter &filter) {
const auto button = wrap->add(
object_ptr<FilterRowButton>(wrap, session, filter));
@ -358,6 +365,39 @@ void FilterRowButton::paintEvent(QPaintEvent *e) {
rows->push_back({ button, filter });
*rowsCount = rows->size();
const auto filters = &controller->session().data().chatsFilters();
const auto id = filter.id();
if (ranges::contains(filters->list(), id, &Data::ChatFilter::id)) {
filters->chatsList(id)->fullSize().changes(
) | rpl::start_with_next([=] {
const auto found = find(button);
if (found->postponedCountUpdate) {
return;
}
found->postponedCountUpdate = true;
Ui::PostponeCall(button, [=] {
const auto &list = filters->list();
const auto i = ranges::find(
list,
id,
&Data::ChatFilter::id);
if (i == end(list)) {
return;
}
const auto found = find(button);
const auto &real = *i;
const auto &now = found->filter;
if ((i->flags() != found->filter.flags())
|| (i->always() != found->filter.always())
|| (i->never() != found->filter.never())) {
return;
}
button->updateCount(found->filter);
found->postponedCountUpdate = false;
});
}, button->lifetime());
}
wrap->resizeToWidth(container->width());
};
const auto &list = session->data().chatsFilters().list();