diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 3910e007..819ef669 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -2411,9 +2411,38 @@ Status NotificationManager::process_push_notification_payload(string payload) { return Status::OK(); } + TRY_RESULT(msg_id, get_json_object_int_field(custom, "msg_id")); + ServerMessageId server_message_id(msg_id); + if (server_message_id != ServerMessageId() && !server_message_id.is_valid()) { + return Status::Error("Receive invalid msg_id"); + } + + TRY_RESULT(random_id, get_json_object_long_field(custom, "random_id")); + + UserId sender_user_id; + if (has_json_object_field(custom, "chat_from_id")) { + TRY_RESULT(sender_user_id_int, get_json_object_int_field(custom, "chat_from_id")); + sender_user_id = UserId(sender_user_id_int); + if (!sender_user_id.is_valid()) { + return Status::Error("Receive invalid chat_from_id"); + } + } + + TRY_RESULT(contains_mention_int, get_json_object_int_field(custom, "mention")); + bool contains_mention = contains_mention_int != 0; + + process_message_push_notification(dialog_id, sender_user_id, MessageId(server_message_id), random_id, + contains_mention, std::move(loc_key), std::move(loc_args)); + return Status::OK(); } +void NotificationManager::process_message_push_notification(DialogId dialog_id, UserId sender_user_id, + MessageId message_id, int64 random_id, + bool contains_mention, string loc_key, + vector loc_args) { +} + Result NotificationManager::get_push_receiver_id(string payload) { if (payload == "{}") { return static_cast(0); diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 95ee1157..d716f82a 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -255,6 +255,10 @@ class NotificationManager : public Actor { Status process_push_notification_payload(string payload); + void process_message_push_notification(DialogId dialog_id, UserId sender_user_id, MessageId message_id, + int64 random_id, bool contains_mention, string loc_key, + vector loc_args); + void after_get_difference_impl(); void after_get_chat_difference_impl(NotificationGroupId group_id); diff --git a/tdutils/td/utils/JsonBuilder.cpp b/tdutils/td/utils/JsonBuilder.cpp index 4e5e3d90..566a2880 100644 --- a/tdutils/td/utils/JsonBuilder.cpp +++ b/tdutils/td/utils/JsonBuilder.cpp @@ -637,6 +637,25 @@ Result get_json_object_int_field(JsonObject &object, Slice name, bool is_ return Status::Error(400, PSLICE() << "Can't find field \"" << name << "\""); } +Result get_json_object_long_field(JsonObject &object, Slice name, bool is_optional, int64 default_value) { + for (auto &field_value : object) { + if (field_value.first == name) { + if (field_value.second.type() == JsonValue::Type::String) { + return to_integer_safe(field_value.second.get_string()); + } + if (field_value.second.type() == JsonValue::Type::Number) { + return to_integer_safe(field_value.second.get_number()); + } + + return Status::Error(400, PSLICE() << "Field \"" << name << "\" must be a Number"); + } + } + if (is_optional) { + return default_value; + } + return Status::Error(400, PSLICE() << "Can't find field \"" << name << "\""); +} + Result get_json_object_double_field(JsonObject &object, Slice name, bool is_optional, double default_value) { TRY_RESULT(value, get_json_object_field(object, name, JsonValue::Type::Number, is_optional)); if (value.type() == JsonValue::Type::Null) { diff --git a/tdutils/td/utils/JsonBuilder.h b/tdutils/td/utils/JsonBuilder.h index 425a4d88..3aabe1a8 100644 --- a/tdutils/td/utils/JsonBuilder.h +++ b/tdutils/td/utils/JsonBuilder.h @@ -827,6 +827,9 @@ Result get_json_object_bool_field(JsonObject &object, Slice name, bool is_ Result get_json_object_int_field(JsonObject &object, Slice name, bool is_optional = true, int32 default_value = 0) TD_WARN_UNUSED_RESULT; +Result get_json_object_long_field(JsonObject &object, Slice name, bool is_optional = true, + int64 default_value = 0) TD_WARN_UNUSED_RESULT; + Result get_json_object_double_field(JsonObject &object, Slice name, bool is_optional = true, double default_value = 0.0) TD_WARN_UNUSED_RESULT;