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 618e7f5 commit f8e913c
Show file tree
Hide file tree
Showing 39 changed files with 516 additions and 172 deletions.
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/data/components/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ For license and copyright information please follow this link:
#include "main/main_app_config.h"
#include "main/main_session.h"

#include "tdb/tdb_tl_scheme.h"

namespace Data {
namespace {

Expand All @@ -26,9 +28,14 @@ Credits::Credits(not_null<Main::Session*> session)

Credits::~Credits() = default;

#if 0 // mtp
void Credits::apply(const MTPDupdateStarsBalance &data) {
apply(data.vbalance().v);
}
#endif
void Credits::apply(const Tdb::TLDupdateOwnedStarCount &data) {
apply(data.vstar_count().v);
}

rpl::producer<float64> Credits::rateValue(
not_null<PeerData*> ownedBotOrChannel) {
Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/data/components/credits.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace Main {
class Session;
} // namespace Main

namespace Tdb {
class TLDupdateOwnedStarCount;
} // namespace Tdb

namespace Data {

class Credits final {
Expand All @@ -40,7 +44,10 @@ class Credits final {
void withdrawLocked(int count);
void invalidate();

#if 0 // mtp
void apply(const MTPDupdateStarsBalance &data);
#endif
void apply(const Tdb::TLDupdateOwnedStarCount &data);

private:
void updateNonLockedValue();
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/data/components/sponsored_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ void SponsoredMessages::clicked(
const auto id = DeserializeRandomId(entryPtr->sponsored.randomId);
_session->sender().request(TLclickChatSponsoredMessage(
peerToTdbChat(id.peer),
tl_int53(id.msg.bare)
tl_int53(id.msg.bare),
tl_bool(isMedia),
tl_bool(isFullscreen)
)).send();
#if 0 // mtp
const auto randomId = entryPtr->sponsored.randomId;
Expand Down
15 changes: 7 additions & 8 deletions Telegram/SourceFiles/data/data_media_preload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ For license and copyright information please follow this link:
#include "media/streaming/media_streaming_reader.h"
#include "storage/file_download.h" // kMaxFileInMemory.

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

namespace Data {
namespace {

using namespace Tdb;

constexpr auto kDefaultPreloadPrefix = 4 * 1024 * 1024;

[[nodiscard]] int64 ChoosePreloadPrefix(not_null<DocumentData*> video) {
Expand Down Expand Up @@ -208,13 +213,6 @@ bool VideoPreload::setWebFileSizeHook(int64 size) {
}
#endif

[[nodiscard]] int ChoosePreloadPrefix(not_null<DocumentData*> document) {
const auto prefix = document->videoPreloadPrefix();
const auto part = Storage::kDownloadPartSize;
const auto parts = (prefix + part - 1) / part;
return std::min(int64(parts) * part, document->size);
}

[[nodiscard]] QByteArray PackPreload(const QByteArray &bytes, int64 full) {
if (bytes.isEmpty()) {
return {};
Expand Down Expand Up @@ -244,6 +242,7 @@ VideoPreload::VideoPreload(
not_null<DocumentData*> video,
Fn<void()> done)
: MediaPreload(std::move(done))
, _video(video)
, _session(&video->session())
, _sender(&_session->sender())
, _full(video->size)
Expand Down Expand Up @@ -334,7 +333,7 @@ void VideoPreload::startWith(const TLDlocalFile &data) {
});
}
}).fail([=] {
done();
done({});
}).send();
}
}
Expand Down
21 changes: 16 additions & 5 deletions Telegram/SourceFiles/data/data_media_preload.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ For license and copyright information please follow this link:

#include "storage/download_manager_mtproto.h"

#include "tdb/tdb_sender.h"

namespace Tdb {
class TLDlocalFile;
} // namespace Tdb

namespace Main {
class Session;
} // namespace Main

namespace Data {

class PhotoMedia;
Expand Down Expand Up @@ -98,15 +108,16 @@ class VideoPreload final
void load();
void done(QByteArray result);

void startWith(const TLDlocalFile &data);
bool continueWith(const TLDlocalFile &data);
void finishWith(const TLDlocalFile &data);
void startWith(const Tdb::TLDlocalFile &data);
bool continueWith(const Tdb::TLDlocalFile &data);
void finishWith(const Tdb::TLDlocalFile &data);

const not_null<DocumentData*> _video;
const not_null<Main::Session*> _session;
Sender _sender;
Tdb::Sender _sender;
int64 _full = 0;
FileId _fileId = 0;
int _prefix = 0;
int64 _prefix = 0;

rpl::lifetime _downloadLifetime;

Expand Down
21 changes: 15 additions & 6 deletions Telegram/SourceFiles/data/data_media_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,18 @@ bool IsFirstVideo(const Invoice &invoice) {

GiveawayStart ComputeGiveawayStartData(
not_null<HistoryItem*> item,
const TLDmessagePremiumGiveaway &data) {
const TLDmessageGiveaway &data) {
const auto &fields = data.vparameters().data();
auto result = GiveawayStart{
.untilDate = fields.vwinners_selection_date().v,
.quantity = data.vwinner_count().v,
.months = data.vmonth_count().v,
.all = !fields.vonly_new_members().v,
};
data.vprize().match([&](const TLDgiveawayPrizePremium &data) {
result.months = data.vmonth_count().v;
}, [&](const TLDgiveawayPrizeStars &data) {
result.credits = data.vstar_count().v;
});
const auto &list = fields.vadditional_chat_ids().v;
result.channels.reserve(1 + list.size());
const auto owner = &item->history()->owner();
Expand All @@ -658,7 +662,7 @@ GiveawayStart ComputeGiveawayStartData(

GiveawayResults ComputeGiveawayResultsData(
not_null<HistoryItem*> item,
const TLDmessagePremiumGiveawayWinners &data) {
const TLDmessageGiveawayWinners &data) {
auto result = GiveawayResults{
.channel = item->history()->owner().channel(
peerToChannel(peerFromTdbChat(data.vboosted_chat_id()))),
Expand All @@ -667,10 +671,14 @@ GiveawayResults ComputeGiveawayResultsData(
.additionalPeersCount = data.vadditional_chat_count().v,
.winnersCount = data.vwinner_count().v,
.unclaimedCount = data.vunclaimed_prize_count().v,
.months = data.vmonth_count().v,
.refunded = data.vwas_refunded().v,
.all = !data.vonly_new_members().v,
};
data.vprize().match([&](const TLDgiveawayPrizePremium &data) {
result.months = data.vmonth_count().v;
}, [&](const TLDgiveawayPrizeStars &data) {
result.credits = data.vstar_count().v;
});
result.winners.reserve(data.vwinner_user_ids().v.size());
const auto owner = &item->history()->owner();
for (const auto &id : data.vwinner_user_ids().v) {
Expand Down Expand Up @@ -2517,9 +2525,10 @@ MediaGiftBox::MediaGiftBox(
MediaGiftBox::MediaGiftBox(
not_null<HistoryItem*> parent,
not_null<PeerData*> from,
int months,
GiftType type,
int count,
DocumentData *sticker)
: MediaGiftBox(parent, from, GiftCode{ .months = months }, sticker) {
: MediaGiftBox(parent, from, { .count = count, .type = type }, sticker) {
}

MediaGiftBox::MediaGiftBox(
Expand Down
11 changes: 6 additions & 5 deletions Telegram/SourceFiles/data/data_media_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class TLDmessageInvoice;
class TLDmessageCall;
class TLDmessageDice;
class TLmessageContent;
class TLDmessagePremiumGiveaway;
class TLDmessagePremiumGiveawayWinners;
class TLDmessageGiveaway;
class TLDmessageGiveawayWinners;
} // namespace Tdb

class Image;
Expand Down Expand Up @@ -661,7 +661,8 @@ class MediaGiftBox final : public Media {
MediaGiftBox(
not_null<HistoryItem*> parent,
not_null<PeerData*> from,
int months,
GiftType type,
int count,
DocumentData *sticker);
MediaGiftBox(
not_null<HistoryItem*> parent,
Expand Down Expand Up @@ -857,10 +858,10 @@ class MediaGiveawayResults final : public Media {

[[nodiscard]] GiveawayStart ComputeGiveawayStartData(
not_null<HistoryItem*> item,
const Tdb::TLDmessagePremiumGiveaway &data);
const Tdb::TLDmessageGiveaway &data);

[[nodiscard]] GiveawayResults ComputeGiveawayResultsData(
not_null<HistoryItem*> item,
const Tdb::TLDmessagePremiumGiveawayWinners &data);
const Tdb::TLDmessageGiveawayWinners &data);

} // namespace Data
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/data/data_message_reaction_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ ReactionId ReactionFromTL(const TLreactionType &reaction) {
return ReactionId{ data.vemoji().v };
}, [&](const TLDreactionTypeCustomEmoji &data) {
return ReactionId{ DocumentId(data.vcustom_emoji_id().v) };
}, [](const TLDreactionTypePaid &) {
return ReactionId::Paid();
});
}

Expand Down
48 changes: 47 additions & 1 deletion Telegram/SourceFiles/data/data_message_reactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ Reactions::Reactions(not_null<Session*> owner)
}, _lifetime);
});
#endif
{
}

Reactions::~Reactions() = default;
Expand Down Expand Up @@ -2233,20 +2232,30 @@ void Reactions::sendPaidPrivacyRequest(
Expects(!send.count);

const auto id = item->fullId();
#if 0 // mtp
auto &api = _owner->session().api();
const auto requestId = api.request(
MTPmessages_TogglePaidReactionPrivacy(
item->history()->peer->input,
MTP_int(id.msg),
MTP_bool(*send.anonymous))
#endif
const auto requestId = _owner->session().sender().request(
TLtogglePaidMessageReactionIsAnonymous(
peerToTdbChat(item->history()->peer->id),
tl_int53(id.msg.bare),
tl_bool(*send.anonymous))
).done([=] {
if (const auto item = _owner->message(id)) {
if (_sendingPaid.remove(item)) {
sendPaidFinish(item, send, true);
}
}
checkQuitPreventFinished();
#if 0 // mtp
}).fail([=](const MTP::Error &error) {
#endif
}).fail([=](const Error &error) {
if (const auto item = _owner->message(id)) {
if (_sendingPaid.remove(item)) {
sendPaidFinish(item, send, false);
Expand All @@ -2268,6 +2277,7 @@ void Reactions::sendPaidRequest(
}

const auto id = item->fullId();
#if 0 // mtp
const auto randomId = base::unixtime::mtproto_msg_id();
auto &api = _owner->session().api();
using Flag = MTPmessages_SendPaidReaction::Flag;
Expand All @@ -2279,19 +2289,55 @@ void Reactions::sendPaidRequest(
MTP_long(randomId),
MTP_bool(send.anonymous.value_or(false))
)).done([=](const MTPUpdates &result) {
#endif
const auto requestId = _owner->session().sender().request(
TLaddPendingPaidMessageReaction(
peerToTdbChat(id.peer),
tl_int53(id.msg.bare),
tl_int53(send.count),
tl_bool(!send.anonymous.has_value()),
tl_bool(send.anonymous.value_or(false)))
).done([=] {
const auto item = _owner->message(id);
if (!item) {
checkQuitPreventFinished();
return;
}
_sendingPaid[item] = _owner->session().sender().request(
TLcommitPendingPaidMessageReactions(
peerToTdbChat(id.peer),
tl_int53(id.msg.bare))
).done([=] {

if (const auto item = _owner->message(id)) {
if (_sendingPaid.remove(item)) {
sendPaidFinish(item, send, true);
}
}
#if 0 // mtp
_owner->session().api().applyUpdates(result);
#endif
checkQuitPreventFinished();

}).fail([=] {
if (const auto item = _owner->message(id)) {
_sendingPaid.remove(item);
sendPaidFinish(item, send, false);
}
checkQuitPreventFinished();
}).send();
#if 0 // mtp
}).fail([=](const MTP::Error &error) {
#endif
}).fail([=] {
if (const auto item = _owner->message(id)) {
_sendingPaid.remove(item);
#if 0 // mtp
if (error.type() == u"RANDOM_ID_EXPIRED"_q) {
sendPaidRequest(item, send);
} else {
#endif
{
sendPaidFinish(item, send, false);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/data/data_message_reactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,13 @@ class Reactions final : private CustomEmojiManager::Listener {
base::flat_set<not_null<HistoryItem*>> _pollItems;
base::flat_set<not_null<HistoryItem*>> _pollingItems;
mtpRequestId _pollRequestId = 0;
#endif

base::flat_map<not_null<HistoryItem*>, crl::time> _sendPaidItems;
base::flat_map<not_null<HistoryItem*>, mtpRequestId> _sendingPaid;
base::Timer _sendPaidTimer;

#if 0 // mtp
mtpRequestId _saveFaveRequestId = 0;
#endif

Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/data/data_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ QImage PeerData::GenerateUserpicImage(
int size,
std::optional<int> radius) {
if (const auto user = peer->secretChatUser()) {
return user->generateUserpicImage(view, size, radius);
return GenerateUserpicImage(user, view, size, radius);
}
if (const auto userpic = peer->userpicCloudImage(view)) {
auto image = userpic->scaled(
Expand Down
Loading

0 comments on commit f8e913c

Please sign in to comment.