2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-01 15:05:56 +00:00

Fixed request of recent gifts only when peer has gifts.

This commit is contained in:
23rd
2025-07-02 10:18:14 +03:00
parent f2f5ffd861
commit 20815eecbc

View File

@@ -316,10 +316,10 @@ not_null<Ui::SettingsButton*> AddPeerGiftsButton(
});
struct State final {
std::optional<MTP::Sender> api;
std::vector<std::unique_ptr<Ui::Text::CustomEmoji>> emojiList;
rpl::event_stream<> textRefreshed;
QPointer<Ui::SettingsButton> button;
rpl::lifetime appearedLifetime;
};
const auto state = parent->lifetime().make_state<State>();
@@ -329,8 +329,6 @@ not_null<Ui::SettingsButton*> AddPeerGiftsButton(
}
};
state->api.emplace(&navigation->session().mtp());
auto customs = state->textRefreshed.events(
) | rpl::map([=]() -> TextWithEntities {
auto result = TextWithEntities();
@@ -365,6 +363,10 @@ not_null<Ui::SettingsButton*> AddPeerGiftsButton(
wrap->toggleOn(rpl::duplicate(forked) | rpl::map(rpl::mappers::_1 > 0));
tracker.track(wrap);
rpl::duplicate(forked) | rpl::filter(
rpl::mappers::_1 > 0
) | rpl::start_with_next([=] {
state->appearedLifetime.destroy();
const auto requestDone = crl::guard(wrap, [=](
std::vector<DocumentId> ids) {
state->emojiList.clear();
@@ -375,6 +377,7 @@ not_null<Ui::SettingsButton*> AddPeerGiftsButton(
state->textRefreshed.fire({});
});
navigation->session().recentSharedGifts().request(peer, requestDone);
}, state->appearedLifetime);
state->button = wrap->entity();