diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5e227ffb7..b0f344282 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2511,6 +2511,9 @@ getTemporaryPasswordState = TemporaryPasswordState; //@description Handles a DC_UPDATE push service notification. Can be called before authorization @dc Value of the "dc" parameter of the notification @addr Value of the "addr" parameter of the notification processDcUpdate dc:string addr:string = Ok; +//@description Handles a push notification. Can be called before authorization @payload Push notification payload +processPushNotification payload:string = Ok; + //@description Returns the current user getMe = User; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 632d9d5cc..ee6a6396b 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index fad8dfeed..bfbf8ec5a 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -1842,6 +1842,11 @@ void NotificationManager::on_notification_default_delay_changed() { VLOG(notifications) << "Set notification_default_delay_ms to " << notification_default_delay_ms_; } +void NotificationManager::process_push_notification(const string &payload, Promise &&promise) { + VLOG(notifications) << "Process push notification \"" << payload << '"'; + promise.set_value(Unit()); +} + void NotificationManager::before_get_difference() { if (is_disabled()) { return; diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 288252661..5680939b6 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -85,6 +85,8 @@ class NotificationManager : public Actor { void on_notification_default_delay_changed(); + void process_push_notification(const string &payload, Promise &&promise); + void before_get_difference(); void after_get_difference(); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index d1f220cde..303d1478c 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3220,6 +3220,7 @@ bool Td::is_preinitialization_request(int32 id) { bool Td::is_preauthentication_request(int32 id) { switch (id) { case td_api::processDcUpdate::ID: + case td_api::processPushNotification::ID: case td_api::getLocalizationTargetInfo::ID: case td_api::getLanguagePackStrings::ID: case td_api::setCustomLanguagePack::ID: @@ -4015,6 +4016,7 @@ Status Td::init(DbKey key) { complete_pending_preauthentication_requests([](int32 id) { switch (id) { case td_api::processDcUpdate::ID: + case td_api::processPushNotification::ID: case td_api::setNetworkType::ID: case td_api::getNetworkStatistics::ID: case td_api::addNetworkStatistics::ID: @@ -4691,6 +4693,13 @@ void Td::on_request(uint64 id, td_api::processDcUpdate &request) { std::move(promise)); } +void Td::on_request(uint64 id, td_api::processPushNotification &request) { + CLEAN_INPUT_STRING(request.payload_); + CREATE_OK_REQUEST_PROMISE(); + send_closure(G()->notification_manager(), &NotificationManager::process_push_notification, + std::move(request.payload_), std::move(promise)); +} + void Td::on_request(uint64 id, td_api::registerDevice &request) { CHECK_IS_USER(); if (request.device_token_ == nullptr) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index d909cabe8..747c8b2a9 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -380,6 +380,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::processDcUpdate &request); + void on_request(uint64 id, td_api::processPushNotification &request); + void on_request(uint64 id, td_api::registerDevice &request); void on_request(uint64 id, td_api::getUserPrivacySettingRules &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 71a9540c0..56a31dec0 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1359,6 +1359,8 @@ class CliClient final : public Actor { string ip_port; std::tie(dc_id, ip_port) = split(args); send_request(make_tl_object(dc_id, ip_port)); + } else if (op == "ppn") { + send_request(make_tl_object(args)); } else if (op == "rda") { send_request(make_tl_object(make_tl_object(args, true), as_user_ids(""))); diff --git a/tdutils/td/utils/format.h b/tdutils/td/utils/format.h index b83a56709..0ca1ce150 100644 --- a/tdutils/td/utils/format.h +++ b/tdutils/td/utils/format.h @@ -145,7 +145,7 @@ inline StringBuilder &operator<<(StringBuilder &builder, const Escaped &escaped) builder << static_cast(c); } else { const char *oct = "01234567"; - builder << "\\0" << oct[c >> 6] << oct[(c >> 3) & 7] << oct[c & 7]; + builder << '\\' << oct[c >> 6] << oct[(c >> 3) & 7] << oct[c & 7]; } } return builder;