mirror of https://github.com/procxx/kepka.git
Try to fix a crash in pinned reordering.
This commit is contained in:
parent
87bf0654a2
commit
1f16ac59ca
|
@ -393,11 +393,11 @@ bool ChatFilters::applyChange(ChatFilter &filter, ChatFilter &&updated) {
|
|||
});
|
||||
}
|
||||
}
|
||||
filter = std::move(updated);
|
||||
if (pinnedChanged) {
|
||||
const auto filterList = _owner->chatsFilters().chatsList(id);
|
||||
filterList->pinned()->applyList(updated.pinned());
|
||||
filterList->pinned()->applyList(filter.pinned());
|
||||
}
|
||||
filter = std::move(updated);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ int PinnedList::addPinnedGetPosition(const Key &key) {
|
|||
}
|
||||
|
||||
void PinnedList::setPinned(const Key &key, bool pinned) {
|
||||
Expects(key.entry()->folderKnown());
|
||||
Expects(key.entry()->folderKnown() || _filterId != 0);
|
||||
|
||||
if (pinned) {
|
||||
const int position = addPinnedGetPosition(key);
|
||||
|
@ -100,7 +100,8 @@ void PinnedList::applyList(
|
|||
void PinnedList::applyList(const std::vector<not_null<History*>> &list) {
|
||||
Expects(_filterId != 0);
|
||||
|
||||
clear();
|
||||
const auto old = base::take(_data);
|
||||
|
||||
const auto count = int(list.size());
|
||||
_data.reserve(count);
|
||||
for (auto i = 0; i != count; ++i) {
|
||||
|
@ -108,6 +109,13 @@ void PinnedList::applyList(const std::vector<not_null<History*>> &list) {
|
|||
_data.emplace_back(history);
|
||||
history->cachePinnedIndex(_filterId, i + 1);
|
||||
}
|
||||
|
||||
for (const auto &key : old) {
|
||||
const auto history = key.history();
|
||||
if (!history || !ranges::contains(_data, history, &Key::history)) {
|
||||
key.entry()->cachePinnedIndex(_filterId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PinnedList::reorder(const Key &key1, const Key &key2) {
|
||||
|
|
Loading…
Reference in New Issue