From 129a04b24d890a950851ceaf3f17944e064d0d69 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 13 Oct 2023 13:28:01 +0300 Subject: [PATCH] Add pushMessageContentPremiumGiveaway. --- td/generate/scheme/td_api.tl | 8 +++++++- td/telegram/NotificationManager.cpp | 21 +++++++++++++++++++++ td/telegram/NotificationType.cpp | 12 ++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 794a3e3b7..2392982ff 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2810,7 +2810,7 @@ messageGiftedPremium gifter_user_id:int53 currency:string amount:int53 cryptocur //@code The gift code messagePremiumGiftCode creator_id:MessageSender is_from_giveaway:Bool month_count:int32 code:string = MessageContent; -//@description A Telegram Premium giveaway is scheduled by channel chats +//@description A Telegram Premium giveaway was created //@parameters Giveaway parameters //@user_count Number of users which will receive Telegram Premium subscription gift codes //@month_count Number of month the Telegram Premium subscription will be active after code activation @@ -4785,6 +4785,12 @@ pushMessageContentPoll question:string is_regular:Bool is_pinned:Bool = PushMess //@description A message with a Telegram Premium gift code created for the user @month_count Number of month the Telegram Premium subscription will be active after code activation pushMessageContentPremiumGiftCode month_count:int32 = PushMessageContent; +//@description A message with a Telegram Premium giveaway +//@user_count Number of users which will receive Telegram Premium subscription gift codes; 0 for pinned message +//@month_count Number of month the Telegram Premium subscription will be active after code activation; 0 for pinned message +//@is_pinned True, if the message is a pinned message with the specified content +pushMessageContentPremiumGiveaway user_count:int32 month_count:int32 is_pinned:Bool = PushMessageContent; + //@description A screenshot of a message in the chat has been taken pushMessageContentScreenshotTaken = PushMessageContent; diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 7ce8e4c3b..2e1280b1d 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -2890,6 +2890,9 @@ string NotificationManager::convert_loc_key(const string &loc_key) { if (loc_key == "MESSAGE_GIFTCODE") { return "MESSAGE_GIFTCODE"; } + if (loc_key == "MESSAGE_GIVEAWAY") { + return "MESSAGE_GIVEAWAY"; + } break; case 'H': if (loc_key == "PINNED_PHOTO") { @@ -2903,6 +2906,9 @@ string NotificationManager::convert_loc_key(const string &loc_key) { if (loc_key == "PINNED_GIF") { return "PINNED_MESSAGE_ANIMATION"; } + if (loc_key == "PINNED_GIVEAWAY") { + return "PINNED_MESSAGE_GIVEAWAY"; + } if (loc_key == "MESSAGE_INVOICE") { return "MESSAGE_INVOICE"; } @@ -3421,6 +3427,21 @@ Status NotificationManager::process_push_notification_payload(string payload, bo arg = PSTRING() << loc_args[1] << ' ' << loc_args[0]; loc_args.clear(); } + if (loc_key == "MESSAGE_GIVEAWAY") { + if (loc_args.size() != 2) { + return Status::Error("Expected 2 arguments for MESSAGE_GIVEAWAY"); + } + TRY_RESULT(user_count, to_integer_safe(loc_args[0])); + if (user_count <= 0) { + return Status::Error("Expected user count to be non-negative"); + } + TRY_RESULT(month_count, to_integer_safe(loc_args[1])); + if (month_count <= 0) { + return Status::Error("Expected month count to be non-negative"); + } + arg = PSTRING() << user_count << ' ' << month_count; + loc_args.clear(); + } if (loc_args.size() > 1) { return Status::Error("Receive too many arguments"); } diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp index 285b59b27..9a81fbb61 100644 --- a/td/telegram/NotificationType.cpp +++ b/td/telegram/NotificationType.cpp @@ -258,6 +258,18 @@ class NotificationTypePushMessage final : public NotificationType { int32 month_count = to_integer(arg); return td_api::make_object(month_count); } + if (key == "MESSAGE_GIVEAWAY") { + int32 user_count = 0; + int32 month_count = 0; + if (!is_pinned) { + string user_count_str; + string month_count_str; + std::tie(user_count_str, month_count_str) = split(arg); + user_count = to_integer(user_count_str); + month_count = to_integer(month_count_str); + } + return td_api::make_object(user_count, month_count, is_pinned); + } break; case 'I': if (key == "MESSAGE_INVOICE") {