Fix crashes in filter chats list editing.

This commit is contained in:
John Preston 2020-03-18 17:00:53 +04:00
parent 455d113955
commit 36b9911995
4 changed files with 27 additions and 41 deletions

View file

@ -44,12 +44,7 @@ public:
QString generateName() override;
QString generateShortName() override;
void paintEntityUserpicLeft(
Painter &p,
int x,
int y,
int outerWidth,
int size) override;
PaintRoundImageCallback generatePaintUserpicCallback() override;
private:
[[nodiscard]] Flag flag() const;
@ -144,13 +139,11 @@ QString TypeRow::generateShortName() {
return generateName();
}
void TypeRow::paintEntityUserpicLeft(
Painter &p,
int x,
int y,
int outerWidth,
int size) {
PaintFilterChatsTypeIcon(p, flag(), x, y, outerWidth, size);
PaintRoundImageCallback TypeRow::generatePaintUserpicCallback() {
const auto flag = this->flag();
return [=](Painter &p, int x, int y, int outerWidth, int size) {
PaintFilterChatsTypeIcon(p, flag, x, y, outerWidth, size);
};
}
Flag TypeRow::flag() const {

View file

@ -345,13 +345,12 @@ void ManageFiltersPrepare::SetupBox(
AddSubsectionTitle(content, tr::lng_filters_subtitle());
const auto rows = box->lifetime().make_state<std::vector<FilterRow>>();
const auto rowsCount = box->lifetime().make_state<rpl::variable<int>>();
const auto find = [=](not_null<FilterRowButton*> button) {
const auto i = ranges::find(*rows, button, &FilterRow::button);
Assert(i != end(*rows));
return &*i;
};
const auto countNonRemoved = [=] {
};
const auto showLimitReached = [=] {
const auto removed = ranges::count_if(*rows, &FilterRow::removed);
if (rows->size() < kFiltersLimit + removed) {
@ -393,6 +392,7 @@ void ManageFiltersPrepare::SetupBox(
crl::guard(button, doneCallback)));
});
rows->push_back({ button, filter });
*rowsCount = rows->size();
wrap->resizeToWidth(content->width());
};
@ -462,8 +462,14 @@ void ManageFiltersPrepare::SetupBox(
}
using namespace rpl::mappers;
emptyAbout->toggleOn(suggested->value() | rpl::map(_1 == 0));
nonEmptyAbout->toggleOn(suggested->value() | rpl::map(_1 > 0));
auto showSuggestions = rpl::combine(
suggested->value(),
rowsCount->value()
) | rpl::map(_1 > 0 && _2 < kFiltersLimit);
emptyAbout->toggleOn(rpl::duplicate(
showSuggestions
) | rpl::map(!_1));
nonEmptyAbout->toggleOn(std::move(showSuggestions));
const auto prepareGoodIdsForNewFilters = [=] {
const auto &list = session->data().chatsFilters().list();

View file

@ -484,24 +484,17 @@ QString PeerListRow::generateShortName() {
}
PaintRoundImageCallback PeerListRow::generatePaintUserpicCallback() {
const auto saved = _isSavedMessagesChat;
const auto peer = this->peer();
return [=](Painter &p, int x, int y, int outerWidth, int size) {
paintEntityUserpicLeft(p, x, y, outerWidth, size);
if (saved) {
Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, size);
} else {
peer->paintUserpicLeft(p, x, y, outerWidth, size);
}
};
}
void PeerListRow::paintEntityUserpicLeft(
Painter &p,
int x,
int y,
int outerWidth,
int size) {
if (_isSavedMessagesChat) {
Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, size);
} else {
peer()->paintUserpicLeft(p, x, y, outerWidth, size);
}
}
void PeerListRow::invalidatePixmapsCache() {
if (_checkbox) {
_checkbox->invalidateCache();
@ -571,8 +564,8 @@ void PeerListRow::paintUserpic(
paintDisabledCheckUserpic(p, st, x, y, outerWidth);
} else if (_checkbox) {
_checkbox->paint(p, x, y, outerWidth);
} else {
paintEntityUserpicLeft(p, x, y, outerWidth, st.photoSize);
} else if (const auto callback = generatePaintUserpicCallback()) {
callback(p, x, y, outerWidth, st.photoSize);
}
}

View file

@ -87,7 +87,8 @@ public:
[[nodiscard]] virtual QString generateName();
[[nodiscard]] virtual QString generateShortName();
[[nodiscard]] PaintRoundImageCallback generatePaintUserpicCallback();
[[nodiscard]] virtual auto generatePaintUserpicCallback()
-> PaintRoundImageCallback;
void setCustomStatus(const QString &status);
void clearCustomStatus();
@ -207,13 +208,6 @@ protected:
explicit PeerListRow(PeerListRowId id);
virtual void paintEntityUserpicLeft(
Painter &p,
int x,
int y,
int outerWidth,
int size);
private:
void createCheckbox(
const style::RoundImageCheckbox &st,