Skip to content

Commit

Permalink
Improve top senders rebuild.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Aug 21, 2024
1 parent 46304c7 commit 6b83c52
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
33 changes: 29 additions & 4 deletions Telegram/SourceFiles/payments/ui/payments_reaction_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ For license and copyright information please follow this link:
*/
#include "payments/ui/payments_reaction_box.h"

#include "base/qt/qt_compare.h"
#include "lang/lang_keys.h"
#include "ui/boxes/boost_box.h" // MakeBoostFeaturesBadge.
#include "ui/effects/premium_bubble.h"
Expand Down Expand Up @@ -196,7 +197,7 @@ void PaidReactionSlider(
state->name.setText(st::defaultTextStyle, data.name);

const auto count = data.count;
const auto photo = data.photo;
const auto photo = data.photo->clone();
photo->subscribeToUpdates([=] {
result->update();
});
Expand Down Expand Up @@ -248,7 +249,16 @@ void FillTopReactors(
object_ptr<FixedHeightWidget>(container, height),
st::paidReactTopMargin));
const auto parent = wrap->entity();
struct Key {
std::shared_ptr<DynamicImage> photo;
int count = 0;
QString name;

inline auto operator<=>(const Key &) const = default;
inline bool operator==(const Key &) const = default;
};
struct State {
base::flat_map<Key, not_null<RpWidget*>> cache;
std::vector<not_null<RpWidget*>> widgets;
rpl::event_stream<> updated;
std::optional<int> initialChosen;
Expand Down Expand Up @@ -290,11 +300,26 @@ void FillTopReactors(
wrap->hide(anim::type::normal);
} else {
for (const auto &widget : state->widgets) {
delete widget;
widget->hide();
}
state->widgets.clear();
for (const auto &entry : list) {
state->widgets.push_back(MakeTopReactor(parent, entry));
const auto key = Key{
.photo = entry.photo,
.count = entry.count,
.name = entry.name,
};
const auto i = state->cache.find(key);
const auto widget = (i != end(state->cache))
? i->second
: MakeTopReactor(parent, entry);
state->widgets.push_back(widget);
widget->show();
}
for (const auto &[k, widget] : state->cache) {
if (widget->isHidden()) {
delete widget;
}
}
wrap->show(anim::type::normal);
}
Expand All @@ -313,7 +338,7 @@ void FillTopReactors(
}
const auto count = int(state->widgets.size());
auto left = (width - single * count) / 2;
for (const auto widget : state->widgets) {
for (const auto &widget : state->widgets) {
widget->setGeometry(left, 0, single, height);
left += single;
}
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/ui/dynamic_thumbnails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ void PeerUserpic::subscribeToUpdates(Fn<void()> callback) {
_subscribed = nullptr;
return;
}
_subscribed = std::make_unique<Subscribed>(std::move(callback));
const auto old = std::exchange(
_subscribed,
std::make_unique<Subscribed>(std::move(callback)));

_peer->session().changes().peerUpdates(
_peer,
Expand Down

0 comments on commit 6b83c52

Please sign in to comment.