Add getStarTransactions.owner_id.

This commit is contained in:
levlam 2024-06-14 14:09:02 +03:00
parent b0bfe55580
commit f4a64ad28c
5 changed files with 55 additions and 34 deletions

View File

@ -10978,11 +10978,13 @@ getPremiumGiveawayInfo chat_id:int53 message_id:int53 = PremiumGiveawayInfo;
//@description Returns available options for Telegram stars purchase
getStarPaymentOptions = StarPaymentOptions;
//@description Returns the list of Telegram star transactions for the current user
//@description Returns the list of Telegram star transactions for the specified owner
//@owner_id Identifier of the owner of the Telegram stars; can be the identifier of the current user, identifier of an owned bot,
//-or identifier of a channel chat with supergroupFullInfo.can_get_revenue_statistics == true
//@direction Direction of the transactions to receive; pass null to get all transactions
//@offset Offset of the first transaction to return as received from the previous request; use empty string to get the first chunk of results
//@limit The maximum number of transactions to return
getStarTransactions direction:StarTransactionDirection offset:string limit:int32 = StarTransactions;
getStarTransactions owner_id:MessageSender direction:StarTransactionDirection offset:string limit:int32 = StarTransactions;
//@description Checks whether an in-store purchase is possible. Must be called before any in-store purchase @purpose Transaction purpose
canPurchaseFromStore purpose:StorePaymentPurpose = Ok;

View File

@ -11,6 +11,7 @@
#include "td/telegram/DialogManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/InputInvoice.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/PasswordManager.h"
#include "td/telegram/Photo.h"
#include "td/telegram/Td.h"
@ -58,13 +59,18 @@ class GetStarsTopupOptionsQuery final : public Td::ResultHandler {
class GetStarsTransactionsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::starTransactions>> promise_;
DialogId dialog_id_;
public:
explicit GetStarsTransactionsQuery(Promise<td_api::object_ptr<td_api::starTransactions>> &&promise)
: promise_(std::move(promise)) {
}
void send(const string &offset, int32 limit, td_api::object_ptr<td_api::StarTransactionDirection> &&direction) {
void send(DialogId dialog_id, const string &offset, int32 limit,
td_api::object_ptr<td_api::StarTransactionDirection> &&direction) {
dialog_id_ = dialog_id;
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
int32 flags = 0;
if (direction != nullptr) {
switch (direction->get_id()) {
@ -79,8 +85,7 @@ class GetStarsTransactionsQuery final : public Td::ResultHandler {
}
}
send_query(G()->net_query_creator().create(telegram_api::payments_getStarsTransactions(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
telegram_api::make_object<telegram_api::inputPeerSelf>(), offset, limit)));
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_peer), offset, limit)));
}
void on_result(BufferSlice packet) final {
@ -152,6 +157,7 @@ class GetStarsTransactionsQuery final : public Td::ResultHandler {
}
void on_error(Status status) final {
td_->dialog_manager_->on_get_dialog_error(dialog_id_, status, "GetStarsTransactionsQuery");
promise_.set_error(std::move(status));
}
};
@ -227,17 +233,46 @@ void StarManager::tear_down() {
parent_.reset();
}
Status StarManager::can_manage_stars(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User: {
auto user_id = dialog_id.get_user_id();
TRY_RESULT(bot_data, td_->user_manager_->get_bot_data(user_id));
if (!bot_data.can_be_edited) {
return Status::Error(400, "The bot isn't owned");
}
break;
}
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
if (!td_->chat_manager_->is_broadcast_channel(channel_id)) {
return Status::Error(400, "Chat is not a channel");
}
if (!td_->chat_manager_->get_channel_permissions(channel_id).is_creator()) {
return Status::Error(400, "Not enough rights to withdraw stars");
}
break;
}
default:
return Status::Error(400, "Unallowed chat specified");
}
return Status::OK();
}
void StarManager::get_star_payment_options(Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise) {
td_->create_handler<GetStarsTopupOptionsQuery>(std::move(promise))->send();
}
void StarManager::get_star_transactions(const string &offset, int32 limit,
td_api::object_ptr<td_api::StarTransactionDirection> &&direction,
void StarManager::get_star_transactions(td_api::object_ptr<td_api::MessageSender> owner_id, const string &offset,
int32 limit, td_api::object_ptr<td_api::StarTransactionDirection> &&direction,
Promise<td_api::object_ptr<td_api::starTransactions>> &&promise) {
TRY_RESULT_PROMISE(promise, dialog_id, get_message_sender_dialog_id(td_, owner_id, true, false));
TRY_STATUS_PROMISE(promise, can_manage_stars(dialog_id));
if (limit < 0) {
return promise.set_error(Status::Error(400, "Limit must be non-negative"));
}
td_->create_handler<GetStarsTransactionsQuery>(std::move(promise))->send(offset, limit, std::move(direction));
td_->create_handler<GetStarsTransactionsQuery>(std::move(promise))
->send(dialog_id, offset, limit, std::move(direction));
}
void StarManager::refund_star_payment(UserId user_id, const string &telegram_payment_charge_id,
@ -251,27 +286,7 @@ void StarManager::get_star_withdrawal_url(DialogId dialog_id, int64 star_count,
Promise<string> &&promise) {
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
"get_star_withdrawal_url"));
switch (dialog_id.get_type()) {
case DialogType::User: {
auto user_id = dialog_id.get_user_id();
if (!td_->user_manager_->is_user_bot(user_id)) {
return promise.set_error(Status::Error(400, "User is not a bot"));
}
break;
}
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
if (!td_->chat_manager_->is_broadcast_channel(channel_id)) {
return promise.set_error(Status::Error(400, "Chat is not a channel"));
}
if (!td_->chat_manager_->get_channel_permissions(channel_id).is_creator()) {
return promise.set_error(Status::Error(400, "Not enough rights to withdraw stars"));
}
break;
}
default:
return promise.set_error(Status::Error(400, "Unallowed chat specified"));
}
TRY_STATUS_PROMISE(promise, can_manage_stars(dialog_id));
if (password.empty()) {
return promise.set_error(Status::Error(400, "PASSWORD_HASH_INVALID"));
}

