Support unencrypted pushes in getPushReceiverId.

GitOrigin-RevId: f8404aec776934ae804f7b76dd8cbbe352ace50b
This commit is contained in:
levlam 2019-01-13 22:56:38 +03:00
parent 4618d0611e
commit ca4fe0ecb3
2 changed files with 18 additions and 2 deletions

View File

@ -2074,7 +2074,6 @@ void NotificationManager::process_push_notification(string payload, Promise<Unit
}
Result<int64> NotificationManager::get_push_receiver_id(string payload) {
VLOG(notifications) << "Get push notification receiver ID of \"" << format::escaped(payload) << '"';
auto r_json_value = json_decode(payload);
if (r_json_value.is_error()) {
return Status::Error(400, "Failed to parse payload as JSON object");
@ -2097,6 +2096,21 @@ Result<int64> NotificationManager::get_push_receiver_id(string payload) {
}
return as<int64>(data.data());
}
if (field_value.first == "user_id") {
auto user_id = std::move(field_value.second);
if (user_id.type() != JsonValue::Type::String && user_id.type() != JsonValue::Type::Number) {
return Status::Error(400, "Expected user_id as a String or a Number");
}
Slice user_id_str = user_id.type() == JsonValue::Type::String ? user_id.get_string() : user_id.get_number();
auto r_user_id = to_integer_safe<int32>(user_id_str);
if (r_user_id.is_error()) {
return Status::Error(400, PSLICE() << "Failed to get user_id from " << user_id_str);
}
if (r_user_id.ok() <= 0) {
return Status::Error(400, PSLICE() << "Receive wrong user_id " << user_id_str);
}
return static_cast<int64>(r_user_id.ok());
}
}
return Status::Error(200, "Unsupported push notification");

View File

@ -7007,8 +7007,10 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getLangua
td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getPushReceiverId &request) {
// don't check push payload UTF-8 correctness
auto r_push_receiver_id = NotificationManager::get_push_receiver_id(std::move(request.payload_));
auto r_push_receiver_id = NotificationManager::get_push_receiver_id(request.payload_);
if (r_push_receiver_id.is_error()) {
VLOG(notifications) << "Failed to get push notification receiver from \"" << format::escaped(request.payload_)
<< '"';
return make_error(r_push_receiver_id.error().code(), r_push_receiver_id.error().message());
}
return td_api::make_object<td_api::pushReceiverId>(r_push_receiver_id.ok());