Skip to content

Commit

Permalink
Removed duplicated search of correspond chat filter for tags in dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Nov 21, 2024
1 parent 8f4133c commit b639661
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 10 additions & 14 deletions Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
// Hack for History::fakeUnreadWhileOpened().
continue;
}
if (const auto tag = cacheChatsFilterTag(filter.id(), 0, a)) {
if (const auto tag = cacheChatsFilterTag(filter, 0, a)) {
if (more) {
more++;
continue;
Expand All @@ -826,13 +826,13 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
}
}
if (more) {
if (const auto tag = cacheChatsFilterTag(0, more, a)) {
if (const auto tag = cacheChatsFilterTag({}, more, a)) {
const auto tagWidth = tag->width()
/ style::DevicePixelRatio();
if (availableWidth < tagWidth) {
more++;
if (!chatsFilterTags.empty()) {
const auto tag = cacheChatsFilterTag(0, more, a);
const auto tag = cacheChatsFilterTag({}, more, a);
if (tag) {
chatsFilterTags.back() = tag;
}
Expand Down Expand Up @@ -4089,13 +4089,13 @@ void InnerWidget::restoreChatsFilterScrollState(FilterId filterId) {
}

QImage *InnerWidget::cacheChatsFilterTag(
FilterId filterId,
const Data::ChatFilter &filter,
uint8 more,
bool active) {
if (!filterId && !more) {
if (!filter.id() && !more) {
return nullptr;
}
const auto key = SerializeFilterTagsKey(filterId, more, active);
const auto key = SerializeFilterTagsKey(filter.id(), more, active);
{
const auto it = _chatsFilterTags.find(key);
if (it != end(_chatsFilterTags)) {
Expand All @@ -4104,14 +4104,10 @@ QImage *InnerWidget::cacheChatsFilterTag(
}
auto roundedText = QString();
auto colorIndex = -1;
if (filterId) {
const auto &list = session().data().chatsFilters().list();
const auto it = ranges::find(list, filterId, &Data::ChatFilter::id);
if (it != end(list)) {
roundedText = it->title().toUpper();
if (it->colorIndex()) {
colorIndex = *it->colorIndex();
}
if (filter.id()) {
roundedText = filter.title().toUpper();
if (filter.colorIndex()) {
colorIndex = *(filter.colorIndex());
}
} else if (more > 0) {
roundedText = QChar('+') + QString::number(more);
Expand Down
6 changes: 5 additions & 1 deletion Telegram/SourceFiles/dialogs/dialogs_inner_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SessionController;
} // namespace Window

namespace Data {
class ChatFilter;
class Thread;
class Folder;
class Forum;
Expand Down Expand Up @@ -450,7 +451,10 @@ class InnerWidget final : public Ui::RpWidget {
void saveChatsFilterScrollState(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;

Expand Down

0 comments on commit b639661

Please sign in to comment.