View File

@ -26,7 +26,7 @@ class StarManager final : public Actor {
void get_star_payment_options(Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise);
void get_star_transactions(const string &offset, int32 limit,
void get_star_transactions(td_api::object_ptr<td_api::MessageSender> owner_id, const string &offset, int32 limit,
td_api::object_ptr<td_api::StarTransactionDirection> &&direction,
Promise<td_api::object_ptr<td_api::starTransactions>> &&promise);
@ -37,6 +37,8 @@ class StarManager final : public Actor {
private:
void tear_down() final;
Status can_manage_stars(DialogId dialog_id) const;
void send_get_star_withdrawal_url_query(
DialogId dialog_id, int64 star_count,
telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password, Promise<string> &&promise);

View File

@ -9501,8 +9501,8 @@ void Td::on_request(uint64 id, td_api::getStarTransactions &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.offset_);
CREATE_REQUEST_PROMISE();
star_manager_->get_star_transactions(request.offset_, request.limit_, std::move(request.direction_),
std::move(promise));
star_manager_->get_star_transactions(std::move(request.owner_id_), request.offset_, request.limit_,
std::move(request.direction_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::canPurchaseFromStore &request) {

View File

@ -3436,16 +3436,18 @@ class CliClient final : public Actor {
} else if (op == "gspo") {
send_request(td_api::make_object<td_api::getStarPaymentOptions>());
} else if (op == "gsta" || op == "gsti" || op == "gsto") {
string owner_id;
string offset;
string limit;
get_args(args, offset, limit);
get_args(args, owner_id, offset, limit);
td_api::object_ptr<td_api::StarTransactionDirection> direction;
if (op == "gsti") {
direction = td_api::make_object<td_api::starTransactionDirectionIncoming>();
} else if (op == "gsto") {
direction = td_api::make_object<td_api::starTransactionDirectionOutgoing>();
}
send_request(td_api::make_object<td_api::getStarTransactions>(std::move(direction), offset, as_limit(limit)));
send_request(td_api::make_object<td_api::getStarTransactions>(as_message_sender(owner_id), std::move(direction),
offset, as_limit(limit)));
} else if (op == "cpfs" || op == "cpfsb") {
UserId user_id;
string currency;