Return error 406 if notification is not supported from processPushNotification.

GitOrigin-RevId: 6913bdc376e4af14848ed0f403f6807ae7a84b8f
This commit is contained in:
levlam 2019-04-01 22:51:39 +03:00
parent 606b427673
commit b548f222dc
2 changed files with 13 additions and 4 deletions

View File

@ -11776,7 +11776,8 @@ void MessagesManager::on_get_common_dialogs(UserId user_id, int32 offset_chat_id
td_->contacts_manager_->on_update_user_common_chat_count(user_id, total_count);
auto &common_dialogs = found_common_dialogs_[user_id];
if (common_dialogs.is_outdated && offset_chat_id == 0 && common_dialogs.dialog_ids.size() < static_cast<size_t>(MAX_GET_DIALOGS)) {
if (common_dialogs.is_outdated && offset_chat_id == 0 &&
common_dialogs.dialog_ids.size() < static_cast<size_t>(MAX_GET_DIALOGS)) {
// drop outdated cache if possible
common_dialogs = CommonDialogs();
}
@ -18287,7 +18288,7 @@ Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_messag
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return Status::Error("Ignore notification in unknown chat");
return Status::Error(406, "Ignore notification in unknown chat");
}
bool is_new_pinned = is_pinned && message_id.is_valid() && message_id.get() > d->max_notification_message_id.get();
@ -18308,7 +18309,7 @@ Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_messag
if (random_id != 0) {
CHECK(dialog_id.get_type() == DialogType::SecretChat);
if (get_message_id_by_random_id(d, random_id, "need_message_push_notification").is_valid()) {
return Status::Error("Ignore notification about known secret message");
return Status::Error(406, "Ignore notification about known secret message");
}
}

View File

@ -2551,6 +2551,10 @@ void NotificationManager::process_push_notification(string payload, Promise<Unit
if (receiver_id == 0 || receiver_id == G()->get_my_id()) {
auto status = process_push_notification_payload(payload);
if (status.is_error()) {
if (status.code() == 406) {
return promise.set_error(std::move(status));
}
LOG(ERROR) << "Receive error " << status << ", while parsing push payload " << payload;
return promise.set_error(Status::Error(400, status.message()));
}
@ -3120,6 +3124,9 @@ Status NotificationManager::process_message_push_notification(DialogId dialog_id
if (logevent_id != 0) {
binlog_erase(G()->td_db()->get_binlog(), logevent_id);
}
if (r_info.error().code() == 406) {
return r_info.move_as_error();
}
return Status::OK();
}
@ -3130,8 +3137,9 @@ Status NotificationManager::process_message_push_notification(DialogId dialog_id
VLOG(notifications) << "Skip notification in secret " << dialog_id;
// TODO support secret chat notifications
// main problem: there is no message_id yet
// also don't forget to delete newSecretChat notification
CHECK(logevent_id == 0);
return Status::OK();
return Status::Error(406, "Secret chat push notifications are unsupported");
}
CHECK(random_id == 0);