Removed duplicated search of correspond chat filter for tags in dialogs.

This commit is contained in:
23rd 2024-11-21 13:56:13 +03:00
parent 9d5ca1252a
commit b335981621
2 changed files with 15 additions and 15 deletions

View file

@ -809,7 +809,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
// Hack for History::fakeUnreadWhileOpened(). // Hack for History::fakeUnreadWhileOpened().
continue; continue;
} }
if (const auto tag = cacheChatsFilterTag(filter.id(), 0, a)) { if (const auto tag = cacheChatsFilterTag(filter, 0, a)) {
if (more) { if (more) {
more++; more++;
continue; continue;
@ -826,13 +826,13 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
} }
} }
if (more) { if (more) {
if (const auto tag = cacheChatsFilterTag(0, more, a)) { if (const auto tag = cacheChatsFilterTag({}, 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 (!chatsFilterTags.empty()) { if (!chatsFilterTags.empty()) {
const auto tag = cacheChatsFilterTag(0, more, a); const auto tag = cacheChatsFilterTag({}, more, a);
if (tag) { if (tag) {
chatsFilterTags.back() = tag; chatsFilterTags.back() = tag;
} }
@ -4089,13 +4089,13 @@ void InnerWidget::restoreChatsFilterScrollState(FilterId filterId) {
} }
QImage *InnerWidget::cacheChatsFilterTag( QImage *InnerWidget::cacheChatsFilterTag(
FilterId filterId, const Data::ChatFilter &filter,
uint8 more, uint8 more,
bool active) { bool active) {
if (!filterId && !more) { if (!filter.id() && !more) {
return nullptr; return nullptr;
} }
const auto key = SerializeFilterTagsKey(filterId, more, active); const auto key = SerializeFilterTagsKey(filter.id(), more, active);
{ {
const auto it = _chatsFilterTags.find(key); const auto it = _chatsFilterTags.find(key);
if (it != end(_chatsFilterTags)) { if (it != end(_chatsFilterTags)) {
@ -4104,14 +4104,10 @@ QImage *InnerWidget::cacheChatsFilterTag(
} }
auto roundedText = QString(); auto roundedText = QString();
auto colorIndex = -1; auto colorIndex = -1;
if (filterId) { if (filter.id()) {
const auto &list = session().data().chatsFilters().list(); roundedText = filter.title().toUpper();
const auto it = ranges::find(list, filterId, &Data::ChatFilter::id); if (filter.colorIndex()) {
if (it != end(list)) { colorIndex = *(filter.colorIndex());
roundedText = it->title().toUpper();
if (it->colorIndex()) {
colorIndex = *it->colorIndex();
}
} }
} else if (more > 0) { } else if (more > 0) {
roundedText = QChar('+') + QString::number(more); roundedText = QChar('+') + QString::number(more);

View file

@ -41,6 +41,7 @@ class SessionController;
} // namespace Window } // namespace Window
namespace Data { namespace Data {
class ChatFilter;
class Thread; class Thread;
class Folder; class Folder;
class Forum; class Forum;
@ -450,7 +451,10 @@ private:
void saveChatsFilterScrollState(FilterId filterId); void saveChatsFilterScrollState(FilterId filterId);
void restoreChatsFilterScrollState(FilterId filterId); void restoreChatsFilterScrollState(FilterId filterId);
[[nodiscard]] QImage *cacheChatsFilterTag(FilterId, uint8, bool); [[nodiscard]] QImage *cacheChatsFilterTag(
const Data::ChatFilter &filter,
uint8 more,
bool active);
const not_null<Window::SessionController*> _controller; const not_null<Window::SessionController*> _controller;