2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Added ability to inspect earn balance from channel info.

This commit is contained in:
23rd
2025-05-05 02:15:17 +03:00
parent 14328eb601
commit a8afc62db7
8 changed files with 119 additions and 54 deletions

View File

@@ -7,7 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "data/data_channel.h"
#include "api/api_credits.h"
#include "api/api_global_privacy.h"
#include "api/api_statistics.h"
#include "data/components/credits.h"
#include "data/data_changes.h"
#include "data/data_channel_admins.h"
@@ -1357,6 +1359,34 @@ void ApplyChannelUpdate(
channel->setWallPaper({});
}
if (channel->flags() & Flag::CanViewRevenue) {
const auto id = channel->id;
const auto weak = base::make_weak(&channel->session());
const auto creditsLoadLifetime = std::make_shared<rpl::lifetime>();
const auto creditsLoad
= creditsLoadLifetime->make_state<Api::CreditsStatus>(channel);
creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) {
if (const auto strong = weak.get()) {
strong->credits().apply(id, slice.balance);
creditsLoadLifetime->destroy();
}
});
const auto currencyLoadLifetime = std::make_shared<rpl::lifetime>();
const auto currencyLoad
= currencyLoadLifetime->make_state<Api::EarnStatistics>(channel);
currencyLoad->request(
) | rpl::start_with_error_done([=](const QString &error) {
currencyLoadLifetime->destroy();
}, [=] {
if (const auto strong = weak.get()) {
strong->credits().applyCurrency(
id,
currencyLoad->data().currentBalance);
currencyLoadLifetime->destroy();
}
}, *currencyLoadLifetime);
}
// For clearUpTill() call.
channel->owner().sendHistoryChangeNotifications();
}