Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 23, 2024
1 parent 85a56c9 commit 4aa6f2a
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ DocumentData *LookupGiftSticker(
not_null<Main::Session*> session,
const GiftDescriptor &descriptor) {
auto &packs = session->giftBoxStickersPacks();
#if 0 // mtp
packs.load();
#endif
return v::match(descriptor, [&](GiftTypePremium data) {
return packs.lookup(data.months);
}, [&](GiftTypeStars data) {
Expand Down
21 changes: 21 additions & 0 deletions Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ For license and copyright information please follow this link:
#include "styles/style_info.h"
#include "styles/style_credits.h" // giftBoxPadding

#include "tdb/tdb_tl_scheme.h"
#include "tdb/tdb_sender.h"

namespace Info::PeerGifts {
namespace {

using namespace Tdb;

constexpr auto kPreloadPages = 2;
constexpr auto kPerPage = 50;

Expand Down Expand Up @@ -208,13 +213,28 @@ void InnerWidget::loadMore() {
if (_allLoaded || _loadMoreRequestId) {
return;
}
#if 0 // mtp
_loadMoreRequestId = _api.request(MTPpayments_GetUserStarGifts(
_user->inputUser,
MTP_string(_offset),
MTP_int(kPerPage)
)).done([=](const MTPpayments_UserStarGifts &result) {
#endif
_loadMoreRequestId = _api.request(TLgetUserGifts(
tl_int53(peerToUser(_user->id).bare),
tl_string(_offset),
tl_int32(kPerPage)
)).done([=](const TLuserGifts &result) {
_loadMoreRequestId = 0;
const auto &data = result.data();
const auto offset = data.vnext_offset().v;
if (offset.isEmpty()) {
_allLoaded = true;
} else {
_offset = offset;
}
_totalCount = data.vtotal_count().v;
#if 0 // mtp
if (const auto next = data.vnext_offset()) {
_offset = qs(*next);
} else {
Expand All @@ -224,6 +244,7 @@ void InnerWidget::loadMore() {

const auto owner = &_user->owner();
owner->processUsers(data.vusers());
#endif

_entries.reserve(_entries.size() + data.vgifts().v.size());
for (const auto &gift : data.vgifts().v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,12 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) {

auto giftPacksRequested = false;
for (const auto &item : slice.list) {
#if 0 // mtp
if (item.bareGiveawayMsgId && !giftPacksRequested) {
giftPacksRequested = true;
session().giftBoxStickersPacks().load();
}
#endif
delegate()->peerListAppendRow(create(item, {}));
}
for (const auto &item : slice.subscriptions) {
Expand Down
30 changes: 30 additions & 0 deletions Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,19 @@ void WebViewInstance::requestSimple() {
}

void WebViewInstance::requestMain() {
_requestId = _session->sender().request(TLgetMainWebApp(
peerToTdbChat(_context.action->history->peer->id),
tl_int53(peerToUser(_bot->id).bare),
tl_string(_button.startCommand),
Window::Theme::WebViewTheme(),
tl_string("tdesktop")
)).done([=](const TLmainWebApp &result) {
show(qs(result.data().vurl()));
}).fail([=](const Error &error) {
_parentShow->showToast(error.message);
close();
}).send();
#if 0 // mtp
using Flag = MTPmessages_RequestMainWebView::Flag;
_requestId = _session->api().request(MTPmessages_RequestMainWebView(
MTP_flags(Flag::f_theme_params
Expand All @@ -1097,6 +1110,7 @@ void WebViewInstance::requestMain() {
_parentShow->showToast(error.type());
close();
}).send();
#endif
}

void WebViewInstance::requestApp(bool allowWrite) {
Expand Down Expand Up @@ -1765,7 +1779,10 @@ AttachWebView::AttachWebView(not_null<Main::Session*> session)

AttachWebView::~AttachWebView() {
closeAll();
#if 0 // mtp
_session->api().request(_popularAppBotsRequestId).cancel();
#endif
_session->sender().request(_popularAppBotsRequestId).cancel();
}

void AttachWebView::openByUsername(
Expand Down Expand Up @@ -1827,18 +1844,31 @@ void AttachWebView::loadPopularAppBots() {
if (_popularAppBotsLoaded.current() || _popularAppBotsRequestId) {
return;
}
#if 0 // mtp
_popularAppBotsRequestId = _session->api().request(
MTPbots_GetPopularAppBots(
MTP_string(),
MTP_int(kPopularAppBotsLimit))
).done([=](const MTPbots_PopularAppBots &result) {
#endif
_popularAppBotsRequestId = _session->sender().request(
TLgetGrossingWebAppBots(
tl_string(), // offset
tl_int32(kPopularAppBotsLimit))
).done([=](const TLfoundUsers &result) {
_popularAppBotsRequestId = 0;

#if 0 // mtp
const auto &list = result.data().vusers().v;
#endif
const auto &list = result.data().vuser_ids().v;
auto parsed = std::vector<not_null<UserData*>>();
parsed.reserve(list.size());
for (const auto &user : list) {
#if 0 // mtp
const auto bot = _session->data().processUser(user);
#endif
const auto bot = _session->data().user(UserId(user.v));
if (bot->isBot()) {
parsed.push_back(bot);
}
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/main/main_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void AppConfig::refresh(bool force) {
}
#endif

void AppConfig::refresh() {
void AppConfig::refresh(bool force) {
if (_requestId || !_api) {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions Telegram/SourceFiles/main/main_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ Session::Session(
, _user(_data->processUser(user))
, _emojiStickersPack(std::make_unique<Stickers::EmojiPack>(this))
, _diceStickersPacks(std::make_unique<Stickers::DicePacks>(this))
#if 0 // mtp
, _giftBoxStickersPacks(std::make_unique<Stickers::GiftBoxPack>(this))
#endif
, _sendAsPeers(std::make_unique<SendAsPeers>(this))
, _attachWebView(std::make_unique<InlineBots::AttachWebView>(this))
, _recentPeers(std::make_unique<Data::RecentPeers>(this))
Expand Down
4 changes: 0 additions & 4 deletions Telegram/SourceFiles/main/main_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,9 @@ class Session final : public base::has_weak_ptr {
[[nodiscard]] Stickers::DicePacks &diceStickersPacks() const {
return *_diceStickersPacks;
}
#if 0 // mtp
[[nodiscard]] Stickers::GiftBoxPack &giftBoxStickersPacks() const {
return *_giftBoxStickersPacks;
}
#endif
[[nodiscard]] Data::Session &data() const {
return *_data;
}
Expand Down Expand Up @@ -299,9 +297,7 @@ class Session final : public base::has_weak_ptr {
// _emojiStickersPack depends on _data.
const std::unique_ptr<Stickers::EmojiPack> _emojiStickersPack;
const std::unique_ptr<Stickers::DicePacks> _diceStickersPacks;
#if 0 // mtp
const std::unique_ptr<Stickers::GiftBoxPack> _giftBoxStickersPacks;
#endif
const std::unique_ptr<SendAsPeers> _sendAsPeers;
const std::unique_ptr<InlineBots::AttachWebView> _attachWebView;
const std::unique_ptr<Data::RecentPeers> _recentPeers;
Expand Down
11 changes: 6 additions & 5 deletions Telegram/SourceFiles/payments/payments_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ MTPinputStorePaymentPurpose InvoicePremiumGiftCodeGiveawayToTL(
}
#endif

Tdb::TLpremiumGiveawayParameters InvoiceGiftCodeGiveawayToTL(
Tdb::TLgiveawayParameters InvoiceGiftCodeGiveawayToTL(
const InvoicePremiumGiftCode &invoice) {
const auto &giveaway = v::get<InvoicePremiumGiftCodeGiveaway>(
invoice.purpose);
return Tdb::tl_premiumGiveawayParameters(
return Tdb::tl_giveawayParameters(
peerToTdbChat(giveaway.boostPeer->id),
Tdb::tl_vector(ranges::views::all(
giveaway.additionalChannels
Expand Down Expand Up @@ -536,17 +536,18 @@ TLinputInvoice Form::inputInvoice() const {
if (users) {
return Tdb::tl_inputInvoiceTelegram(
Tdb::tl_telegramPaymentPurposePremiumGiftCodes(
users->boostPeer
(users->boostPeer
? peerToTdbChat(users->boostPeer->id)
: TLint53(),
: TLint53()),
Tdb::tl_string(giftCode.currency),
Tdb::tl_int53(giftCode.amount),
Tdb::tl_vector(ranges::views::all(
users->users
) | ranges::views::transform([](not_null<UserData*> user) {
return peerToTdbChat(user->id);
}) | ranges::to<QVector<TLint53>>),
Tdb::tl_int32(giftCode.months)));
Tdb::tl_int32(giftCode.months),
Api::FormattedTextToTdb(users->message)));
} else {
return Tdb::tl_inputInvoiceTelegram(
Tdb::tl_telegramPaymentPurposePremiumGiveaway(
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/payments/payments_form.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TLsavedCredentials;
class TLshippingOption;
class TLDpaymentProviderStripe;
class TLDpaymentProviderSmartGlocal;
class TLpremiumGiveawayParameters;
class TLgiveawayParameters;
} // namespace Tdb

class Image;
Expand Down Expand Up @@ -310,7 +310,7 @@ struct FormUpdate : std::variant<
[[nodiscard]] MTPinputStorePaymentPurpose InvoiceCreditsGiveawayToTL(
const InvoicePremiumGiftCode &invoice);
#endif
[[nodiscard]] Tdb::TLpremiumGiveawayParameters InvoiceGiftCodeGiveawayToTL(
[[nodiscard]] Tdb::TLgiveawayParameters InvoiceGiftCodeGiveawayToTL(
const InvoicePremiumGiftCode &invoice);

class Form final : public base::has_weak_ptr {
Expand Down
60 changes: 60 additions & 0 deletions Telegram/SourceFiles/settings/settings_credits_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ For license and copyright information please follow this link:
#include "styles/style_settings.h"
#include "styles/style_statistics.h"

#include "tdb/tdb_tl_scheme.h"
#include "tdb/tdb_sender.h"

#include <xxhash.h> // XXH64.

#include <QtSvg/QSvgRenderer>

namespace Settings {
namespace {

using namespace Tdb;

const auto kTopUpPrefix = "cloud_lng_topup_purpose_";

[[nodiscard]] uint64 UniqueIdFromOption(
Expand Down Expand Up @@ -167,6 +172,7 @@ void ToggleStarGiftSaved(
using Flag = MTPpayments_SaveStarGift::Flag;
const auto api = &window->session().api();
const auto weak = base::make_weak(window);
#if 0 // mtp
api->request(MTPpayments_SaveStarGift(
MTP_flags(save ? Flag(0) : Flag::f_unsave),
sender->inputUser,
Expand All @@ -184,6 +190,24 @@ void ToggleStarGiftSaved(
}
done(false);
}).send();
#endif
window->session().sender().request(TLtoggleGiftIsSaved(
tl_int53(peerToUser(sender->id).bare),
tl_int53(itemId.bare),
tl_bool(save)
)).done([=] {
if (const auto strong = weak.get()) {
strong->showToast((save
? tr::lng_gift_display_done
: tr::lng_gift_display_done_hide)(tr::now));
}
done(true);
}).fail([=](const Error &error) {
if (const auto strong = weak.get()) {
strong->showToast(error.message);
}
done(false);
}).send();
}

void ConfirmConvertStarGift(
Expand Down Expand Up @@ -212,6 +236,7 @@ void ConvertStarGift(
Fn<void(bool)> done) {
const auto api = &window->session().api();
const auto weak = base::make_weak(window);
#if 0 // mtp
api->request(MTPpayments_ConvertStarGift(
sender->inputUser,
MTP_int(itemId)
Expand All @@ -231,6 +256,26 @@ void ConvertStarGift(
}
done(false);
}).send();
#endif
window->session().sender().request(TLsellGift(
tl_int53(peerToUser(sender->id).bare),
tl_int53(itemId.bare)
)).done([=] {
if (const auto strong = weak.get()) {
strong->showSettings(Settings::CreditsId());
strong->showToast(tr::lng_gift_got_stars(
tr::now,
lt_count,
stars,
Ui::Text::RichLangValue));
}
done(true);
}).fail([=](const Error &error) {
if (const auto strong = weak.get()) {
strong->showToast(error.message);
}
done(false);
}).send();
}

void AddViewMediaHandler(
Expand Down Expand Up @@ -1229,6 +1274,7 @@ void ReceiptCreditsBox(
}
});
} else {
#if 0 // mtp
using Flag = MTPpayments_ChangeStarsSubscription::Flag;
session->api().request(
MTPpayments_ChangeStarsSubscription(
Expand All @@ -1246,6 +1292,20 @@ void ReceiptCreditsBox(
}
show->showToast(error.type());
}).send();
#endif
session->sender().request(TLeditStarSubscription(
tl_string(s.id),
tl_bool(toCancel)
)).done([=] {
if (const auto strong = weak.data()) {
strong->closeBox();
}
}).fail([=, show = box->uiShow()](const Error &error) {
if (const auto strong = weak.data()) {
state->confirmButtonBusy = false;
}
show->showToast(error.message);
}).send();
}
};

Expand Down
13 changes: 1 addition & 12 deletions Telegram/SourceFiles/settings/settings_privacy_controllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,7 @@ AdminLog::OwnedItem GenerateForwardedItem(
tl_bool(false), // is_outgoing
tl_bool(false), // is_pinned
tl_bool(false), // is_from_offline
tl_bool(false), // can_be_edited
tl_bool(false), // can_be_forwarded
tl_bool(false), // can_be_replied_in_another_chat
tl_bool(true), // can_be_saved
tl_bool(true), // can_be_deleted_only_for_self
tl_bool(false), // can_be_deleted_for_all_users
tl_bool(false), // can_get_added_reactions
tl_bool(false), // can_get_statistics
tl_bool(false), // can_get_message_thread
tl_bool(false), // can_get_read_date
tl_bool(false), // can_get_viewers
tl_bool(false), // can_get_media_timestamp_links
tl_bool(false), // can_report_reactions
tl_bool(false), // has_timestamped_media
tl_bool(false), // is_channel_post
tl_bool(false), // is_topic_message
Expand Down Expand Up @@ -216,6 +204,7 @@ AdminLog::OwnedItem GenerateForwardedItem(
tl_string(), // author_signature
tl_int64(0), // media_album_id
tl_int64(0), // effect_id
tl_bool(false), // has_sensitive_content
tl_string(), // restriction_reason
tl_messageText(
tl_formattedText(tl_string(text), tl_vector<TLtextEntity>()),
Expand Down
Loading

0 comments on commit 4aa6f2a

Please sign in to comment.