mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added initial ability to claim refund credits from history entries list.
This commit is contained in:
parent
885dcf0b28
commit
be099880d8
5 changed files with 74 additions and 7 deletions
|
@ -8,15 +8,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "api/api_credits.h"
|
#include "api/api_credits.h"
|
||||||
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_updates.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
#include "data/data_photo.h"
|
#include "data/data_photo.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_user.h"
|
||||||
#include "main/main_app_config.h"
|
#include "main/main_app_config.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#if _DEBUG
|
|
||||||
#include "base/random.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -199,4 +198,24 @@ rpl::producer<not_null<PeerData*>> PremiumPeerBot(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreditsRefund(
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
const QString &entryId,
|
||||||
|
Fn<void()> done,
|
||||||
|
Fn<void(QString)> fail) {
|
||||||
|
const auto user = peer->asUser();
|
||||||
|
if (!user) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
peer->session().api().request(MTPpayments_RefundStarsCharge(
|
||||||
|
user->inputUser,
|
||||||
|
MTP_string(entryId)
|
||||||
|
)).done([=](const MTPUpdates &result) {
|
||||||
|
peer->session().api().updates().applyUpdates(result);
|
||||||
|
done();
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
fail(error.type());
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
|
@ -68,6 +68,12 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void CreditsRefund(
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
const QString &entryId,
|
||||||
|
Fn<void()> done,
|
||||||
|
Fn<void(QString)> fail);
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<not_null<PeerData*>> PremiumPeerBot(
|
[[nodiscard]] rpl::producer<not_null<PeerData*>> PremiumPeerBot(
|
||||||
not_null<Main::Session*> session);
|
not_null<Main::Session*> session);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "info/channel_statistics/boosts/giveaway/boost_badge.h"
|
#include "info/channel_statistics/boosts/giveaway/boost_badge.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "main/session/session_show.h"
|
||||||
#include "ui/effects/credits_graphics.h"
|
#include "ui/effects/credits_graphics.h"
|
||||||
#include "ui/effects/outline_segments.h" // Ui::UnreadStoryOutlineGradient.
|
#include "ui/effects/outline_segments.h" // Ui::UnreadStoryOutlineGradient.
|
||||||
#include "ui/effects/toggle_arrow.h"
|
#include "ui/effects/toggle_arrow.h"
|
||||||
|
@ -841,6 +842,10 @@ public:
|
||||||
void rowClicked(not_null<PeerListRow*> row) override;
|
void rowClicked(not_null<PeerListRow*> row) override;
|
||||||
void loadMoreRows() override;
|
void loadMoreRows() override;
|
||||||
|
|
||||||
|
base::unique_qptr<Ui::PopupMenu> rowContextMenu(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<PeerListRow*> row) override;
|
||||||
|
|
||||||
[[nodiscard]] bool skipRequest() const;
|
[[nodiscard]] bool skipRequest() const;
|
||||||
void requestNext();
|
void requestNext();
|
||||||
|
|
||||||
|
@ -930,6 +935,29 @@ void CreditsController::rowClicked(not_null<PeerListRow*> row) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base::unique_qptr<Ui::PopupMenu> CreditsController::rowContextMenu(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<PeerListRow*> row) {
|
||||||
|
const auto entry = static_cast<const CreditsRow*>(row.get())->entry();
|
||||||
|
if (!entry.bareId) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
auto menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
parent,
|
||||||
|
st::defaultPopupMenu);
|
||||||
|
const auto peer = row->peer();
|
||||||
|
const auto callback = crl::guard(parent, [=, id = entry.id] {
|
||||||
|
const auto show = delegate()->peerListUiShow();
|
||||||
|
Api::CreditsRefund(
|
||||||
|
peer,
|
||||||
|
id,
|
||||||
|
[=] { show->showToast(tr::lng_report_spam_done(tr::now)); },
|
||||||
|
[=](const QString &error) { show->showToast(error); });
|
||||||
|
});
|
||||||
|
menu->addAction(tr::lng_channel_earn_history_return(tr::now), callback);
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
rpl::producer<bool> CreditsController::allLoadedValue() const {
|
rpl::producer<bool> CreditsController::allLoadedValue() const {
|
||||||
return _allLoaded.value();
|
return _allLoaded.value();
|
||||||
}
|
}
|
||||||
|
@ -1086,6 +1114,7 @@ void AddBoostsList(
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddCreditsHistoryList(
|
void AddCreditsHistoryList(
|
||||||
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
const Data::CreditsStatusSlice &firstSlice,
|
const Data::CreditsStatusSlice &firstSlice,
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
Fn<void(const Data::CreditsHistoryEntry &)> callback,
|
Fn<void(const Data::CreditsHistoryEntry &)> callback,
|
||||||
|
@ -1094,13 +1123,18 @@ void AddCreditsHistoryList(
|
||||||
bool in,
|
bool in,
|
||||||
bool out) {
|
bool out) {
|
||||||
struct State final {
|
struct State final {
|
||||||
State(CreditsDescriptor d) : controller(std::move(d)) {
|
State(
|
||||||
|
CreditsDescriptor d,
|
||||||
|
std::shared_ptr<Main::SessionShow> show)
|
||||||
|
: delegate(std::move(show))
|
||||||
|
, controller(std::move(d)) {
|
||||||
}
|
}
|
||||||
PeerListContentDelegateSimple delegate;
|
PeerListContentDelegateShow delegate;
|
||||||
CreditsController controller;
|
CreditsController controller;
|
||||||
};
|
};
|
||||||
auto d = CreditsDescriptor{ firstSlice, callback, bot, icon, in, out };
|
const auto state = container->lifetime().make_state<State>(
|
||||||
const auto state = container->lifetime().make_state<State>(std::move(d));
|
CreditsDescriptor{ firstSlice, callback, bot, icon, in, out },
|
||||||
|
show);
|
||||||
|
|
||||||
state->delegate.setContent(container->add(
|
state->delegate.setContent(container->add(
|
||||||
object_ptr<PeerListContent>(container, &state->controller)));
|
object_ptr<PeerListContent>(container, &state->controller)));
|
||||||
|
|
|
@ -23,6 +23,10 @@ struct RecentPostId;
|
||||||
struct SupergroupStatistics;
|
struct SupergroupStatistics;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
||||||
|
namespace Main {
|
||||||
|
class SessionShow;
|
||||||
|
} // namespace Main
|
||||||
|
|
||||||
namespace Info::Statistics {
|
namespace Info::Statistics {
|
||||||
|
|
||||||
void AddPublicForwards(
|
void AddPublicForwards(
|
||||||
|
@ -47,6 +51,7 @@ void AddBoostsList(
|
||||||
rpl::producer<QString> title);
|
rpl::producer<QString> title);
|
||||||
|
|
||||||
void AddCreditsHistoryList(
|
void AddCreditsHistoryList(
|
||||||
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
const Data::CreditsStatusSlice &firstSlice,
|
const Data::CreditsStatusSlice &firstSlice,
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
Fn<void(const Data::CreditsHistoryEntry &)> entryClickedCallback,
|
Fn<void(const Data::CreditsHistoryEntry &)> entryClickedCallback,
|
||||||
|
|
|
@ -239,6 +239,7 @@ void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Info::Statistics::AddCreditsHistoryList(
|
Info::Statistics::AddCreditsHistoryList(
|
||||||
|
controller->uiShow(),
|
||||||
fullSlice,
|
fullSlice,
|
||||||
fullWrap->entity(),
|
fullWrap->entity(),
|
||||||
entryClicked,
|
entryClicked,
|
||||||
|
@ -247,6 +248,7 @@ void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
|
||||||
true,
|
true,
|
||||||
true);
|
true);
|
||||||
Info::Statistics::AddCreditsHistoryList(
|
Info::Statistics::AddCreditsHistoryList(
|
||||||
|
controller->uiShow(),
|
||||||
inSlice,
|
inSlice,
|
||||||
inWrap->entity(),
|
inWrap->entity(),
|
||||||
entryClicked,
|
entryClicked,
|
||||||
|
@ -255,6 +257,7 @@ void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
|
||||||
true,
|
true,
|
||||||
false);
|
false);
|
||||||
Info::Statistics::AddCreditsHistoryList(
|
Info::Statistics::AddCreditsHistoryList(
|
||||||
|
controller->uiShow(),
|
||||||
outSlice,
|
outSlice,
|
||||||
outWrap->entity(),
|
outWrap->entity(),
|
||||||
std::move(entryClicked),
|
std::move(entryClicked),
|
||||||
|
|
Loading…
Add table
Reference in a new issue