From e3bc4dab8507ce6c5494322b2f2a527bb54c4999 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 16 Sep 2024 11:23:16 +0400 Subject: [PATCH] Update API scheme to layer 189. --- Telegram/SourceFiles/api/api_chat_invite.cpp | 1 - .../SourceFiles/boxes/send_credits_box.cpp | 7 +- .../export/data/export_data_types.cpp | 13 ++++ .../export/data/export_data_types.h | 77 +++++++++++-------- .../export/output/export_output_html.cpp | 5 ++ .../export/output/export_output_json.cpp | 8 ++ Telegram/SourceFiles/history/history_item.cpp | 13 ++++ Telegram/SourceFiles/mtproto/scheme/api.tl | 22 +++++- .../SourceFiles/payments/payments_form.cpp | 2 + 9 files changed, 108 insertions(+), 40 deletions(-) diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index dde941b33..be07e72ac 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -275,7 +275,6 @@ void ConfirmSubscriptionBox( : 0; state->api->request( MTPpayments_SendStarsForm( - MTP_flags(0), MTP_long(formId), MTP_inputInvoiceChatInviteSubscription(MTP_string(hash))) ).done([=](const MTPpayments_PaymentResult &result) { diff --git a/Telegram/SourceFiles/boxes/send_credits_box.cpp b/Telegram/SourceFiles/boxes/send_credits_box.cpp index efa5d46cf..1bfeb01cc 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.cpp +++ b/Telegram/SourceFiles/boxes/send_credits_box.cpp @@ -272,10 +272,13 @@ void SendCreditsBox( state->confirmButtonBusy = true; session->api().request( MTPpayments_SendStarsForm( - MTP_flags(0), MTP_long(form->formId), form->inputInvoice) - ).done([=](auto result) { + ).done([=](const MTPpayments_PaymentResult &result) { + result.match([&](const MTPDpayments_paymentResult &data) { + session->api().applyUpdates(data.vupdates()); + }, [](const MTPDpayments_paymentVerificationNeeded &data) { + }); if (weak) { state->confirmButtonBusy = false; box->closeBox(); diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index 4eb403263..7bd2d3515 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -1658,6 +1658,19 @@ ServiceAction ParseServiceAction( .giveawayMsgId = data.vgiveaway_msg_id().v, .isUnclaimed = data.is_unclaimed(), }; + }, [&](const MTPDmessageActionStarGift &data) { + const auto &gift = data.vgift().data(); + result.content = ActionStarGift{ + .giftId = uint64(gift.vid().v), + .stars = int64(gift.vstars().v), + .text = (data.vmessage() + ? ParseText( + data.vmessage()->data().vtext(), + data.vmessage()->data().ventities().v) + : std::vector()), + .anonymous = data.is_name_hidden(), + .limited = gift.is_limited(), + }; }, [](const MTPDmessageActionEmpty &data) {}); return result; } diff --git a/Telegram/SourceFiles/export/data/export_data_types.h b/Telegram/SourceFiles/export/data/export_data_types.h index d07b4de55..e07554974 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.h +++ b/Telegram/SourceFiles/export/data/export_data_types.h @@ -401,6 +401,39 @@ Media ParseMedia( const QString &folder, TimeId date); +struct TextPart { + enum class Type { + Text, + Unknown, + Mention, + Hashtag, + BotCommand, + Url, + Email, + Bold, + Italic, + Code, + Pre, + TextUrl, + MentionName, + Phone, + Cashtag, + Underline, + Strike, + Blockquote, + BankCard, + Spoiler, + CustomEmoji, + }; + Type type = Type::Text; + Utf8String text; + Utf8String additional; + + [[nodiscard]] static Utf8String UnavailableEmoji() { + return "(unavailable)"; + } +}; + struct ActionChatCreate { Utf8String title; std::vector userIds; @@ -617,6 +650,14 @@ struct ActionPrizeStars { bool isUnclaimed = false; }; +struct ActionStarGift { + uint64 giftId = 0; + int64 stars = 0; + std::vector text; + bool anonymous = false; + bool limited = false; +}; + struct ServiceAction { std::variant< v::null_t, @@ -661,7 +702,8 @@ struct ServiceAction { ActionBoostApply, ActionPaymentRefunded, ActionGiftStars, - ActionPrizeStars> content; + ActionPrizeStars, + ActionStarGift> content; }; ServiceAction ParseServiceAction( @@ -669,39 +711,6 @@ ServiceAction ParseServiceAction( const MTPMessageAction &data, const QString &mediaFolder); -struct TextPart { - enum class Type { - Text, - Unknown, - Mention, - Hashtag, - BotCommand, - Url, - Email, - Bold, - Italic, - Code, - Pre, - TextUrl, - MentionName, - Phone, - Cashtag, - Underline, - Strike, - Blockquote, - BankCard, - Spoiler, - CustomEmoji, - }; - Type type = Type::Text; - Utf8String text; - Utf8String additional; - - [[nodiscard]] static Utf8String UnavailableEmoji() { - return "(unavailable)"; - } -}; - struct Reaction { enum class Type { Empty, diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp index 21e6b0893..61f122b8d 100644 --- a/Telegram/SourceFiles/export/output/export_output_html.cpp +++ b/Telegram/SourceFiles/export/output/export_output_html.cpp @@ -1362,6 +1362,11 @@ auto HtmlWriter::Wrap::pushMessage( + ".\n Your prize is " + QString::number(data.amount).toUtf8() + " Telegram Stars."; + }, [&](const ActionStarGift &data) { + return serviceFrom + + " sent you a gift of " + + QByteArray::number(data.stars) + + " Telegram Stars."; }, [](v::null_t) { return QByteArray(); }); if (!serviceText.isEmpty()) { diff --git a/Telegram/SourceFiles/export/output/export_output_json.cpp b/Telegram/SourceFiles/export/output/export_output_json.cpp index 3dba1a90e..a91c07dbd 100644 --- a/Telegram/SourceFiles/export/output/export_output_json.cpp +++ b/Telegram/SourceFiles/export/output/export_output_json.cpp @@ -647,6 +647,14 @@ QByteArray SerializeMessage( push("is_unclaimed", data.isUnclaimed); push("giveaway_msg_id", data.giveawayMsgId); push("transaction_id", data.transactionId); + }, [&](const ActionStarGift &data) { + pushActor(); + pushAction("send_star_gift"); + push("gift_id", data.giftId); + push("stars", data.stars); + push("is_limited", data.limited); + push("is_anonymous", data.anonymous); + pushBare("text", SerializeText(context, data.text)); }, [](v::null_t) {}); if (v::is_null(message.action.content)) { diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index ea92626c4..67166e01d 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -5270,6 +5270,12 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { return result; }; + auto prepareStarGift = [&]( + const MTPDmessageActionStarGift &action) { + auto result = PreparedServiceText(); + return result; + }; + setServiceText(action.match( prepareChatAddUserText, prepareChatJoinedByLink, @@ -5315,6 +5321,7 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { preparePaymentRefunded, prepareGiftStars, prepareGiftPrize, + prepareStarGift, PrepareEmptyText, PrepareErrorText)); @@ -5427,6 +5434,12 @@ void HistoryItem::applyAction(const MTPMessageAction &action) { .viaGiveaway = true, .unclaimed = data.is_unclaimed(), }); + }, [&](const MTPDmessageActionStarGift &data) { + _media = std::make_unique( + this, + _from, + Data::GiftType::Credits, + data.vstars_amount().v); }, [](const auto &) { }); } diff --git a/Telegram/SourceFiles/mtproto/scheme/api.tl b/Telegram/SourceFiles/mtproto/scheme/api.tl index 39865d48e..261788c08 100644 --- a/Telegram/SourceFiles/mtproto/scheme/api.tl +++ b/Telegram/SourceFiles/mtproto/scheme/api.tl @@ -183,6 +183,7 @@ messageActionRequestedPeerSentMe#93b31848 button_id:int peers:Vector wallpaper:flags.24?WallPaper stories:flags.25?PeerStories business_work_hours:flags2.0?BusinessWorkHours business_location:flags2.1?BusinessLocation business_greeting_message:flags2.2?BusinessGreetingMessage business_away_message:flags2.3?BusinessAwayMessage business_intro:flags2.4?BusinessIntro birthday:flags2.5?Birthday personal_channel_id:flags2.6?long personal_channel_message:flags2.6?int = UserFull; +userFull#1f58e369 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true translations_disabled:flags.23?true stories_pinned_available:flags.26?true blocked_my_stories_from:flags.27?true wallpaper_overridden:flags.28?true contact_require_premium:flags.29?true read_dates_private:flags.30?true flags2:# sponsored_enabled:flags2.7?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector wallpaper:flags.24?WallPaper stories:flags.25?PeerStories business_work_hours:flags2.0?BusinessWorkHours business_location:flags2.1?BusinessLocation business_greeting_message:flags2.2?BusinessGreetingMessage business_away_message:flags2.3?BusinessAwayMessage business_intro:flags2.4?BusinessIntro birthday:flags2.5?Birthday personal_channel_id:flags2.6?long personal_channel_message:flags2.6?int stargifts_count:flags2.8?int = UserFull; contact#145ade0b user_id:long mutual:Bool = Contact; @@ -915,6 +916,7 @@ upload.webFile#21e753bc size:int mime_type:string file_type:storage.FileType mti payments.paymentForm#a0058751 flags:# can_save_credentials:flags.2?true password_missing:flags.3?true form_id:long bot_id:long title:string description:string photo:flags.5?WebDocument invoice:Invoice provider_id:long url:string native_provider:flags.4?string native_params:flags.4?DataJSON additional_methods:flags.6?Vector saved_info:flags.0?PaymentRequestedInfo saved_credentials:flags.1?Vector users:Vector = payments.PaymentForm; payments.paymentFormStars#7bf6b15c flags:# form_id:long bot_id:long title:string description:string photo:flags.5?WebDocument invoice:Invoice users:Vector = payments.PaymentForm; +payments.paymentFormStarGift#b425cfe1 form_id:long invoice:Invoice = payments.PaymentForm; payments.validatedRequestedInfo#d1451883 flags:# id:flags.0?string shipping_options:flags.1?Vector = payments.ValidatedRequestedInfo; @@ -1464,6 +1466,7 @@ inputInvoiceSlug#c326caef slug:string = InputInvoice; inputInvoicePremiumGiftCode#98986c0d purpose:InputStorePaymentPurpose option:PremiumGiftCodeOption = InputInvoice; inputInvoiceStars#65f00ce3 purpose:InputStorePaymentPurpose = InputInvoice; inputInvoiceChatInviteSubscription#34e793f1 hash:string = InputInvoice; +inputInvoiceStarGift#25d8c1d8 flags:# hide_name:flags.0?true user_id:InputUser gift_id:long message:flags.1?TextWithEntities = InputInvoice; payments.exportedInvoice#aed0cbd9 url:string = payments.ExportedInvoice; @@ -1859,6 +1862,15 @@ starsGiveawayOption#94ce852a flags:# extended:flags.0?true default:flags.1?true starsGiveawayWinnersOption#54236209 flags:# default:flags.0?true users:int per_user_stars:long = StarsGiveawayWinnersOption; +starGift#aea174ee flags:# limited:flags.0?true id:long sticker:Document stars:long availability_remains:flags.0?int availability_total:flags.0?int convert_stars:long = StarGift; + +payments.starGiftsNotModified#a388a368 = payments.StarGifts; +payments.starGifts#901689ea hash:int gifts:Vector = payments.StarGifts; + +userStarGift#eea49a6e flags:# name_hidden:flags.0?true unsaved:flags.5?true from_id:flags.1?long date:int gift:StarGift message:flags.2?TextWithEntities msg_id:flags.3?int convert_stars:flags.4?long = UserStarGift; + +payments.userStarGifts#6b65b517 flags:# count:int gifts:Vector next_offset:flags.0?string users:Vector = payments.UserStarGifts; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -2413,7 +2425,7 @@ payments.launchPrepaidGiveaway#5ff58f20 peer:InputPeer giveaway_id:long purpose: payments.getStarsTopupOptions#c00ec7d3 = Vector; payments.getStarsStatus#104fcfa7 peer:InputPeer = payments.StarsStatus; payments.getStarsTransactions#69da4557 flags:# inbound:flags.0?true outbound:flags.1?true ascending:flags.2?true subscription_id:flags.3?string peer:InputPeer offset:string limit:int = payments.StarsStatus; -payments.sendStarsForm#2bb731d flags:# form_id:long invoice:InputInvoice = payments.PaymentResult; +payments.sendStarsForm#7998c914 form_id:long invoice:InputInvoice = payments.PaymentResult; payments.refundStarsCharge#25ae8f4a user_id:InputUser charge_id:string = Updates; payments.getStarsRevenueStats#d91ffad6 flags:# dark:flags.0?true peer:InputPeer = payments.StarsRevenueStats; payments.getStarsRevenueWithdrawalUrl#13bbe8b3 peer:InputPeer stars:long password:InputCheckPasswordSRP = payments.StarsRevenueWithdrawalUrl; @@ -2424,6 +2436,10 @@ payments.getStarsSubscriptions#32512c5 flags:# missing_balance:flags.0?true peer payments.changeStarsSubscription#c7770878 flags:# peer:InputPeer subscription_id:string canceled:flags.0?Bool = Bool; payments.fulfillStarsSubscription#cc5bebb3 peer:InputPeer subscription_id:string = Bool; payments.getStarsGiveawayOptions#bd1efd3e = Vector; +payments.getStarGifts#c4563590 hash:int = payments.StarGifts; +payments.getUserStarGifts#5e72c7e1 user_id:InputUser offset:string limit:int = payments.UserStarGifts; +payments.saveStarGift#87acf08e flags:# unsave:flags.0?true user_id:InputUser msg_id:int = Bool; +payments.convertStarGift#421e027 user_id:InputUser msg_id:int = Bool; stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true emojis:flags.5?true text_color:flags.6?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector software:flags.3?string = messages.StickerSet; stickers.removeStickerFromSet#f7760f51 sticker:InputDocument = messages.StickerSet; @@ -2543,4 +2559,4 @@ smsjobs.finishJob#4f1ebf24 flags:# job_id:string error:flags.0?string = Bool; fragment.getCollectibleInfo#be1e85ba collectible:InputCollectible = fragment.CollectibleInfo; -// LAYER 188 +// LAYER 189 diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 472de9d9c..bddfb5321 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -460,6 +460,8 @@ void Form::requestForm() { .inputInvoice = inputInvoice(), }; _updates.fire(CreditsPaymentStarted{ .data = formData }); + }, [&](const MTPDpayments_paymentFormStarGift &data) { + // todo pay for star gift. }); }).fail([=](const MTP::Error &error) { hideProgress();