Skip to content

Commit

Permalink
Migrate paid reactions to TDLib.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Nov 7, 2024
1 parent ddd90e7 commit d8cc38d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Telegram/SourceFiles/data/data_message_reactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2234,20 +2234,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 @@ -2269,6 +2279,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 @@ -2280,19 +2291,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

0 comments on commit d8cc38d

Please sign in to comment.