Fixed tags display when color of chats filter tag is toggled.

This commit is contained in:
23rd 2024-11-20 17:40:22 +03:00
parent 4a19f193ce
commit 1f162aa2a0
5 changed files with 52 additions and 14 deletions

View file

@ -652,6 +652,8 @@ bool ChatFilters::applyChange(ChatFilter &filter, ChatFilter &&updated) {
|| (filter.title() != updated.title())
|| (filter.iconEmoji() != updated.iconEmoji());
const auto colorChanged = filter.colorIndex() != updated.colorIndex();
const auto colorExistenceChanged = (!filter.colorIndex())
!= (!updated.colorIndex());
if (!listUpdated && !chatlistChanged && !colorChanged) {
return false;
}
@ -707,7 +709,10 @@ bool ChatFilters::applyChange(ChatFilter &filter, ChatFilter &&updated) {
_isChatlistChanged.fire_copy(id);
}
if (colorChanged) {
_tagColorChanged.fire_copy(id);
_tagColorChanged.fire_copy(TagColorChanged{
.filterId = id,
.colorExistenceChanged = colorExistenceChanged,
});
}
if (entryToRefreshHeight) {
// Trigger a full refresh of height for the main list.
@ -855,7 +860,7 @@ rpl::producer<FilterId> ChatFilters::isChatlistChanged() const {
return _isChatlistChanged.events();
}
rpl::producer<FilterId> ChatFilters::tagColorChanged() const {
rpl::producer<TagColorChanged> ChatFilters::tagColorChanged() const {
return _tagColorChanged.events();
}

View file

@ -124,6 +124,11 @@ struct SuggestedFilter {
QString description;
};
struct TagColorChanged final {
FilterId filterId = 0;
bool colorExistenceChanged = false;
};
class ChatFilters final {
public:
explicit ChatFilters(not_null<Session*> owner);
@ -140,7 +145,7 @@ public:
[[nodiscard]] const std::vector<ChatFilter> &list() const;
[[nodiscard]] rpl::producer<> changed() const;
[[nodiscard]] rpl::producer<FilterId> isChatlistChanged() const;
[[nodiscard]] rpl::producer<FilterId> tagColorChanged() const;
[[nodiscard]] rpl::producer<TagColorChanged> tagColorChanged() const;
[[nodiscard]] bool loaded() const;
[[nodiscard]] bool has() const;
@ -215,7 +220,7 @@ private:
base::flat_map<FilterId, std::unique_ptr<Dialogs::MainList>> _chatsLists;
rpl::event_stream<> _listChanged;
rpl::event_stream<FilterId> _isChatlistChanged;
rpl::event_stream<FilterId> _tagColorChanged;
rpl::event_stream<TagColorChanged> _tagColorChanged;
mtpRequestId _loadRequestId = 0;
mtpRequestId _saveOrderRequestId = 0;
mtpRequestId _saveOrderAfterId = 0;

View file

@ -332,23 +332,32 @@ int Entry::posInChatList(FilterId filterId) const {
return mainChatListLink(filterId)->index();
}
void Entry::setColorIndexForFilterId(
FilterId filterId,
std::optional<uint8> colorIndex) {
if (!filterId) {
return;
}
if (colorIndex) {
_tagColors[filterId] = *colorIndex;
} else {
_tagColors.remove(filterId);
}
}
not_null<Row*> Entry::addToChatList(
FilterId filterId,
not_null<MainList*> list) {
if (const auto main = maybeMainChatListLink(filterId)) {
return main;
}
if (filterId) {
const auto &list = owner().chatsFilters().list();
const auto it = ranges::find(list, filterId, &Data::ChatFilter::id);
if (it != end(list) && it->colorIndex()) {
_tagColors[filterId] = *(it->colorIndex());
} else {
if (it != end(list)) {
}
_tagColors.remove(filterId);
if (it != end(list)) {
setColorIndexForFilterId(filterId, it->colorIndex());
}
}
if (const auto main = maybeMainChatListLink(filterId)) {
return main;
}
return _chatListLinks.emplace(
filterId,
list->addEntry(this)

View file

@ -189,6 +189,7 @@ public:
not_null<Row*> addToChatList(
FilterId filterId,
not_null<MainList*> list);
void setColorIndexForFilterId(FilterId, std::optional<uint8>);
void removeFromChatList(
FilterId filterId,
not_null<MainList*> list);

View file

@ -329,10 +329,28 @@ InnerWidget::InnerWidget(
}, _handleChatListEntryTagRefreshesLifetime);
session().data().chatsFilters().tagColorChanged(
) | rpl::start_with_next([=](FilterId filterId) {
) | rpl::start_with_next([=](Data::TagColorChanged data) {
const auto filterId = data.filterId;
const auto it = _chatsFilterTags.find(filterId);
if (it != _chatsFilterTags.end()) {
_chatsFilterTags.erase(it);
}
if (data.colorExistenceChanged) {
for (const auto &f : session().data().chatsFilters().list()) {
if (f.id() != filterId) {
continue;
}
const auto color = f.colorIndex();
const auto list = session().data().chatsFilters().chatsList(
filterId);
for (const auto &row : list->indexed()->all()) {
row->entry()->setColorIndexForFilterId(filterId, color);
}
}
if (_shownList->updateHeights(_narrowRatio)) {
refresh();
}
} else {
update();
}
}, _handleChatListEntryTagRefreshesLifetime);