Skip to content

Commit

Permalink
Update TDLib to 1.8.21.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Nov 17, 2023
1 parent a0be4c5 commit 74f3cb3
Show file tree
Hide file tree
Showing 41 changed files with 1,117 additions and 222 deletions.
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/api/api_polls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void Polls::create(

_api.request(Tdb::TLsendMessage(
peerToTdbChat(peer->id),
Tdb::tl_int53(action.replyTo.topicRootId.bare),
MessageThreadId(peer, action),
MessageReplyTo(action),
MessageSendOptions(peer, action),
PollToTL(&data)
Expand Down
87 changes: 87 additions & 0 deletions Telegram/SourceFiles/api/api_premium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ namespace {

using namespace Tdb;

[[nodiscard]] GiftCode Parse(const TLDpremiumGiftCodeInfo &data) {
return {
.from = peerFromSender(data.vcreator_id()),
.to = data.vuser_id().v ? peerFromUser(data.vuser_id()) : PeerId(),
.giveawayId = data.vgiveaway_message_id().v,
.date = data.vcreation_date().v,
.used = data.vuse_date().v,
.months = data.vmonth_count().v,
.giveaway = data.vis_from_giveaway().v,
};
}

#if 0 // mtp
[[nodiscard]] GiftCode Parse(const MTPDpayments_checkedGiftCode &data) {
return {
.from = peerFromMTP(data.vfrom_id()),
Expand Down Expand Up @@ -59,6 +72,7 @@ using namespace Tdb;
}
return options;
}
#endif

} // namespace

Expand Down Expand Up @@ -398,6 +412,16 @@ void Premium::checkGiftCode(
_api.request(_giftCodeRequestId).cancel();
}
_giftCodeSlug = slug;
_giftCodeRequestId = _api.request(TLcheckPremiumGiftCode(
tl_string(slug)
)).done([=](const TLDpremiumGiftCodeInfo &data) {
_giftCodeRequestId = 0;
done(updateGiftCode(slug, Parse(data)));
}).fail([=] {
_giftCodeRequestId = 0;
done(updateGiftCode(slug, {}));
}).send();
#if 0 // mtp
_giftCodeRequestId = _api.request(MTPpayments_CheckGiftCode(
MTP_string(slug)
)).done([=](const MTPpayments_CheckedGiftCode &result) {
Expand All @@ -412,6 +436,7 @@ void Premium::checkGiftCode(

done(updateGiftCode(slug, {}));
}).send();
#endif
}

GiftCode Premium::updateGiftCode(
Expand All @@ -435,6 +460,14 @@ rpl::producer<GiftCode> Premium::giftCodeValue(const QString &slug) const {
}

void Premium::applyGiftCode(const QString &slug, Fn<void(QString)> done) {
_api.request(TLapplyPremiumGiftCode(
tl_string(slug)
)).done([=] {
done({});
}).fail([=](const Error &error) {
done(error.message);
}).send();
#if 0 // mtp
_api.request(MTPpayments_ApplyGiftCode(
MTP_string(slug)
)).done([=](const MTPUpdates &result) {
Expand All @@ -443,6 +476,7 @@ void Premium::applyGiftCode(const QString &slug, Fn<void(QString)> done) {
}).fail([=](const MTP::Error &error) {
done(error.type());
}).send();
#endif
}

void Premium::resolveGiveawayInfo(
Expand All @@ -461,6 +495,7 @@ void Premium::resolveGiveawayInfo(
}
_giveawayInfoPeer = peer;
_giveawayInfoMessageId = messageId;
#if 0 // mtp
_giveawayInfoRequestId = _api.request(MTPpayments_GetGiveawayInfo(
_giveawayInfoPeer->input,
MTP_int(_giveawayInfoMessageId.bare)
Expand Down Expand Up @@ -490,6 +525,49 @@ void Premium::resolveGiveawayInfo(
info.finishDate = data.vfinish_date().v;
info.startDate = data.vstart_date().v;
});
#endif
_giveawayInfoRequestId = _api.request(TLgetPremiumGiveawayInfo(
peerToTdbChat(_giveawayInfoPeer->id),
tl_int53(_giveawayInfoMessageId.bare)
)).done([=](const TLpremiumGiveawayInfo &result) {
_giveawayInfoRequestId = 0;

auto info = GiveawayInfo();
result.match([&](const TLDpremiumGiveawayInfoOngoing &data) {
using AlreadyWasMember
= TLDpremiumGiveawayParticipantStatusAlreadyWasMember;
using Participating
= TLDpremiumGiveawayParticipantStatusParticipating;
using Administrator
= TLDpremiumGiveawayParticipantStatusAdministrator;
using DisallowedCountry
= TLDpremiumGiveawayParticipantStatusDisallowedCountry;

data.vstatus().match([&](
const TLDpremiumGiveawayParticipantStatusEligible &) {
}, [&](const Participating &) {
info.participating = true;
}, [&](const AlreadyWasMember &data) {
info.tooEarlyDate = data.vjoined_chat_date().v;
}, [&](const Administrator &data) {
info.adminChannelId = peerToChannel(
peerFromTdbChat(data.vchat_id()));
}, [&](const DisallowedCountry &data) {
info.disallowedCountry = data.vuser_country_code().v;
});
info.state = data.vis_ended().v
? GiveawayState::Preparing
: GiveawayState::Running;
info.startDate = data.vcreation_date().v;
}, [&](const TLDpremiumGiveawayInfoCompleted &data) {
info.state = data.vwas_refunded().v
? GiveawayState::Refunded
: GiveawayState::Finished;
info.giftCode = data.vgift_code().v;
info.activatedCount = data.vactivation_count().v;
info.finishDate = data.vactual_winners_selection_date().v;
info.startDate = data.vcreation_date().v;
});
_giveawayInfoDone(std::move(info));
}).fail([=] {
_giveawayInfoRequestId = 0;
Expand All @@ -503,7 +581,10 @@ const Data::SubscriptionOptions &Premium::subscriptionOptions() const {

PremiumGiftCodeOptions::PremiumGiftCodeOptions(not_null<PeerData*> peer)
: _peer(peer)
#if 0 // mtp
, _api(&peer->session().api().instance()) {
#endif
, _api(&peer->session().sender()) {
}

rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::request() {
Expand All @@ -514,6 +595,7 @@ rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::request() {
return lifetime;
}

#if 0 // todo
using TLOption = MTPPremiumGiftCodeOption;
_api.request(MTPpayments_GetPremiumGiftCodeOptions(
MTP_flags(
Expand Down Expand Up @@ -552,6 +634,7 @@ rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::request() {
}).fail([=](const MTP::Error &error) {
consumer.put_error_copy(error.type());
}).send();
#endif

return lifetime;
};
Expand All @@ -567,6 +650,7 @@ rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::applyPrepaid(
return lifetime;
}

#if 0 // todo
_api.request(MTPpayments_LaunchPrepaidGiveaway(
_peer->input,
MTP_long(prepaidId),
Expand All @@ -577,6 +661,7 @@ rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::applyPrepaid(
}).fail([=](const MTP::Error &error) {
consumer.put_error_copy(error.type());
}).send();
#endif

return lifetime;
};
Expand Down Expand Up @@ -612,6 +697,7 @@ Data::SubscriptionOptions PremiumGiftCodeOptions::options(int amount) {
if (it != end(_subscriptionOptions)) {
return it->second;
} else {
#if 0 // todo
auto tlOptions = QVector<MTPPremiumGiftCodeOption>();
for (auto i = 0; i < _optionsForOnePerson.months.size(); i++) {
tlOptions.push_back(MTP_premiumGiftCodeOption(
Expand All @@ -624,6 +710,7 @@ Data::SubscriptionOptions PremiumGiftCodeOptions::options(int amount) {
MTP_long(_optionsForOnePerson.totalCosts[i] * amount)));
}
_subscriptionOptions[amount] = GiftCodesFromTL(tlOptions);
#endif
return _subscriptionOptions[amount];
}
}
Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/api/api_premium.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ class PremiumGiftCodeOptions final {

base::flat_map<Token, Store> _stores;

#if 0 // mtp
MTP::Sender _api;
#endif
Tdb::Sender _api;

};

Expand Down
64 changes: 49 additions & 15 deletions Telegram/SourceFiles/api/api_sending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ For license and copyright information please follow this link:
#include "tdb/tdb_file_generator.h"
#include "tdb/tdb_tl_scheme.h"
#include "inline_bots/inline_bot_result.h"
#include "data/data_forum_topic.h"

namespace Api {
namespace {
Expand Down Expand Up @@ -414,16 +415,16 @@ void SendPreparedAlbumIfReady(
const auto session = &peer->session();
session->sender().request(TLsendMessageAlbum(
peerToTdbChat(peer->id),
tl_int53(action.replyTo.topicRootId.bare),
MessageThreadId(peer, action),
MessageReplyTo(action),
tl_messageSendOptions(
tl_bool(silentPost),
tl_bool(false), // from_background
tl_bool(false), // update_order_of_installed_stickers_sets
ScheduledToTL(action.options.scheduled),
tl_int32(0)), // sending_id
tl_vector(std::move(contents)),
tl_bool(false) // only_preview
tl_int32(0), // sending_id
tl_bool(false)), // only_preview
tl_vector(std::move(contents))
)).done([=](const TLmessages &result) {
// They should've been added by updates.
}).fail([=](const Error &error) {
Expand Down Expand Up @@ -587,7 +588,7 @@ bool SendDice(MessageToSend &message) {
const auto &action = message.action;
session->sender().request(TLsendMessage(
peerToTdbChat(peer->id),
tl_int53(action.replyTo.topicRootId.bare),
MessageThreadId(peer, action),
MessageReplyTo(action),
MessageSendOptions(peer, action),
tl_inputMessageDice(tl_string(emoji), tl_bool(action.clearDraft))
Expand Down Expand Up @@ -888,23 +889,56 @@ TLmessageSendOptions MessageSendOptions(
tl_bool(false), // from_background
tl_bool(false), // update_order_of_installed_stickers_sets
ScheduledToTL(action.options.scheduled),
tl_int32(sendingId));
tl_int32(sendingId),
tl_bool(false)); // only_preview
}

std::optional<TLmessageReplyTo> MessageReplyTo(
const SendAction &action) {
if (const auto &storyId = action.replyTo.storyId) {
return tl_messageReplyToStory(
std::optional<TLinputMessageReplyTo> MessageReplyTo(
not_null<History*> history,
const FullReplyTo &replyTo) {
if (const auto &storyId = replyTo.storyId) {
return tl_inputMessageReplyToStory(
peerToTdbChat(storyId.peer),
tl_int32(storyId.story));
} else if (const auto to = action.replyTo.msgId) {
return tl_messageReplyToMessage(
peerToTdbChat(action.history->peer->id),
tl_int53(to.bare));
} else if (const auto messageId = replyTo.messageId) {
// Complex logic for external replies.
// Reply should be external if done to another thread.
const auto to = LookupReplyTo(history, messageId);
const auto replyingToTopic = replyTo.topicRootId
? history->peer->forumTopicFor(replyTo.topicRootId)
: nullptr;
const auto replyingToTopicId = replyTo.topicRootId
? (replyingToTopic
? replyingToTopic->rootId()
: Data::ForumTopic::kGeneralId)
: (to ? to->topicRootId() : Data::ForumTopic::kGeneralId);
const auto replyToTopicId = to
? to->topicRootId()
: replyingToTopicId;
const auto external = (replyTo.messageId.peer != history->peer->id)
|| (replyingToTopicId != replyToTopicId);

return tl_inputMessageReplyToMessage(
external ? peerToTdbChat(messageId.peer) : tl_int53(0),
tl_int53(messageId.msg.bare),
(replyTo.quote.empty()
? std::optional<TLformattedText>()
: Api::FormattedTextToTdb(replyTo.quote)));
}
return std::nullopt;
}

std::optional<TLinputMessageReplyTo> MessageReplyTo(
const SendAction &action) {
return MessageReplyTo(action.history, action.replyTo);
}

TLint53 MessageThreadId(
not_null<PeerData*> peer,
const SendAction &action) {
return tl_int53(action.replyTo.topicRootId.bare);
}

void SendPreparedMessage(
const SendAction &action,
TLinputMessageContent content,
Expand All @@ -924,7 +958,7 @@ void SendPreparedMessage(
const auto sendingId = ClientMsgIndex(localId);
session->sender().request(TLsendMessage(
peerToTdbChat(peer->id),
tl_int53(topicRootId.bare),
MessageThreadId(peer, action),
MessageReplyTo(action),
MessageSendOptions(peer, action, sendingId),
std::move(content)
Expand Down
15 changes: 13 additions & 2 deletions Telegram/SourceFiles/api/api_sending.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ class PhotoData;
class DocumentData;
struct FileLoadResult;

namespace tl {
class int64_type;
} // namespace tl

namespace Tdb {
class TLinputMessageContent;
class TLmessageSchedulingState;
class TLmessageSendOptions;
class TLmessageReplyTo;
class TLinputMessageReplyTo;
using TLint53 = tl::int64_type;
} // namespace Tdb

namespace InlineBots {
Expand Down Expand Up @@ -57,7 +62,13 @@ void SendConfirmedFile(
not_null<PeerData*> peer,
const SendAction &action,
int32 sendingId = 0);
[[nodiscard]] std::optional<Tdb::TLmessageReplyTo> MessageReplyTo(
[[nodiscard]] std::optional<Tdb::TLinputMessageReplyTo> MessageReplyTo(
not_null<History*> history,
const FullReplyTo &replyTo);
[[nodiscard]] std::optional<Tdb::TLinputMessageReplyTo> MessageReplyTo(
const SendAction &action);
[[nodiscard]] Tdb::TLint53 MessageThreadId(
not_null<PeerData*> peer,
const SendAction &action);

void SendPreparedMessage(
Expand Down
Loading

0 comments on commit 74f3cb3

Please sign in to comment.