More push notification parsing.

GitOrigin-RevId: df7da02f718aab0c9158d77f73744808f7597396
This commit is contained in:
levlam 2019-03-26 03:57:38 +03:00
parent 8a5d186e34
commit 89e5b00a95
4 changed files with 55 additions and 0 deletions

View File

@ -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<string> loc_args) {
}
Result<int64> NotificationManager::get_push_receiver_id(string payload) {
if (payload == "{}") {
return static_cast<int64>(0);

View File

@ -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<string> loc_args);
void after_get_difference_impl();
void after_get_chat_difference_impl(NotificationGroupId group_id);

View File

@ -637,6 +637,25 @@ Result<int32> get_json_object_int_field(JsonObject &object, Slice name, bool is_
return Status::Error(400, PSLICE() << "Can't find field \"" << name << "\"");
}
Result<int64> 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<int64>(field_value.second.get_string());
}
if (field_value.second.type() == JsonValue::Type::Number) {
return to_integer_safe<int64>(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<double> 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) {

View File

@ -827,6 +827,9 @@ Result<bool> get_json_object_bool_field(JsonObject &object, Slice name, bool is_
Result<int32> get_json_object_int_field(JsonObject &object, Slice name, bool is_optional = true,
int32 default_value = 0) TD_WARN_UNUSED_RESULT;
Result<int64> get_json_object_long_field(JsonObject &object, Slice name, bool is_optional = true,
int64 default_value = 0) TD_WARN_UNUSED_RESULT;
Result<double> get_json_object_double_field(JsonObject &object, Slice name, bool is_optional = true,
double default_value = 0.0) TD_WARN_UNUSED_RESULT;