Support SESSION_REVOKE push notification.

GitOrigin-RevId: 58ffab4a39bb36d973a064e8768d7a5e5dd56af9
This commit is contained in:
levlam 2019-04-20 22:39:41 +03:00
parent 651172ed85
commit adaf85ae70
2 changed files with 15 additions and 3 deletions

View File

@ -2632,6 +2632,7 @@ void NotificationManager::process_push_notification(string payload, Promise<Unit
<< "\" with receiver_id = " << receiver_id; << "\" with receiver_id = " << receiver_id;
auto encryption_keys = td_->device_token_manager_->get_actor_unsafe()->get_encryption_keys(); auto encryption_keys = td_->device_token_manager_->get_actor_unsafe()->get_encryption_keys();
bool was_encrypted = false;
for (auto &key : encryption_keys) { for (auto &key : encryption_keys) {
// VLOG(notifications) << "Have key " << key.first << ": \"" << format::escaped(key.second) << '"'; // VLOG(notifications) << "Have key " << key.first << ": \"" << format::escaped(key.second) << '"';
if (key.first == receiver_id) { if (key.first == receiver_id) {
@ -2642,6 +2643,7 @@ void NotificationManager::process_push_notification(string payload, Promise<Unit
return promise.set_error(Status::Error(400, "Failed to decrypt push payload")); return promise.set_error(Status::Error(400, "Failed to decrypt push payload"));
} }
payload = r_payload.move_as_ok(); payload = r_payload.move_as_ok();
was_encrypted = true;
} }
receiver_id = 0; receiver_id = 0;
break; break;
@ -2654,7 +2656,7 @@ void NotificationManager::process_push_notification(string payload, Promise<Unit
} }
if (receiver_id == 0 || receiver_id == G()->get_my_id()) { if (receiver_id == 0 || receiver_id == G()->get_my_id()) {
auto status = process_push_notification_payload(payload, promise); auto status = process_push_notification_payload(payload, was_encrypted, promise);
if (status.is_error()) { if (status.is_error()) {
if (status.code() == 406 || status.code() == 200) { if (status.code() == 406 || status.code() == 200) {
return promise.set_error(std::move(status)); return promise.set_error(std::move(status));
@ -2868,7 +2870,8 @@ string NotificationManager::convert_loc_key(const string &loc_key) {
return string(); return string();
} }
Status NotificationManager::process_push_notification_payload(string payload, Promise<Unit> &promise) { Status NotificationManager::process_push_notification_payload(string payload, bool was_encrypted,
Promise<Unit> &promise) {
VLOG(notifications) << "Process push notification payload " << payload; VLOG(notifications) << "Process push notification payload " << payload;
auto r_json_value = json_decode(payload); auto r_json_value = json_decode(payload);
if (r_json_value.is_error()) { if (r_json_value.is_error()) {
@ -2980,6 +2983,15 @@ Status NotificationManager::process_push_notification_payload(string payload, Pr
return Status::OK(); return Status::OK();
} }
if (loc_key == "SESSION_REVOKE") {
if (was_encrypted) {
send_closure(td_->auth_manager_actor_, &AuthManager::on_authorization_lost);
} else {
LOG(ERROR) << "Receive unencrypted SESSION_REVOKE push notification";
}
return Status::OK();
}
if (loc_key == "LOCKED_MESSAGE") { if (loc_key == "LOCKED_MESSAGE") {
return Status::Error(200, "Immediate success"); return Status::Error(200, "Immediate success");
} }

View File

@ -292,7 +292,7 @@ class NotificationManager : public Actor {
static string convert_loc_key(const string &loc_key); static string convert_loc_key(const string &loc_key);
Status process_push_notification_payload(string payload, Promise<Unit> &promise); Status process_push_notification_payload(string payload, bool was_encrypted, Promise<Unit> &promise);
void add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id, void add_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id, UserId sender_user_id,
string sender_name, int32 date, bool contains_mention, bool is_silent, string sender_name, int32 date, bool contains_mention, bool is_silent,