Fixed display of chats filter tag for active dialog rows.

This commit is contained in:
23rd 2024-11-20 18:36:38 +03:00
parent 1f162aa2a0
commit 5362d54ab6
2 changed files with 48 additions and 21 deletions

View file

@ -87,6 +87,15 @@ constexpr auto kStartReorderThreshold = 30;
constexpr auto kQueryPreviewLimit = 32; constexpr auto kQueryPreviewLimit = 32;
constexpr auto kPreviewPostsLimit = 3; constexpr auto kPreviewPostsLimit = 3;
[[nodiscard]] InnerWidget::ChatsFilterTagsKey SerializeFilterTagsKey(
FilterId filterId,
uint8 more,
bool active) {
return (filterId & 0xFFFFFFFF)
| (static_cast<int64_t>(more) << 32)
| (static_cast<int64_t>(active) << 40);
}
[[nodiscard]] int FixedOnTopDialogsCount(not_null<Dialogs::IndexedList*> list) { [[nodiscard]] int FixedOnTopDialogsCount(not_null<Dialogs::IndexedList*> list) {
auto result = 0; auto result = 0;
for (const auto &row : *list) { for (const auto &row : *list) {
@ -221,6 +230,7 @@ InnerWidget::InnerWidget(
style::PaletteChanged( style::PaletteChanged(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
_topicJumpCache = nullptr; _topicJumpCache = nullptr;
_chatsFilterTags.clear();
}, lifetime()); }, lifetime());
session().downloaderTaskFinished( session().downloaderTaskFinished(
@ -331,20 +341,27 @@ InnerWidget::InnerWidget(
session().data().chatsFilters().tagColorChanged( session().data().chatsFilters().tagColorChanged(
) | rpl::start_with_next([=](Data::TagColorChanged data) { ) | rpl::start_with_next([=](Data::TagColorChanged data) {
const auto filterId = data.filterId; const auto filterId = data.filterId;
const auto it = _chatsFilterTags.find(filterId); const auto key = SerializeFilterTagsKey(filterId, 0, false);
if (it != _chatsFilterTags.end()) { const auto activeKey = SerializeFilterTagsKey(filterId, 0, true);
_chatsFilterTags.erase(it); {
auto &tags = _chatsFilterTags;
if (const auto it = tags.find(key); it != tags.end()) {
tags.erase(it);
}
if (const auto it = tags.find(activeKey); it != tags.end()) {
tags.erase(it);
}
} }
if (data.colorExistenceChanged) { if (data.colorExistenceChanged) {
for (const auto &f : session().data().chatsFilters().list()) { auto &filters = session().data().chatsFilters();
if (f.id() != filterId) { for (const auto &filter : filters.list()) {
if (filter.id() != filterId) {
continue; continue;
} }
const auto color = f.colorIndex(); const auto c = filter.colorIndex();
const auto list = session().data().chatsFilters().chatsList( const auto list = filters.chatsList(filterId);
filterId);
for (const auto &row : list->indexed()->all()) { for (const auto &row : list->indexed()->all()) {
row->entry()->setColorIndexForFilterId(filterId, color); row->entry()->setColorIndexForFilterId(filterId, c);
} }
} }
if (_shownList->updateHeights(_narrowRatio)) { if (_shownList->updateHeights(_narrowRatio)) {
@ -771,6 +788,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
if (context.narrow) { if (context.narrow) {
context.chatsFilterTags = nullptr; context.chatsFilterTags = nullptr;
} else if (row->entry()->hasChatsFilterTags(context.filter)) { } else if (row->entry()->hasChatsFilterTags(context.filter)) {
const auto a = active;
context.st = forum context.st = forum
? &st::taggedForumDialogRow ? &st::taggedForumDialogRow
: &st::taggedDialogRow; : &st::taggedDialogRow;
@ -778,14 +796,14 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
- context.st->padding.right() - context.st->padding.right()
- st::dialogsUnreadPadding - st::dialogsUnreadPadding
- context.st->nameLeft; - context.st->nameLeft;
auto more = ushort(0); auto more = uint8(0);
const auto &list = session().data().chatsFilters().list(); const auto &list = session().data().chatsFilters().list();
for (const auto &filter : list) { for (const auto &filter : list) {
if (!row->entry()->inChatList(filter.id()) if (!row->entry()->inChatList(filter.id())
|| (filter.id() == context.filter)) { || (filter.id() == context.filter)) {
continue; continue;
} }
if (const auto tag = cacheChatsFilterTag(filter.id(), 0)) { if (const auto tag = cacheChatsFilterTag(filter.id(), 0, a)) {
if (more) { if (more) {
more++; more++;
continue; continue;
@ -802,13 +820,14 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
} }
} }
if (more) { if (more) {
if (const auto tag = cacheChatsFilterTag(0, more)) { if (const auto tag = cacheChatsFilterTag(0, more, a)) {
const auto tagWidth = tag->width() const auto tagWidth = tag->width()
/ style::DevicePixelRatio(); / style::DevicePixelRatio();
if (availableWidth < tagWidth) { if (availableWidth < tagWidth) {
more++; more++;
if (const auto tag = cacheChatsFilterTag(0, more)) { if (!chatsFilterTags.empty()) {
if (!chatsFilterTags.empty()) { const auto tag = cacheChatsFilterTag(0, more, a);
if (tag) {
chatsFilterTags.back() = tag; chatsFilterTags.back() = tag;
} }
} }
@ -4063,11 +4082,14 @@ void InnerWidget::restoreChatsFilterScrollState(FilterId filterId) {
} }
} }
QImage *InnerWidget::cacheChatsFilterTag(FilterId filterId, ushort more) { QImage *InnerWidget::cacheChatsFilterTag(
FilterId filterId,
uint8 more,
bool active) {
if (!filterId && !more) { if (!filterId && !more) {
return nullptr; return nullptr;
} }
const auto key = filterId ? filterId : -more; const auto key = SerializeFilterTagsKey(filterId, more, active);
{ {
const auto it = _chatsFilterTags.find(key); const auto it = _chatsFilterTags.find(key);
if (it != end(_chatsFilterTags)) { if (it != end(_chatsFilterTags)) {
@ -4103,10 +4125,13 @@ QImage *InnerWidget::cacheChatsFilterTag(FilterId filterId, ushort more) {
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
{ {
auto p = QPainter(&cache); auto p = QPainter(&cache);
const auto pen = QPen( const auto pen = QPen(active
Ui::EmptyUserpic::UserpicColor(colorIndex).color2); ? st::dialogsBgActive
: Ui::EmptyUserpic::UserpicColor(colorIndex).color2);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.setBrush(anim::with_alpha(pen.color(), .15)); p.setBrush(active
? st::dialogsTextFgActive->c
: anim::with_alpha(pen.color(), .15));
{ {
auto hq = PainterHighQualityEnabler(p); auto hq = PainterHighQualityEnabler(p);
const auto radius = roundedFont->height / 3.; const auto radius = roundedFont->height / 3.;

View file

@ -99,6 +99,8 @@ enum class WidgetState {
class InnerWidget final : public Ui::RpWidget { class InnerWidget final : public Ui::RpWidget {
public: public:
using ChatsFilterTagsKey = int64;
struct ChildListShown { struct ChildListShown {
PeerId peerId = 0; PeerId peerId = 0;
float64 shown = 0.; float64 shown = 0.;
@ -448,7 +450,7 @@ private:
void saveChatsFilterScrollState(FilterId filterId); void saveChatsFilterScrollState(FilterId filterId);
void restoreChatsFilterScrollState(FilterId filterId); void restoreChatsFilterScrollState(FilterId filterId);
[[nodiscard]] QImage *cacheChatsFilterTag(FilterId filterId, ushort more); [[nodiscard]] QImage *cacheChatsFilterTag(FilterId, uint8, bool);
const not_null<Window::SessionController*> _controller; const not_null<Window::SessionController*> _controller;
@ -556,7 +558,7 @@ private:
base::flat_map<FilterId, int> _chatsFilterScrollStates; base::flat_map<FilterId, int> _chatsFilterScrollStates;
std::unordered_map<FilterId, QImage> _chatsFilterTags; std::unordered_map<ChatsFilterTagsKey, QImage> _chatsFilterTags;
bool _waitingAllChatListEntryRefreshesForTags = false; bool _waitingAllChatListEntryRefreshesForTags = false;
rpl::lifetime _handleChatListEntryTagRefreshesLifetime; rpl::lifetime _handleChatListEntryTagRefreshesLifetime;