Added support of muted chats filters to chats filters strip.

This commit is contained in:
23rd 2024-11-13 18:58:04 +03:00
parent edf6c42e9d
commit 9c1701c62a
3 changed files with 15 additions and 8 deletions

View file

@ -70,19 +70,19 @@ void ChatsFiltersTabs::fitWidthToSections() {
} }
} }
void ChatsFiltersTabs::setUnreadCount(int index, int unreadCount) { void ChatsFiltersTabs::setUnreadCount(int index, int unreadCount, bool mute) {
const auto it = _unreadCounts.find(index); const auto it = _unreadCounts.find(index);
if (it == _unreadCounts.end()) { if (it == _unreadCounts.end()) {
if (unreadCount) { if (unreadCount) {
_unreadCounts.emplace(index, Unread{ _unreadCounts.emplace(index, Unread{
.cache = cacheUnreadCount(unreadCount), .cache = cacheUnreadCount(unreadCount, mute),
.count = unreadCount, .count = unreadCount,
}); });
} }
} else { } else {
if (unreadCount) { if (unreadCount) {
it->second.count = unreadCount; it->second.count = unreadCount;
it->second.cache = cacheUnreadCount(unreadCount); it->second.cache = cacheUnreadCount(unreadCount, mute);
} else { } else {
_unreadCounts.erase(it); _unreadCounts.erase(it);
} }
@ -132,7 +132,7 @@ void ChatsFiltersTabs::setLockedFrom(int index) {
}); });
} }
QImage ChatsFiltersTabs::cacheUnreadCount(int count) const { QImage ChatsFiltersTabs::cacheUnreadCount(int count, bool muted) const {
const auto widthIndex = (count < 10) ? 0 : (count < 100) ? 1 : 2; const auto widthIndex = (count < 10) ? 0 : (count < 100) ? 1 : 2;
auto image = QImage( auto image = QImage(
QSize(_cachedBadgeWidths[widthIndex], _cachedBadgeHeight) QSize(_cachedBadgeWidths[widthIndex], _cachedBadgeHeight)
@ -145,7 +145,13 @@ QImage ChatsFiltersTabs::cacheUnreadCount(int count) const {
: QString::number(count); : QString::number(count);
{ {
auto p = QPainter(&image); auto p = QPainter(&image);
Ui::PaintUnreadBadge(p, string, 0, 0, _unreadSt, 0); if (muted) {
auto copy = _unreadSt;
copy.muted = muted;
Ui::PaintUnreadBadge(p, string, 0, 0, copy, 0);
} else {
Ui::PaintUnreadBadge(p, string, 0, 0, _unreadSt, 0);
}
} }
return image; return image;
} }

View file

@ -29,7 +29,7 @@ public:
[[nodiscard]] int centerOfSection(int section) const; [[nodiscard]] int centerOfSection(int section) const;
void fitWidthToSections(); void fitWidthToSections();
void setUnreadCount(int index, int unreadCount); void setUnreadCount(int index, int unreadCount, bool muted);
void setLockedFrom(int index); void setLockedFrom(int index);
[[nodiscard]] rpl::producer<int> contextMenuRequested() const; [[nodiscard]] rpl::producer<int> contextMenuRequested() const;
@ -62,7 +62,7 @@ protected:
std::vector<ShiftedSection> _sections; std::vector<ShiftedSection> _sections;
private: private:
[[nodiscard]] QImage cacheUnreadCount(int count) const; [[nodiscard]] QImage cacheUnreadCount(int count, bool muted) const;
[[nodiscard]] int calculateLockedFromX() const; [[nodiscard]] int calculateLockedFromX() const;
using Index = int; using Index = int;

View file

@ -330,7 +330,8 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
const auto muted = (state.chatsMuted + state.marksMuted); const auto muted = (state.chatsMuted + state.marksMuted);
const auto count = (state.chats + state.marks) const auto count = (state.chats + state.marks)
- (includeMuted ? 0 : muted); - (includeMuted ? 0 : muted);
slider->setUnreadCount(i, count); const auto isMuted = includeMuted && (count == muted);
slider->setUnreadCount(i, count, isMuted);
slider->fitWidthToSections(); slider->fitWidthToSections();
}, state->unreadLifetime); }, state->unreadLifetime);
} }