Use error code 400 instead of small error codes.

This commit is contained in:
levlam 2021-09-24 10:59:51 +03:00
parent 2ec2e4d78f
commit d6f3d9f08a
18 changed files with 567 additions and 575 deletions

View File

@ -685,7 +685,7 @@ int64 AnimationsManager::get_saved_animations_hash(const char *source) const {
void AnimationsManager::add_saved_animation(const tl_object_ptr<td_api::InputFile> &input_file,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(7, "Method is not available for bots"));
return promise.set_error(Status::Error(400, "Method is not available for bots"));
}
if (!are_saved_animations_loaded_) {
load_saved_animations(std::move(promise));
@ -694,7 +694,7 @@ void AnimationsManager::add_saved_animation(const tl_object_ptr<td_api::InputFil
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Animation, input_file, DialogId(), false, false);
if (r_file_id.is_error()) {
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
return promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
}
add_saved_animation_impl(r_file_id.ok(), true, std::move(promise));
@ -730,7 +730,7 @@ void AnimationsManager::add_saved_animation_impl(FileId animation_id, bool add_o
auto file_view = td_->file_manager_->get_file_view(animation_id);
if (file_view.empty()) {
return promise.set_error(Status::Error(7, "Animation file not found"));
return promise.set_error(Status::Error(400, "Animation file not found"));
}
LOG(INFO) << "Add saved animation " << animation_id << " with main file " << file_view.file_id();
@ -764,20 +764,20 @@ void AnimationsManager::add_saved_animation_impl(FileId animation_id, bool add_o
auto animation = get_animation(animation_id);
if (animation == nullptr) {
return promise.set_error(Status::Error(7, "Animation not found"));
return promise.set_error(Status::Error(400, "Animation not found"));
}
if (animation->mime_type != "video/mp4") {
return promise.set_error(Status::Error(7, "Only MPEG4 animations can be saved"));
return promise.set_error(Status::Error(400, "Only MPEG4 animations can be saved"));
}
if (!file_view.has_remote_location()) {
return promise.set_error(Status::Error(7, "Can save only sent animations"));
return promise.set_error(Status::Error(400, "Can save only sent animations"));
}
if (file_view.remote_location().is_web()) {
return promise.set_error(Status::Error(7, "Can't save web animations"));
return promise.set_error(Status::Error(400, "Can't save web animations"));
}
if (!file_view.remote_location().is_document()) {
return promise.set_error(Status::Error(7, "Can't save encrypted animations"));
return promise.set_error(Status::Error(400, "Can't save encrypted animations"));
}
auto it = std::find_if(saved_animation_ids_.begin(), saved_animation_ids_.end(), is_equal);
@ -804,7 +804,7 @@ void AnimationsManager::add_saved_animation_impl(FileId animation_id, bool add_o
void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::InputFile> &input_file,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(7, "Method is not available for bots"));
return promise.set_error(Status::Error(400, "Method is not available for bots"));
}
if (!are_saved_animations_loaded_) {
load_saved_animations(std::move(promise));
@ -813,7 +813,7 @@ void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::Input
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Animation, input_file, DialogId(), false, false);
if (r_file_id.is_error()) {
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
return promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
}
FileId file_id = r_file_id.ok();
@ -823,7 +823,7 @@ void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::Input
auto animation = get_animation(file_id);
if (animation == nullptr) {
return promise.set_error(Status::Error(7, "Animation not found"));
return promise.set_error(Status::Error(400, "Animation not found"));
}
send_save_gif_query(file_id, true, std::move(promise));

View File

@ -158,7 +158,7 @@ void AuthManager::check_bot_token(uint64 query_id, string bot_token) {
query_id, Status::Error(400, "Cannot set bot token after authentication began. You need to log out first"));
}
if (was_check_bot_token_ && bot_token_ != bot_token) {
return on_query_error(query_id, Status::Error(8, "Cannot change bot token. You need to log out first"));
return on_query_error(query_id, Status::Error(400, "Cannot change bot token. You need to log out first"));
}
on_new_query(query_id);
@ -175,13 +175,13 @@ void AuthManager::request_qr_code_authentication(uint64 query_id, vector<UserId>
net_query_id_ == 0) {
// ok
} else {
return on_query_error(query_id, Status::Error(8, "Call to requestQrCodeAuthentication unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to requestQrCodeAuthentication unexpected"));
}
}
if (was_check_bot_token_) {
return on_query_error(
query_id,
Status::Error(8,
Status::Error(400,
"Cannot request QR code authentication after bot token was entered. You need to log out first"));
}
for (auto &other_user_id : other_user_ids) {
@ -237,15 +237,15 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number,
net_query_id_ == 0) {
// ok
} else {
return on_query_error(query_id, Status::Error(8, "Call to setAuthenticationPhoneNumber unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to setAuthenticationPhoneNumber unexpected"));
}
}
if (was_check_bot_token_) {
return on_query_error(
query_id, Status::Error(8, "Cannot set phone number after bot token was entered. You need to log out first"));
query_id, Status::Error(400, "Cannot set phone number after bot token was entered. You need to log out first"));
}
if (phone_number.empty()) {
return on_query_error(query_id, Status::Error(8, "Phone number can't be empty"));
return on_query_error(query_id, Status::Error(400, "Phone number can't be empty"));
}
other_user_ids_.clear();
@ -264,7 +264,7 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number,
void AuthManager::resend_authentication_code(uint64 query_id) {
if (state_ != State::WaitCode) {
return on_query_error(query_id, Status::Error(8, "Call to resendAuthenticationCode unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to resendAuthenticationCode unexpected"));
}
auto r_resend_code = send_code_helper_.resend_code();
@ -279,7 +279,7 @@ void AuthManager::resend_authentication_code(uint64 query_id) {
void AuthManager::check_code(uint64 query_id, string code) {
if (state_ != State::WaitCode) {
return on_query_error(query_id, Status::Error(8, "Call to checkAuthenticationCode unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to checkAuthenticationCode unexpected"));
}
code_ = std::move(code);
@ -291,13 +291,13 @@ void AuthManager::check_code(uint64 query_id, string code) {
void AuthManager::register_user(uint64 query_id, string first_name, string last_name) {
if (state_ != State::WaitRegistration) {
return on_query_error(query_id, Status::Error(8, "Call to registerUser unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to registerUser unexpected"));
}
on_new_query(query_id);
first_name = clean_name(first_name, MAX_NAME_LENGTH);
if (first_name.empty()) {
return on_query_error(Status::Error(8, "First name can't be empty"));
return on_query_error(Status::Error(400, "First name can't be empty"));
}
last_name = clean_name(last_name, MAX_NAME_LENGTH);
@ -308,7 +308,7 @@ void AuthManager::register_user(uint64 query_id, string first_name, string last_
void AuthManager::check_password(uint64 query_id, string password) {
if (state_ != State::WaitPassword) {
return on_query_error(query_id, Status::Error(8, "Call to checkAuthenticationPassword unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to checkAuthenticationPassword unexpected"));
}
LOG(INFO) << "Have SRP ID " << wait_password_state_.srp_id_;
@ -323,7 +323,7 @@ void AuthManager::check_password(uint64 query_id, string password) {
void AuthManager::request_password_recovery(uint64 query_id) {
if (state_ != State::WaitPassword) {
return on_query_error(query_id, Status::Error(8, "Call to requestAuthenticationPasswordRecovery unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to requestAuthenticationPasswordRecovery unexpected"));
}
on_new_query(query_id);
@ -333,7 +333,7 @@ void AuthManager::request_password_recovery(uint64 query_id) {
void AuthManager::check_password_recovery_code(uint64 query_id, string code) {
if (state_ != State::WaitPassword) {
return on_query_error(query_id, Status::Error(8, "Call to checkAuthenticationPasswordRecoveryCode unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to checkAuthenticationPasswordRecoveryCode unexpected"));
}
on_new_query(query_id);
@ -343,7 +343,7 @@ void AuthManager::check_password_recovery_code(uint64 query_id, string code) {
void AuthManager::recover_password(uint64 query_id, string code, string new_password, string new_hint) {
if (state_ != State::WaitPassword) {
return on_query_error(query_id, Status::Error(8, "Call to recoverAuthenticationPassword unexpected"));
return on_query_error(query_id, Status::Error(400, "Call to recoverAuthenticationPassword unexpected"));
}
on_new_query(query_id);
@ -362,10 +362,10 @@ void AuthManager::recover_password(uint64 query_id, string code, string new_pass
void AuthManager::log_out(uint64 query_id) {
if (state_ == State::Closing) {
return on_query_error(query_id, Status::Error(8, "Already logged out"));
return on_query_error(query_id, Status::Error(400, "Already logged out"));
}
if (state_ == State::LoggingOut || state_ == State::DestroyingKeys) {
return on_query_error(query_id, Status::Error(8, "Already logging out"));
return on_query_error(query_id, Status::Error(400, "Already logging out"));
}
on_new_query(query_id);
if (state_ != State::Ok) {
@ -390,7 +390,7 @@ void AuthManager::send_log_out_query() {
void AuthManager::delete_account(uint64 query_id, const string &reason) {
if (state_ != State::Ok && state_ != State::WaitPassword) {
return on_query_error(query_id, Status::Error(8, "Need to log in first"));
return on_query_error(query_id, Status::Error(400, "Need to log in first"));
}
on_new_query(query_id);
LOG(INFO) << "Deleting account";
@ -408,7 +408,7 @@ void AuthManager::on_closing(bool destroy_flag) {
void AuthManager::on_new_query(uint64 query_id) {
if (query_id_ != 0) {
on_query_error(Status::Error(9, "Another authorization query has started"));
on_query_error(Status::Error(400, "Another authorization query has started"));
}
net_query_id_ = 0;
net_query_type_ = NetQueryType::None;

View File

@ -230,32 +230,32 @@ int64 CallbackQueriesManager::send_callback_query(FullMessageId full_message_id,
tl_object_ptr<td_api::CallbackQueryPayload> &&payload,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
promise.set_error(Status::Error(5, "Bot can't send callback queries to other bot"));
promise.set_error(Status::Error(400, "Bot can't send callback queries to other bot"));
return 0;
}
if (payload == nullptr) {
promise.set_error(Status::Error(5, "Payload must be non-empty"));
promise.set_error(Status::Error(400, "Payload must be non-empty"));
return 0;
}
auto dialog_id = full_message_id.get_dialog_id();
td_->messages_manager_->have_dialog_force(dialog_id, "send_callback_query");
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
promise.set_error(Status::Error(5, "Can't access the chat"));
promise.set_error(Status::Error(400, "Can't access the chat"));
return 0;
}
if (!td_->messages_manager_->have_message_force(full_message_id, "send_callback_query")) {
promise.set_error(Status::Error(5, "Message not found"));
promise.set_error(Status::Error(400, "Message not found"));
return 0;
}
if (full_message_id.get_message_id().is_valid_scheduled()) {
promise.set_error(Status::Error(5, "Can't send callback queries from scheduled messages"));
promise.set_error(Status::Error(400, "Can't send callback queries from scheduled messages"));
return 0;
}
if (!full_message_id.get_message_id().is_server()) {
promise.set_error(Status::Error(5, "Bad message identifier"));
promise.set_error(Status::Error(400, "Bad message identifier"));
return 0;
}
@ -296,7 +296,7 @@ void CallbackQueriesManager::send_get_callback_answer_query(
return promise.set_error(Status::Error(400, "Can't access the chat"));
}
if (!td_->messages_manager_->have_message_force(full_message_id, "send_callback_query")) {
return promise.set_error(Status::Error(5, "Message not found"));
return promise.set_error(Status::Error(400, "Message not found"));
}
td_->create_handler<GetBotCallbackAnswerQuery>(std::move(promise))

View File

@ -872,7 +872,7 @@ class DeleteProfilePhotoQuery final : public Td::ResultHandler {
LOG(INFO) << "Receive result for DeleteProfilePhotoQuery: " << format::as_array(result);
if (result.size() != 1u) {
LOG(WARNING) << "Photo can't be deleted";
return on_error(id, Status::Error(7, "Photo can't be deleted"));
return on_error(id, Status::Error(400, "Photo can't be deleted"));
}
td->contacts_manager_->on_delete_profile_photo(profile_photo_id_, std::move(promise_));
@ -2877,7 +2877,7 @@ class GetChannelParticipantQuery final : public Td::ResultHandler {
void send(ChannelId channel_id, DialogId participant_dialog_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer) {
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(3, "Supergroup not found"));
return promise_.set_error(Status::Error(400, "Supergroup not found"));
}
CHECK(input_peer != nullptr);
@ -2930,7 +2930,7 @@ class GetChannelParticipantsQuery final : public Td::ResultHandler {
void send(ChannelId channel_id, ChannelParticipantsFilter filter, int32 offset, int32 limit) {
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(3, "Supergroup not found"));
return promise_.set_error(Status::Error(400, "Supergroup not found"));
}
channel_id_ = channel_id;
@ -2976,7 +2976,7 @@ class GetChannelAdministratorsQuery final : public Td::ResultHandler {
void send(ChannelId channel_id, int64 hash) {
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(3, "Supergroup not found"));
return promise_.set_error(Status::Error(400, "Supergroup not found"));
}
hash = 0; // to load even only ranks or creator changed
@ -5066,23 +5066,23 @@ UserId ContactsManager::add_anonymous_bot_user() {
void ContactsManager::check_dialog_username(DialogId dialog_id, const string &username,
Promise<CheckDialogUsernameResult> &&promise) {
if (dialog_id != DialogId() && !dialog_id.is_valid()) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User: {
if (dialog_id.get_user_id() != get_my_id()) {
return promise.set_error(Status::Error(3, "Can't check username for private chat with other user"));
return promise.set_error(Status::Error(400, "Can't check username for private chat with other user"));
}
break;
}
case DialogType::Channel: {
auto c = get_channel(dialog_id.get_channel_id());
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (!get_channel_status(c).is_creator()) {
return promise.set_error(Status::Error(6, "Not enough rights to change username"));
return promise.set_error(Status::Error(400, "Not enough rights to change username"));
}
if (username == c->username) {
@ -5097,7 +5097,7 @@ void ContactsManager::check_dialog_username(DialogId dialog_id, const string &us
if (username.empty()) {
return promise.set_value(CheckDialogUsernameResult::Ok);
}
return promise.set_error(Status::Error(3, "Chat can't have username"));
return promise.set_error(Status::Error(400, "Chat can't have username"));
default:
UNREACHABLE();
return;
@ -5347,7 +5347,7 @@ void ContactsManager::add_contact(td_api::object_ptr<td_api::contact> &&contact,
UserId user_id{contact->user_id_};
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
td_->create_handler<AddContactQuery>(std::move(promise))
@ -5771,7 +5771,7 @@ void ContactsManager::share_phone_number(UserId user_id, Promise<Unit> &&promise
LOG(INFO) << "Share phone number with " << user_id;
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
td_->messages_manager_->hide_dialog_action_bar(DialogId(user_id));
@ -6232,7 +6232,7 @@ void ContactsManager::set_name(const string &first_name, const string &last_name
auto new_first_name = clean_name(first_name, MAX_NAME_LENGTH);
auto new_last_name = clean_name(last_name, MAX_NAME_LENGTH);
if (new_first_name.empty()) {
return promise.set_error(Status::Error(7, "First name must be non-empty"));
return promise.set_error(Status::Error(400, "First name must be non-empty"));
}
const User *u = get_user(get_my_id());
@ -6311,10 +6311,10 @@ void ContactsManager::set_chat_description(ChatId chat_id, const string &descrip
auto new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH);
auto c = get_chat(chat_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (!get_chat_permissions(c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(6, "Not enough rights to set chat description"));
return promise.set_error(Status::Error(400, "Not enough rights to set chat description"));
}
td_->create_handler<EditChatAboutQuery>(std::move(promise))->send(DialogId(chat_id), new_description);
@ -6323,10 +6323,10 @@ void ContactsManager::set_chat_description(ChatId chat_id, const string &descrip
void ContactsManager::set_channel_username(ChannelId channel_id, const string &username, Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Supergroup not found"));
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (!get_channel_status(c).is_creator()) {
return promise.set_error(Status::Error(6, "Not enough rights to change supergroup username"));
return promise.set_error(Status::Error(400, "Not enough rights to change supergroup username"));
}
if (!username.empty() && !is_valid_username(username)) {
@ -6336,7 +6336,7 @@ void ContactsManager::set_channel_username(ChannelId channel_id, const string &u
if (!username.empty() && c->username.empty()) {
auto channel_full = get_channel_full(channel_id, false, "set_channel_username");
if (channel_full != nullptr && !channel_full->can_set_username) {
return promise.set_error(Status::Error(3, "Can't set supergroup username"));
return promise.set_error(Status::Error(400, "Can't set supergroup username"));
}
}
@ -6347,13 +6347,13 @@ void ContactsManager::set_channel_sticker_set(ChannelId channel_id, StickerSetId
Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Supergroup not found"));
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (!c->is_megagroup) {
return promise.set_error(Status::Error(6, "Chat sticker set can be set only for supergroups"));
return promise.set_error(Status::Error(400, "Chat sticker set can be set only for supergroups"));
}
if (!get_channel_permissions(c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(6, "Not enough rights to change supergroup sticker set"));
return promise.set_error(Status::Error(400, "Not enough rights to change supergroup sticker set"));
}
telegram_api::object_ptr<telegram_api::InputStickerSet> input_sticker_set;
@ -6362,13 +6362,13 @@ void ContactsManager::set_channel_sticker_set(ChannelId channel_id, StickerSetId
} else {
input_sticker_set = td_->stickers_manager_->get_input_sticker_set(sticker_set_id);
if (input_sticker_set == nullptr) {
return promise.set_error(Status::Error(3, "Sticker set not found"));
return promise.set_error(Status::Error(400, "Sticker set not found"));
}
}
auto channel_full = get_channel_full(channel_id, false, "set_channel_sticker_set");
if (channel_full != nullptr && !channel_full->can_set_sticker_set) {
return promise.set_error(Status::Error(3, "Can't set supergroup sticker set"));
return promise.set_error(Status::Error(400, "Can't set supergroup sticker set"));
}
td_->create_handler<SetChannelStickerSetQuery>(std::move(promise))
@ -6378,13 +6378,13 @@ void ContactsManager::set_channel_sticker_set(ChannelId channel_id, StickerSetId
void ContactsManager::toggle_channel_sign_messages(ChannelId channel_id, bool sign_messages, Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Supergroup not found"));
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (get_channel_type(c) == ChannelType::Megagroup) {
return promise.set_error(Status::Error(6, "Message signatures can't be toggled in supergroups"));
return promise.set_error(Status::Error(400, "Message signatures can't be toggled in supergroups"));
}
if (!get_channel_permissions(c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(6, "Not enough rights to toggle channel sign messages"));
return promise.set_error(Status::Error(400, "Not enough rights to toggle channel sign messages"));
}
td_->create_handler<ToggleChannelSignaturesQuery>(std::move(promise))->send(channel_id, sign_messages);
@ -6394,16 +6394,16 @@ void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_
Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Supergroup not found"));
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (!get_channel_permissions(c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(6, "Not enough rights to toggle all supergroup history availability"));
return promise.set_error(Status::Error(400, "Not enough rights to toggle all supergroup history availability"));
}
if (get_channel_type(c) != ChannelType::Megagroup) {
return promise.set_error(Status::Error(6, "Message history can be hidden in supergroups only"));
return promise.set_error(Status::Error(400, "Message history can be hidden in supergroups only"));
}
if (c->has_linked_channel && !is_all_history_available) {
return promise.set_error(Status::Error(6, "Message history can't be hidden in discussion supergroups"));
return promise.set_error(Status::Error(400, "Message history can't be hidden in discussion supergroups"));
}
// it can be toggled in public chats, but will not affect them
@ -6413,13 +6413,13 @@ void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_
void ContactsManager::convert_channel_to_gigagroup(ChannelId channel_id, Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Supergroup not found"));
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (!get_channel_permissions(c).is_creator()) {
return promise.set_error(Status::Error(6, "Not enough rights to convert group to broadcast group"));
return promise.set_error(Status::Error(400, "Not enough rights to convert group to broadcast group"));
}
if (get_channel_type(c) != ChannelType::Megagroup) {
return promise.set_error(Status::Error(6, "Chat must be a supergroup"));
return promise.set_error(Status::Error(400, "Chat must be a supergroup"));
}
remove_dialog_suggested_action(SuggestedAction{SuggestedAction::Type::ConvertToGigagroup, DialogId(channel_id)});
@ -6432,10 +6432,10 @@ void ContactsManager::set_channel_description(ChannelId channel_id, const string
auto new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH);
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (!get_channel_permissions(c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(6, "Not enough rights to set chat description"));
return promise.set_error(Status::Error(400, "Not enough rights to set chat description"));
}
td_->create_handler<EditChatAboutQuery>(std::move(promise))->send(DialogId(channel_id), new_description);
@ -6735,31 +6735,31 @@ void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id,
Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Supergroup not found"));
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (!c->is_megagroup) {
return promise.set_error(Status::Error(6, "Spam can be reported only in supergroups"));
return promise.set_error(Status::Error(400, "Spam can be reported only in supergroups"));
}
if (!have_input_user(user_id)) {
return promise.set_error(Status::Error(6, "Have no access to the user"));
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
if (user_id == get_my_id()) {
return promise.set_error(Status::Error(6, "Can't report self"));
return promise.set_error(Status::Error(400, "Can't report self"));
}
if (message_ids.empty()) {
return promise.set_error(Status::Error(6, "Message list is empty"));
return promise.set_error(Status::Error(400, "Message list is empty"));
}
vector<MessageId> server_message_ids;
for (auto &message_id : message_ids) {
if (message_id.is_valid_scheduled()) {
return promise.set_error(Status::Error(6, "Can't report scheduled messages"));
return promise.set_error(Status::Error(400, "Can't report scheduled messages"));
}
if (!message_id.is_valid()) {
return promise.set_error(Status::Error(6, "Message not found"));
return promise.set_error(Status::Error(400, "Message not found"));
}
if (message_id.is_server()) {
@ -6802,7 +6802,7 @@ void ContactsManager::delete_channel(ChannelId channel_id, Promise<Unit> &&promi
void ContactsManager::delete_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "delete_dialog")) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
@ -6825,26 +6825,26 @@ void ContactsManager::add_chat_participant(ChatId chat_id, UserId user_id, int32
Promise<Unit> &&promise) {
const Chat *c = get_chat(chat_id);
if (c == nullptr) {
return promise.set_error(Status::Error(3, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (!c->is_active) {
return promise.set_error(Status::Error(3, "Chat is deactivated"));
return promise.set_error(Status::Error(400, "Chat is deactivated"));
}
if (forward_limit < 0) {
return promise.set_error(Status::Error(3, "Can't forward negative number of messages"));
return promise.set_error(Status::Error(400, "Can't forward negative number of messages"));
}
if (user_id != get_my_id()) {
if (!get_chat_permissions(c).can_invite_users()) {
return promise.set_error(Status::Error(3, "Not enough rights to invite members to the group chat"));
return promise.set_error(Status::Error(400, "Not enough rights to invite members to the group chat"));
}
} else if (c->status.is_banned()) {
return promise.set_error(Status::Error(3, "User was kicked from the chat"));
return promise.set_error(Status::Error(400, "User was kicked from the chat"));
}
// TODO upper bound on forward_limit
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
// TODO invoke after
@ -6859,17 +6859,17 @@ void ContactsManager::add_channel_participant(ChannelId channel_id, UserId user_
const Channel *c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(3, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
if (user_id == get_my_id()) {
// join the channel
if (get_channel_status(c).is_banned()) {
return promise.set_error(Status::Error(3, "Can't return to kicked from chat"));
return promise.set_error(Status::Error(400, "Can't return to kicked from chat"));
}
speculative_add_channel_user(channel_id, user_id, DialogParticipantStatus::Member(), c->status);
@ -6878,7 +6878,7 @@ void ContactsManager::add_channel_participant(ChannelId channel_id, UserId user_
}
if (!get_channel_permissions(c).can_invite_users()) {
return promise.set_error(Status::Error(3, "Not enough rights to invite members to the supergroup chat"));
return promise.set_error(Status::Error(400, "Not enough rights to invite members to the supergroup chat"));
}
speculative_add_channel_user(channel_id, user_id, DialogParticipantStatus::Member(), old_status);
@ -6895,18 +6895,18 @@ void ContactsManager::add_channel_participants(ChannelId channel_id, const vecto
const Channel *c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(3, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (!get_channel_permissions(c).can_invite_users()) {
return promise.set_error(Status::Error(3, "Not enough rights to invite members to the supergroup chat"));
return promise.set_error(Status::Error(400, "Not enough rights to invite members to the supergroup chat"));
}
vector<tl_object_ptr<telegram_api::InputUser>> input_users;
for (auto user_id : user_ids) {
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
if (user_id == get_my_id()) {
@ -6927,12 +6927,12 @@ void ContactsManager::set_channel_participant_status(ChannelId channel_id, Dialo
DialogParticipantStatus status, Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
auto input_peer = td_->messages_manager_->get_input_peer(participant_dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(6, "Member not found"));
return promise.set_error(Status::Error(400, "Member not found"));
}
if (participant_dialog_id == DialogId(get_my_id())) {
@ -6971,13 +6971,13 @@ void ContactsManager::set_channel_participant_status_impl(ChannelId channel_id,
bool need_restrict = false;
if (status.is_creator() || old_status.is_creator()) {
if (!old_status.is_creator()) {
return promise.set_error(Status::Error(3, "Can't add another owner to the chat"));
return promise.set_error(Status::Error(400, "Can't add another owner to the chat"));
}
if (!status.is_creator()) {
return promise.set_error(Status::Error(3, "Can't remove chat owner"));
return promise.set_error(Status::Error(400, "Can't remove chat owner"));
}
if (participant_dialog_id != DialogId(get_my_id())) {
return promise.set_error(Status::Error(3, "Not enough rights to edit chat owner rights"));
return promise.set_error(Status::Error(400, "Not enough rights to edit chat owner rights"));
}
if (status.is_member() == old_status.is_member()) {
// change rank and is_anonymous
@ -7049,13 +7049,13 @@ void ContactsManager::promote_channel_participant(ChannelId channel_id, UserId u
if (user_id == get_my_id()) {
if (status.is_administrator()) {
return promise.set_error(Status::Error(3, "Can't promote self"));
return promise.set_error(Status::Error(400, "Can't promote self"));
}
CHECK(status.is_member());
// allow to demote self. TODO is it allowed server-side?
} else {
if (!get_channel_permissions(c).can_promote_members()) {
return promise.set_error(Status::Error(3, "Not enough rights"));
return promise.set_error(Status::Error(400, "Not enough rights"));
}
CHECK(!old_status.is_creator());
@ -7064,7 +7064,7 @@ void ContactsManager::promote_channel_participant(ChannelId channel_id, UserId u
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
speculative_add_channel_user(channel_id, user_id, status, old_status);
@ -7113,11 +7113,11 @@ void ContactsManager::set_chat_participant_status(ChatId chat_id, UserId user_id
}
if (!get_chat_permissions(c).can_promote_members()) {
return promise.set_error(Status::Error(3, "Need owner rights in the group chat"));
return promise.set_error(Status::Error(400, "Need owner rights in the group chat"));
}
if (user_id == get_my_id()) {
return promise.set_error(Status::Error(3, "Can't promote or demote self"));
return promise.set_error(Status::Error(400, "Can't promote or demote self"));
}
if (participant == nullptr) {
@ -7142,7 +7142,7 @@ void ContactsManager::send_edit_chat_admin_query(ChatId chat_id, UserId user_id,
Promise<Unit> &&promise) {
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
td_->create_handler<EditChatAdminQuery>(std::move(promise))->send(chat_id, std::move(input_user), is_administrator);
@ -7203,16 +7203,16 @@ td_api::object_ptr<td_api::CanTransferOwnershipResult> ContactsManager::get_can_
void ContactsManager::transfer_dialog_ownership(DialogId dialog_id, UserId user_id, const string &password,
Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "transfer_dialog_ownership")) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (!have_user_force(user_id)) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
if (is_user_bot(user_id)) {
return promise.set_error(Status::Error(3, "User is a bot"));
return promise.set_error(Status::Error(400, "User is a bot"));
}
if (is_user_deleted(user_id)) {
return promise.set_error(Status::Error(3, "User is deleted"));
return promise.set_error(Status::Error(400, "User is deleted"));
}
if (password.empty()) {
return promise.set_error(Status::Error(400, "PASSWORD_HASH_INVALID"));
@ -7222,7 +7222,7 @@ void ContactsManager::transfer_dialog_ownership(DialogId dialog_id, UserId user_
case DialogType::User:
case DialogType::Chat:
case DialogType::SecretChat:
return promise.set_error(Status::Error(3, "Can't transfer chat ownership"));
return promise.set_error(Status::Error(400, "Can't transfer chat ownership"));
case DialogType::Channel:
send_closure(
td_->password_manager_, &PasswordManager::get_input_check_password_srp, password,
@ -7255,39 +7255,39 @@ void ContactsManager::transfer_channel_ownership(
Status ContactsManager::can_manage_dialog_invite_links(DialogId dialog_id, bool creator_only) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "can_manage_dialog_invite_links")) {
return Status::Error(3, "Chat not found");
return Status::Error(400, "Chat not found");
}
switch (dialog_id.get_type()) {
case DialogType::User:
return Status::Error(3, "Can't invite members to a private chat");
return Status::Error(400, "Can't invite members to a private chat");
case DialogType::Chat: {
const Chat *c = get_chat(dialog_id.get_chat_id());
if (c == nullptr) {
return Status::Error(3, "Chat info not found");
return Status::Error(400, "Chat info not found");
}
if (!c->is_active) {
return Status::Error(3, "Chat is deactivated");
return Status::Error(400, "Chat is deactivated");
}
bool have_rights = creator_only ? c->status.is_creator() : c->status.can_manage_invite_links();
if (!have_rights) {
return Status::Error(3, "Not enough rights to manage chat invite link");
return Status::Error(400, "Not enough rights to manage chat invite link");
}
break;
}
case DialogType::Channel: {
const Channel *c = get_channel(dialog_id.get_channel_id());
if (c == nullptr) {
return Status::Error(3, "Chat info not found");
return Status::Error(400, "Chat info not found");
}
bool have_rights = creator_only ? c->status.is_creator() : c->status.can_manage_invite_links();
if (!have_rights) {
return Status::Error(3, "Not enough rights to manage chat invite link");
return Status::Error(400, "Not enough rights to manage chat invite link");
}
break;
}
case DialogType::SecretChat:
return Status::Error(3, "Can't invite members to a secret chat");
return Status::Error(400, "Can't invite members to a secret chat");
case DialogType::None:
default:
UNREACHABLE();
@ -7451,10 +7451,10 @@ void ContactsManager::delete_chat_participant(ChatId chat_id, UserId user_id, bo
Promise<Unit> &&promise) {
const Chat *c = get_chat(chat_id);
if (c == nullptr) {
return promise.set_error(Status::Error(3, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (!c->is_active) {
return promise.set_error(Status::Error(3, "Chat is deactivated"));
return promise.set_error(Status::Error(400, "Chat is deactivated"));
}
auto my_id = get_my_id();
if (c->status.is_left()) {
@ -7464,7 +7464,7 @@ void ContactsManager::delete_chat_participant(ChatId chat_id, UserId user_id, bo
}
return promise.set_value(Unit());
} else {
return promise.set_error(Status::Error(3, "Not in the chat"));
return promise.set_error(Status::Error(400, "Not in the chat"));
}
}
if (user_id != my_id) {
@ -7477,17 +7477,17 @@ void ContactsManager::delete_chat_participant(ChatId chat_id, UserId user_id, bo
if (c->everyone_is_administrator) {
// if all are administrators, only invited by me participants can be deleted
if (participant->inviter_user_id != my_id) {
return promise.set_error(Status::Error(3, "Need to be inviter of a user to kick it from a basic group"));
return promise.set_error(Status::Error(400, "Need to be inviter of a user to kick it from a basic group"));
}
} else {
// otherwise, only creator can kick administrators
if (participant->status.is_administrator()) {
return promise.set_error(
Status::Error(3, "Only the creator of a basic group can kick group administrators"));
Status::Error(400, "Only the creator of a basic group can kick group administrators"));
}
// regular users can be kicked by administrators and their inviters
if (!my_status.is_administrator() && participant->inviter_user_id != my_id) {
return promise.set_error(Status::Error(3, "Need to be inviter of a user to kick it from a basic group"));
return promise.set_error(Status::Error(400, "Need to be inviter of a user to kick it from a basic group"));
}
}
*/
@ -7496,7 +7496,7 @@ void ContactsManager::delete_chat_participant(ChatId chat_id, UserId user_id, bo
}
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
// TODO invoke after
@ -7510,29 +7510,29 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
<< status;
const Channel *c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(3, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (!c->status.is_member() && !c->status.is_creator()) {
if (participant_dialog_id == DialogId(get_my_id())) {
if (status.is_member()) {
return promise.set_error(Status::Error(3, "Can't unrestrict self"));
return promise.set_error(Status::Error(400, "Can't unrestrict self"));
}
return promise.set_value(Unit());
} else {
return promise.set_error(Status::Error(3, "Not in the chat"));
return promise.set_error(Status::Error(400, "Not in the chat"));
}
}
auto input_peer = td_->messages_manager_->get_input_peer(participant_dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(3, "Member not found"));
return promise.set_error(Status::Error(400, "Member not found"));
}
if (participant_dialog_id == DialogId(get_my_id())) {
if (status.is_restricted() || status.is_banned()) {
return promise.set_error(Status::Error(3, "Can't restrict self"));
return promise.set_error(Status::Error(400, "Can't restrict self"));
}
if (status.is_member()) {
return promise.set_error(Status::Error(3, "Can't unrestrict self"));
return promise.set_error(Status::Error(400, "Can't unrestrict self"));
}
// leave the channel
@ -7558,7 +7558,7 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
CHECK(!status.is_creator());
if (!get_channel_permissions(c).can_restrict_members()) {
return promise.set_error(Status::Error(3, "Not enough rights to restrict/unrestrict chat member"));
return promise.set_error(Status::Error(400, "Not enough rights to restrict/unrestrict chat member"));
}
if (old_status.is_member() && !status.is_member() && !status.is_banned()) {
@ -7596,12 +7596,12 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
ChannelId ContactsManager::migrate_chat_to_megagroup(ChatId chat_id, Promise<Unit> &promise) {
auto c = get_chat(chat_id);
if (c == nullptr) {
promise.set_error(Status::Error(3, "Chat info not found"));
promise.set_error(Status::Error(400, "Chat info not found"));
return ChannelId();
}
if (!c->status.is_creator()) {
promise.set_error(Status::Error(3, "Need creator rights in the chat"));
promise.set_error(Status::Error(400, "Need creator rights in the chat"));
return ChannelId();
}
@ -13619,18 +13619,18 @@ bool ContactsManager::is_user_bot(UserId user_id) const {
Result<ContactsManager::BotData> ContactsManager::get_bot_data(UserId user_id) const {
auto p = users_.find(user_id);
if (p == users_.end()) {
return Status::Error(5, "Bot not found");
return Status::Error(400, "Bot not found");
}
auto bot = p->second.get();
if (!bot->is_bot) {
return Status::Error(5, "User is not a bot");
return Status::Error(400, "User is not a bot");
}
if (bot->is_deleted) {
return Status::Error(5, "Bot is deleted");
return Status::Error(400, "Bot is deleted");
}
if (!bot->is_received) {
return Status::Error(5, "Bot is inaccessible");
return Status::Error(400, "Bot is inaccessible");
}
BotData bot_data;
@ -13726,7 +13726,7 @@ UserId ContactsManager::get_me(Promise<Unit> &&promise) {
bool ContactsManager::get_user(UserId user_id, int left_tries, Promise<Unit> &&promise) {
if (!user_id.is_valid()) {
promise.set_error(Status::Error(6, "Invalid user identifier"));
promise.set_error(Status::Error(400, "Invalid user identifier"));
return false;
}
@ -13745,7 +13745,7 @@ bool ContactsManager::get_user(UserId user_id, int left_tries, Promise<Unit> &&p
}
auto input_user = get_input_user(user_id);
if (left_tries == 1 || input_user == nullptr) {
promise.set_error(Status::Error(6, "User not found"));
promise.set_error(Status::Error(400, "User not found"));
return false;
}
@ -13797,13 +13797,13 @@ ContactsManager::UserFull *ContactsManager::add_user_full(UserId user_id) {
void ContactsManager::reload_user(UserId user_id, Promise<Unit> &&promise) {
if (!user_id.is_valid()) {
return promise.set_error(Status::Error(6, "Invalid user identifier"));
return promise.set_error(Status::Error(400, "Invalid user identifier"));
}
have_user_force(user_id);
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(6, "User info not found"));
return promise.set_error(Status::Error(400, "User info not found"));
}
// there is no much reason to combine different requests into one request
@ -13815,14 +13815,14 @@ void ContactsManager::reload_user(UserId user_id, Promise<Unit> &&promise) {
void ContactsManager::load_user_full(UserId user_id, bool force, Promise<Unit> &&promise, const char *source) {
auto u = get_user(user_id);
if (u == nullptr) {
return promise.set_error(Status::Error(6, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
auto user_full = get_user_full_force(user_id);
if (user_full == nullptr) {
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(6, "Can't get info about inaccessible user"));
return promise.set_error(Status::Error(400, "Can't get info about inaccessible user"));
}
return send_get_user_full_query(user_id, std::move(input_user), std::move(promise), source);
@ -13865,11 +13865,11 @@ std::pair<int32, vector<const Photo *>> ContactsManager::get_user_profile_photos
result.first = -1;
if (offset < 0) {
promise.set_error(Status::Error(3, "Parameter offset must be non-negative"));
promise.set_error(Status::Error(400, "Parameter offset must be non-negative"));
return result;
}
if (limit <= 0) {
promise.set_error(Status::Error(3, "Parameter limit must be positive"));
promise.set_error(Status::Error(400, "Parameter limit must be positive"));
return result;
}
if (limit > MAX_GET_PROFILE_PHOTOS) {
@ -13878,7 +13878,7 @@ std::pair<int32, vector<const Photo *>> ContactsManager::get_user_profile_photos
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
promise.set_error(Status::Error(6, "User not found"));
promise.set_error(Status::Error(400, "User not found"));
return result;
}
@ -13936,7 +13936,7 @@ void ContactsManager::reload_user_profile_photo(UserId user_id, int64 photo_id,
get_user_force(user_id);
auto input_user = get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(6, "User info not found"));
return promise.set_error(Status::Error(400, "User info not found"));
}
// this request will be needed only to download the photo,
@ -14023,7 +14023,7 @@ ContactsManager::Chat *ContactsManager::add_chat(ChatId chat_id) {
bool ContactsManager::get_chat(ChatId chat_id, int left_tries, Promise<Unit> &&promise) {
if (!chat_id.is_valid()) {
promise.set_error(Status::Error(6, "Invalid basic group identifier"));
promise.set_error(Status::Error(400, "Invalid basic group identifier"));
return false;
}
@ -14039,7 +14039,7 @@ bool ContactsManager::get_chat(ChatId chat_id, int left_tries, Promise<Unit> &&p
return false;
}
promise.set_error(Status::Error(6, "Group not found"));
promise.set_error(Status::Error(400, "Group not found"));
return false;
}
@ -14049,7 +14049,7 @@ bool ContactsManager::get_chat(ChatId chat_id, int left_tries, Promise<Unit> &&p
void ContactsManager::reload_chat(ChatId chat_id, Promise<Unit> &&promise) {
if (!chat_id.is_valid()) {
return promise.set_error(Status::Error(6, "Invalid basic group identifier"));
return promise.set_error(Status::Error(400, "Invalid basic group identifier"));
}
// there is no much reason to combine different requests into one request
@ -14108,7 +14108,7 @@ bool ContactsManager::is_chat_full_outdated(const ChatFull *chat_full, const Cha
void ContactsManager::load_chat_full(ChatId chat_id, bool force, Promise<Unit> &&promise, const char *source) {
auto c = get_chat(chat_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Group not found"));
return promise.set_error(Status::Error(400, "Group not found"));
}
auto chat_full = get_chat_full_force(chat_id, source);
@ -14358,7 +14358,7 @@ ContactsManager::Channel *ContactsManager::add_channel(ChannelId channel_id, con
bool ContactsManager::get_channel(ChannelId channel_id, int left_tries, Promise<Unit> &&promise) {
if (!channel_id.is_valid()) {
promise.set_error(Status::Error(6, "Invalid supergroup identifier"));
promise.set_error(Status::Error(400, "Invalid supergroup identifier"));
return false;
}
@ -14374,7 +14374,7 @@ bool ContactsManager::get_channel(ChannelId channel_id, int left_tries, Promise<
return false;
}
promise.set_error(Status::Error(6, "Supergroup not found"));
promise.set_error(Status::Error(400, "Supergroup not found"));
return false;
}
@ -14384,7 +14384,7 @@ bool ContactsManager::get_channel(ChannelId channel_id, int left_tries, Promise<
void ContactsManager::reload_channel(ChannelId channel_id, Promise<Unit> &&promise) {
if (!channel_id.is_valid()) {
return promise.set_error(Status::Error(6, "Invalid supergroup identifier"));
return promise.set_error(Status::Error(400, "Invalid supergroup identifier"));
}
have_channel_force(channel_id);
@ -14520,7 +14520,7 @@ ContactsManager::SecretChat *ContactsManager::get_secret_chat(SecretChatId secre
bool ContactsManager::get_secret_chat(SecretChatId secret_chat_id, bool force, Promise<Unit> &&promise) {
if (!secret_chat_id.is_valid()) {
promise.set_error(Status::Error(6, "Invalid secret chat identifier"));
promise.set_error(Status::Error(400, "Invalid secret chat identifier"));
return false;
}
@ -14531,7 +14531,7 @@ bool ContactsManager::get_secret_chat(SecretChatId secret_chat_id, bool force, P
return false;
}
promise.set_error(Status::Error(6, "Secret chat not found"));
promise.set_error(Status::Error(400, "Secret chat not found"));
return false;
}
@ -14657,19 +14657,19 @@ Result<DialogId> ContactsManager::get_participant_dialog_id(
void ContactsManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "add_dialog_participant")) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
return promise.set_error(Status::Error(3, "Can't add members to a private chat"));
return promise.set_error(Status::Error(400, "Can't add members to a private chat"));
case DialogType::Chat:
return add_chat_participant(dialog_id.get_chat_id(), user_id, forward_limit, std::move(promise));
case DialogType::Channel:
return add_channel_participant(dialog_id.get_channel_id(), user_id, std::move(promise),
DialogParticipantStatus::Left());
case DialogType::SecretChat:
return promise.set_error(Status::Error(3, "Can't add members to a secret chat"));
return promise.set_error(Status::Error(400, "Can't add members to a secret chat"));
case DialogType::None:
default:
UNREACHABLE();
@ -14679,22 +14679,22 @@ void ContactsManager::add_dialog_participant(DialogId dialog_id, UserId user_id,
void ContactsManager::add_dialog_participants(DialogId dialog_id, const vector<UserId> &user_ids,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(3, "Method is not available for bots"));
return promise.set_error(Status::Error(400, "Method is not available for bots"));
}
if (!td_->messages_manager_->have_dialog_force(dialog_id, "add_dialog_participants")) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
return promise.set_error(Status::Error(3, "Can't add members to a private chat"));
return promise.set_error(Status::Error(400, "Can't add members to a private chat"));
case DialogType::Chat:
return promise.set_error(Status::Error(3, "Can't add many members at once to a basic group chat"));
return promise.set_error(Status::Error(400, "Can't add many members at once to a basic group chat"));
case DialogType::Channel:
return add_channel_participants(dialog_id.get_channel_id(), user_ids, std::move(promise));
case DialogType::SecretChat:
return promise.set_error(Status::Error(3, "Can't add members to a secret chat"));
return promise.set_error(Status::Error(400, "Can't add members to a secret chat"));
case DialogType::None:
default:
UNREACHABLE();
@ -14709,18 +14709,18 @@ void ContactsManager::set_dialog_participant_status(DialogId dialog_id,
auto status = get_dialog_participant_status(chat_member_status);
if (!td_->messages_manager_->have_dialog_force(dialog_id, "set_dialog_participant_status")) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
return promise.set_error(Status::Error(3, "Chat member status can't be changed in private chats"));
return promise.set_error(Status::Error(400, "Chat member status can't be changed in private chats"));
case DialogType::Chat:
if (participant_dialog_id.get_type() != DialogType::User) {
if (status == DialogParticipantStatus::Left()) {
return promise.set_value(Unit());
} else {
return promise.set_error(Status::Error(3, "Chats can't be members of basic groups"));
return promise.set_error(Status::Error(400, "Chats can't be members of basic groups"));
}
}
return set_chat_participant_status(dialog_id.get_chat_id(), participant_dialog_id.get_user_id(), status,
@ -14729,7 +14729,7 @@ void ContactsManager::set_dialog_participant_status(DialogId dialog_id,
return set_channel_participant_status(dialog_id.get_channel_id(), participant_dialog_id, status,
std::move(promise));
case DialogType::SecretChat:
return promise.set_error(Status::Error(3, "Chat member status can't be changed in secret chats"));
return promise.set_error(Status::Error(400, "Chat member status can't be changed in secret chats"));
case DialogType::None:
default:
UNREACHABLE();
@ -14742,15 +14742,15 @@ void ContactsManager::ban_dialog_participant(DialogId dialog_id,
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_participant_dialog_id(participant_id));
if (!td_->messages_manager_->have_dialog_force(dialog_id, "ban_dialog_participant")) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
return promise.set_error(Status::Error(3, "Can't ban members in private chats"));
return promise.set_error(Status::Error(400, "Can't ban members in private chats"));
case DialogType::Chat:
if (participant_dialog_id.get_type() != DialogType::User) {
return promise.set_error(Status::Error(3, "Can't ban chats in basic groups"));
return promise.set_error(Status::Error(400, "Can't ban chats in basic groups"));
}
return delete_chat_participant(dialog_id.get_chat_id(), participant_dialog_id.get_user_id(), revoke_messages,
std::move(promise));
@ -14758,7 +14758,7 @@ void ContactsManager::ban_dialog_participant(DialogId dialog_id,
return set_channel_participant_status(dialog_id.get_channel_id(), participant_dialog_id,
DialogParticipantStatus::Banned(banned_until_date), std::move(promise));
case DialogType::SecretChat:
return promise.set_error(Status::Error(3, "Can't ban members in secret chats"));
return promise.set_error(Status::Error(400, "Can't ban members in secret chats"));
case DialogType::None:
default:
UNREACHABLE();
@ -14799,7 +14799,7 @@ void ContactsManager::get_dialog_participant(DialogId dialog_id, DialogId partic
Promise<DialogParticipant> &&promise) {
LOG(INFO) << "Receive GetChatMember request to get " << participant_dialog_id << " in " << dialog_id;
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_participant")) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
@ -14813,7 +14813,7 @@ void ContactsManager::get_dialog_participant(DialogId dialog_id, DialogId partic
DialogParticipant{participant_dialog_id, get_my_id(), 0, DialogParticipantStatus::Member()});
}
return promise.set_error(Status::Error(3, "Member not found"));
return promise.set_error(Status::Error(400, "Member not found"));
case DialogType::Chat:
if (participant_dialog_id.get_type() != DialogType::User) {
return promise.set_value(DialogParticipant::left(participant_dialog_id));
@ -14833,7 +14833,7 @@ void ContactsManager::get_dialog_participant(DialogId dialog_id, DialogId partic
DialogParticipant{participant_dialog_id, get_my_id(), 0, DialogParticipantStatus::Member()});
}
return promise.set_error(Status::Error(3, "Member not found"));
return promise.set_error(Status::Error(400, "Member not found"));
}
case DialogType::None:
default:
@ -14891,10 +14891,10 @@ void ContactsManager::search_dialog_participants(DialogId dialog_id, const strin
LOG(INFO) << "Receive searchChatMembers request to search for \"" << query << "\" in " << dialog_id << " with filter "
<< filter;
if (!td_->messages_manager_->have_dialog_force(dialog_id, "search_dialog_participants")) {
return promise.set_error(Status::Error(3, "Chat not found"));
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (limit < 0) {
return promise.set_error(Status::Error(3, "Parameter limit must be non-negative"));
return promise.set_error(Status::Error(400, "Parameter limit must be non-negative"));
}
switch (dialog_id.get_type()) {
@ -14971,7 +14971,7 @@ void ContactsManager::get_chat_participant(ChatId chat_id, UserId user_id, Promi
auto c = get_chat(chat_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Group not found"));
return promise.set_error(Status::Error(400, "Group not found"));
}
auto chat_full = get_chat_full_force(chat_id, "get_chat_participant");
@ -15009,7 +15009,7 @@ void ContactsManager::finish_get_chat_participant(ChatId chat_id, UserId user_id
void ContactsManager::search_chat_participants(ChatId chat_id, const string &query, int32 limit,
DialogParticipantsFilter filter, Promise<DialogParticipants> &&promise) {
if (limit < 0) {
return promise.set_error(Status::Error(3, "Parameter limit must be non-negative"));
return promise.set_error(Status::Error(400, "Parameter limit must be non-negative"));
}
auto load_chat_full_promise = PromiseCreator::lambda([actor_id = actor_id(this), chat_id, query, limit, filter,
@ -15079,7 +15079,7 @@ void ContactsManager::get_channel_participant(ChannelId channel_id, DialogId par
auto input_peer = td_->messages_manager_->get_input_peer(participant_dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(6, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
if (have_channel_participant_cache(channel_id)) {
@ -15155,7 +15155,7 @@ vector<DialogAdministrator> ContactsManager::get_dialog_administrators(DialogId
Promise<Unit> &&promise) {
LOG(INFO) << "Receive GetChatAdministrators request in " << dialog_id << " with " << left_tries << " left tries";
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_administrators")) {
promise.set_error(Status::Error(3, "Chat not found"));
promise.set_error(Status::Error(400, "Chat not found"));
return {};
}

View File

@ -430,7 +430,7 @@ void DeviceTokenManager::on_result(NetQueryPtr net_query) {
}
info.promise.set_error(r_flag.move_as_error());
} else {
info.promise.set_error(Status::Error(5, "Got false as result of registerDevice server request"));
info.promise.set_error(Status::Error(400, "Got false as result of registerDevice server request"));
}
if (info.state == TokenInfo::State::Reregister) {
// keep trying to reregister the token

View File

@ -211,12 +211,12 @@ void GameManager::set_game_score(FullMessageId full_message_id, bool edit_messag
CHECK(td_->auth_manager_->is_bot());
if (!td_->messages_manager_->have_message_force(full_message_id, "set_game_score")) {
return promise.set_error(Status::Error(5, "Message not found"));
return promise.set_error(Status::Error(400, "Message not found"));
}
auto dialog_id = full_message_id.get_dialog_id();
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Edit)) {
return promise.set_error(Status::Error(5, "Can't access the chat"));
return promise.set_error(Status::Error(400, "Can't access the chat"));
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
@ -225,7 +225,7 @@ void GameManager::set_game_score(FullMessageId full_message_id, bool edit_messag
}
if (!td_->messages_manager_->can_set_game_score(full_message_id)) {
return promise.set_error(Status::Error(5, "Game score can't be set"));
return promise.set_error(Status::Error(400, "Game score can't be set"));
}
auto query_promise = PromiseCreator::lambda(
@ -268,16 +268,16 @@ void GameManager::get_game_high_scores(FullMessageId full_message_id, UserId use
CHECK(td_->auth_manager_->is_bot());
if (!td_->messages_manager_->have_message_force(full_message_id, "get_game_high_scores")) {
return promise.set_error(Status::Error(5, "Message not found"));
return promise.set_error(Status::Error(400, "Message not found"));
}
auto dialog_id = full_message_id.get_dialog_id();
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(5, "Can't access the chat"));
return promise.set_error(Status::Error(400, "Can't access the chat"));
}
auto message_id = full_message_id.get_message_id();
if (message_id.is_scheduled() || !message_id.is_server()) {
return promise.set_error(Status::Error(5, "Wrong message identifier specified"));
return promise.set_error(Status::Error(400, "Wrong message identifier specified"));
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);

View File

@ -780,7 +780,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
uint64 InlineQueriesManager::send_inline_query(UserId bot_user_id, DialogId dialog_id, Location user_location,
const string &query, const string &offset, Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
promise.set_error(Status::Error(5, "Bot can't send inline queries to other bot"));
promise.set_error(Status::Error(400, "Bot can't send inline queries to other bot"));
return 0;
}
@ -790,7 +790,7 @@ uint64 InlineQueriesManager::send_inline_query(UserId bot_user_id, DialogId dial
return 0;
}
if (!r_bot_data.ok().is_inline) {
promise.set_error(Status::Error(5, "Bot doesn't support inline queries"));
promise.set_error(Status::Error(400, "Bot doesn't support inline queries"));
return 0;
}

View File

@ -1995,7 +1995,7 @@ Result<InputMessageContent> get_input_message_content(
FileId file_id;
if (have_file) {
if (r_file_id.is_error()) {
return Status::Error(7, r_file_id.error().message());
return Status::Error(400, r_file_id.error().message());
}
file_id = r_file_id.ok();
CHECK(file_id.is_valid());

View File

@ -3267,7 +3267,7 @@ Result<vector<MessageEntity>> get_message_entities(const ContactsManager *contac
auto entity_mention_name = static_cast<td_api::textEntityTypeMentionName *>(entity->type_.get());
UserId user_id(entity_mention_name->user_id_);
if (contacts_manager != nullptr && !contacts_manager->have_input_user(user_id)) {
return Status::Error(7, "Have no access to the user");
return Status::Error(400, "Have no access to the user");
}
entities.emplace_back(entity->offset_, entity->length_, user_id);
break;
@ -3972,7 +3972,7 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
entities.clear();
return Status::OK();
}
return Status::Error(3, "Message must be non-empty");
return Status::Error(400, "Message must be non-empty");
}
// re-fix entities if needed after removal of some characters
@ -4023,7 +4023,7 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
LOG_CHECK(check_utf8(text)) << text;
if (!allow_empty && is_empty_string(text)) {
return Status::Error(3, "Message must be non-empty");
return Status::Error(400, "Message must be non-empty");
}
constexpr size_t LENGTH_LIMIT = 35000; // server side limit

File diff suppressed because it is too large Load Diff

View File

@ -582,7 +582,7 @@ void PasswordManager::update_password_settings(UpdateSettings update_settings, P
return promise.set_error(r_update_settings.move_as_error());
}
if (!r_update_settings.ok()) {
return promise.set_error(Status::Error(5, "account_updatePasswordSettings returned false"));
return promise.set_error(Status::Error(400, "account_updatePasswordSettings returned false"));
}
send_closure(actor_id, &PasswordManager::get_state, std::move(promise));
});

View File

@ -45,7 +45,7 @@ void PhoneNumberManager::process_send_code_result(uint64 query_id, const T &send
void PhoneNumberManager::set_phone_number(uint64 query_id, string phone_number, Settings settings) {
if (phone_number.empty()) {
return on_query_error(query_id, Status::Error(8, "Phone number can't be empty"));
return on_query_error(query_id, Status::Error(400, "Phone number can't be empty"));
}
switch (type_) {
@ -64,10 +64,10 @@ void PhoneNumberManager::set_phone_number(uint64 query_id, string phone_number,
void PhoneNumberManager::set_phone_number_and_hash(uint64 query_id, string hash, string phone_number,
Settings settings) {
if (phone_number.empty()) {
return on_query_error(query_id, Status::Error(8, "Phone number can't be empty"));
return on_query_error(query_id, Status::Error(400, "Phone number can't be empty"));
}
if (hash.empty()) {
return on_query_error(query_id, Status::Error(8, "Hash can't be empty"));
return on_query_error(query_id, Status::Error(400, "Hash can't be empty"));
}
switch (type_) {
@ -83,7 +83,7 @@ void PhoneNumberManager::set_phone_number_and_hash(uint64 query_id, string hash,
void PhoneNumberManager::resend_authentication_code(uint64 query_id) {
if (state_ != State::WaitCode) {
return on_query_error(query_id, Status::Error(8, "resendAuthenticationCode unexpected"));
return on_query_error(query_id, Status::Error(400, "resendAuthenticationCode unexpected"));
}
auto r_resend_code = send_code_helper_.resend_code();
@ -103,7 +103,7 @@ void PhoneNumberManager::send_new_check_code_query(const T &query) {
void PhoneNumberManager::check_code(uint64 query_id, string code) {
if (state_ != State::WaitCode) {
return on_query_error(query_id, Status::Error(8, "checkAuthenticationCode unexpected"));
return on_query_error(query_id, Status::Error(400, "checkAuthenticationCode unexpected"));
}
on_new_query(query_id);
@ -125,7 +125,7 @@ void PhoneNumberManager::check_code(uint64 query_id, string code) {
void PhoneNumberManager::on_new_query(uint64 query_id) {
if (query_id_ != 0) {
on_query_error(Status::Error(9, "Another authorization query has started"));
on_query_error(Status::Error(400, "Another authorization query has started"));
}
net_query_id_ = 0;
net_query_type_ = NetQueryType::None;

View File

@ -30,7 +30,7 @@ namespace td {
Result<PrivacyManager::UserPrivacySetting> PrivacyManager::UserPrivacySetting::get_user_privacy_setting(
tl_object_ptr<td_api::UserPrivacySetting> key) {
if (!key) {
return Status::Error(5, "UserPrivacySetting must be non-empty");
return Status::Error(400, "UserPrivacySetting must be non-empty");
}
return UserPrivacySetting(*key);
}
@ -379,12 +379,12 @@ Result<PrivacyManager::UserPrivacySettingRules> PrivacyManager::UserPrivacySetti
Result<PrivacyManager::UserPrivacySettingRules> PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules(
tl_object_ptr<td_api::userPrivacySettingRules> rules) {
if (!rules) {
return Status::Error(5, "UserPrivacySettingRules must be non-empty");
return Status::Error(400, "UserPrivacySettingRules must be non-empty");
}
UserPrivacySettingRules result;
for (auto &rule : rules->rules_) {
if (!rule) {
return Status::Error(5, "UserPrivacySettingRule must be non-empty");
return Status::Error(400, "UserPrivacySettingRule must be non-empty");
}
result.rules_.emplace_back(*rule);
}
@ -463,7 +463,7 @@ void PrivacyManager::set_privacy(tl_object_ptr<td_api::UserPrivacySetting> key,
auto &info = get_info(user_privacy_setting);
if (info.has_set_query) {
// TODO cancel previous query
return promise.set_error(Status::Error(5, "Another set_privacy query is active"));
return promise.set_error(Status::Error(400, "Another set_privacy query is active"));
}
auto net_query = G()->net_query_creator().create(telegram_api::account_setPrivacy(
user_privacy_setting.get_input_privacy_key(), privacy_rules.get_input_privacy_rules()));

View File

@ -28,7 +28,7 @@ td_api::object_ptr<td_api::authenticationCodeInfo> SendCodeHelper::get_authentic
Result<telegram_api::auth_resendCode> SendCodeHelper::resend_code() {
if (next_code_info_.type == AuthenticationCodeInfo::Type::None) {
return Status::Error(8, "Authentication code can't be resend");
return Status::Error(400, "Authentication code can't be resend");
}
sent_code_info_ = next_code_info_;
next_code_info_ = {};

View File

@ -39,7 +39,7 @@ class GetSponsoredMessagesQuery final : public Td::ResultHandler {
channel_id_ = channel_id;
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(3, "Chat info not found"));
return promise_.set_error(Status::Error(400, "Chat info not found"));
}
send_query(G()->net_query_creator().create(telegram_api::channels_getSponsoredMessages(std::move(input_channel))));
}
@ -71,7 +71,7 @@ class ViewSponsoredMessageQuery final : public Td::ResultHandler {
channel_id_ = channel_id;
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
if (input_channel == nullptr) {
return promise_.set_error(Status::Error(3, "Chat info not found"));
return promise_.set_error(Status::Error(400, "Chat info not found"));
}
send_query(G()->net_query_creator().create(
telegram_api::channels_viewSponsoredMessage(std::move(input_channel), BufferSlice(message_id))));

View File

@ -2975,12 +2975,8 @@ void StickersManager::on_get_installed_sticker_sets_failed(bool is_masks, Status
}
vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool force, Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
promise.set_error(Status::Error(7, "Method is not available for bots"));
return {};
}
if (limit <= 0) {
promise.set_error(Status::Error(3, "Parameter limit must be positive"));
promise.set_error(Status::Error(400, "Parameter limit must be positive"));
return {};
}
if (!are_installed_sticker_sets_loaded_[0]) {
@ -3176,19 +3172,15 @@ vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool for
}
vector<FileId> StickersManager::search_stickers(string emoji, int32 limit, Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
promise.set_error(Status::Error(7, "Method is not available for bots"));
return {};
}
if (limit <= 0) {
promise.set_error(Status::Error(3, "Parameter limit must be positive"));
promise.set_error(Status::Error(400, "Parameter limit must be positive"));
return {};
}
if (limit > MAX_FOUND_STICKERS) {
limit = MAX_FOUND_STICKERS;
}
if (emoji.empty()) {
promise.set_error(Status::Error(3, "Emoji must be non-empty"));
promise.set_error(Status::Error(400, "Emoji must be non-empty"));
return {};
}
@ -4428,7 +4420,7 @@ std::pair<int32, vector<StickerSetId>> StickersManager::get_archived_sticker_set
int32 limit, bool force,
Promise<Unit> &&promise) {
if (limit <= 0) {
promise.set_error(Status::Error(3, "Parameter limit must be positive"));
promise.set_error(Status::Error(400, "Parameter limit must be positive"));
return {};
}
@ -4511,12 +4503,12 @@ void StickersManager::on_get_archived_sticker_sets(
std::pair<int32, vector<StickerSetId>> StickersManager::get_featured_sticker_sets(int32 offset, int32 limit,
Promise<Unit> &&promise) {
if (offset < 0) {
promise.set_error(Status::Error(3, "Parameter offset must be non-negative"));
promise.set_error(Status::Error(400, "Parameter offset must be non-negative"));
return {};
}
if (limit < 0) {
promise.set_error(Status::Error(3, "Parameter limit must be non-negative"));
promise.set_error(Status::Error(400, "Parameter limit must be non-negative"));
return {};
}
if (limit == 0) {
@ -4902,7 +4894,7 @@ void StickersManager::on_load_old_featured_sticker_sets_finished(uint32 generati
vector<StickerSetId> StickersManager::get_attached_sticker_sets(FileId file_id, Promise<Unit> &&promise) {
if (!file_id.is_valid()) {
promise.set_error(Status::Error(5, "Wrong file_id specified"));
promise.set_error(Status::Error(400, "Wrong file_id specified"));
return {};
}
@ -4919,7 +4911,7 @@ vector<StickerSetId> StickersManager::get_attached_sticker_sets(FileId file_id,
void StickersManager::send_get_attached_stickers_query(FileId file_id, Promise<Unit> &&promise) {
auto file_view = td_->file_manager_->get_file_view(file_id);
if (file_view.empty()) {
return promise.set_error(Status::Error(5, "File not found"));
return promise.set_error(Status::Error(400, "File not found"));
}
if (!file_view.has_remote_location() ||
(!file_view.remote_location().is_document() && !file_view.remote_location().is_photo()) ||
@ -5049,7 +5041,7 @@ string &StickersManager::get_input_sticker_emojis(td_api::InputSticker *sticker)
Result<std::tuple<FileId, bool, bool, bool>> StickersManager::prepare_input_sticker(td_api::InputSticker *sticker) {
if (sticker == nullptr) {
return Status::Error(3, "Input sticker must be non-empty");
return Status::Error(400, "Input sticker must be non-empty");
}
if (!clean_input_string(get_input_sticker_emojis(sticker))) {
@ -5072,7 +5064,7 @@ Result<std::tuple<FileId, bool, bool, bool>> StickersManager::prepare_input_file
auto r_file_id = td_->file_manager_->get_input_file_id(is_animated ? FileType::Sticker : FileType::Document,
input_file, DialogId(), for_thumbnail, false);
if (r_file_id.is_error()) {
return Status::Error(7, r_file_id.error().message());
return Status::Error(400, r_file_id.error().message());
}
auto file_id = r_file_id.move_as_ok();
if (file_id.empty()) {
@ -5128,13 +5120,13 @@ FileId StickersManager::upload_sticker_file(UserId user_id, tl_object_ptr<td_api
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
promise.set_error(Status::Error(3, "User not found"));
promise.set_error(Status::Error(400, "User not found"));
return FileId();
}
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
promise.set_error(Status::Error(3, "Have no access to the user"));
promise.set_error(Status::Error(400, "Have no access to the user"));
return FileId();
}
@ -5201,7 +5193,7 @@ tl_object_ptr<telegram_api::inputStickerSetItem> StickersManager::get_input_stic
void StickersManager::get_suggested_sticker_set_name(string title, Promise<string> &&promise) {
title = strip_empty_characters(title, MAX_STICKER_SET_TITLE_LENGTH);
if (title.empty()) {
return promise.set_error(Status::Error(3, "Sticker set title can't be empty"));
return promise.set_error(Status::Error(400, "Sticker set title can't be empty"));
}
td_->create_handler<SuggestStickerSetShortNameQuery>(std::move(promise))->send(title);
@ -5254,22 +5246,22 @@ void StickersManager::create_new_sticker_set(UserId user_id, string &title, stri
}
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(3, "Have no access to the user"));
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
title = strip_empty_characters(title, MAX_STICKER_SET_TITLE_LENGTH);
if (title.empty()) {
return promise.set_error(Status::Error(3, "Sticker set title can't be empty"));
return promise.set_error(Status::Error(400, "Sticker set title can't be empty"));
}
short_name = strip_empty_characters(short_name, MAX_STICKER_SET_SHORT_NAME_LENGTH);
if (short_name.empty()) {
return promise.set_error(Status::Error(3, "Sticker set name can't be empty"));
return promise.set_error(Status::Error(400, "Sticker set name can't be empty"));
}
if (stickers.empty()) {
@ -5402,7 +5394,7 @@ void StickersManager::do_upload_sticker_file(UserId user_id, FileId file_id,
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(3, "Have no access to the user"));
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
FileView file_view = td_->file_manager_->get_file_view(file_id);
@ -5477,7 +5469,7 @@ void StickersManager::on_new_stickers_uploaded(int64 random_id, Result<Unit> res
auto input_user = td_->contacts_manager_->get_input_user(pending_new_sticker_set->user_id);
if (input_user == nullptr) {
return pending_new_sticker_set->promise.set_error(Status::Error(3, "User not found"));
return pending_new_sticker_set->promise.set_error(Status::Error(400, "User not found"));
}
bool is_masks = pending_new_sticker_set->is_masks;
@ -5500,17 +5492,17 @@ void StickersManager::add_sticker_to_set(UserId user_id, string &short_name,
tl_object_ptr<td_api::InputSticker> &&sticker, Promise<Unit> &&promise) {
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(3, "Have no access to the user"));
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
short_name = strip_empty_characters(short_name, MAX_STICKER_SET_SHORT_NAME_LENGTH);
if (short_name.empty()) {
return promise.set_error(Status::Error(3, "Sticker set name can't be empty"));
return promise.set_error(Status::Error(400, "Sticker set name can't be empty"));
}
auto r_file_id = prepare_input_sticker(sticker.get());
@ -5569,17 +5561,17 @@ void StickersManager::set_sticker_set_thumbnail(UserId user_id, string &short_na
tl_object_ptr<td_api::InputFile> &&thumbnail, Promise<Unit> &&promise) {
auto input_user = td_->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return promise.set_error(Status::Error(3, "User not found"));
return promise.set_error(Status::Error(400, "User not found"));
}
DialogId dialog_id(user_id);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(3, "Have no access to the user"));
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
short_name = clean_username(strip_empty_characters(short_name, MAX_STICKER_SET_SHORT_NAME_LENGTH));
if (short_name.empty()) {
return promise.set_error(Status::Error(3, "Sticker set name can't be empty"));
return promise.set_error(Status::Error(400, "Sticker set name can't be empty"));
}
auto it = short_name_to_sticker_set_id_.find(short_name);
@ -5607,7 +5599,7 @@ void StickersManager::do_set_sticker_set_thumbnail(UserId user_id, string short_
auto it = short_name_to_sticker_set_id_.find(short_name);
const StickerSet *sticker_set = it == short_name_to_sticker_set_id_.end() ? nullptr : get_sticker_set(it->second);
if (sticker_set == nullptr || !sticker_set->was_loaded) {
return promise.set_error(Status::Error(3, "Sticker set not found"));
return promise.set_error(Status::Error(400, "Sticker set not found"));
}
auto r_file_id = prepare_input_file(thumbnail, sticker_set->is_animated, true);
@ -5674,19 +5666,19 @@ void StickersManager::on_sticker_set_thumbnail_uploaded(int64 random_id, Result<
void StickersManager::set_sticker_position_in_set(const tl_object_ptr<td_api::InputFile> &sticker, int32 position,
Promise<Unit> &&promise) {
if (position < 0) {
return promise.set_error(Status::Error(7, "Wrong sticker position specified"));
return promise.set_error(Status::Error(400, "Wrong sticker position specified"));
}
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, sticker, DialogId(), false, false);
if (r_file_id.is_error()) {
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
return promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
}
auto file_id = r_file_id.move_as_ok();
auto file_view = td_->file_manager_->get_file_view(file_id);
if (!file_view.has_remote_location() || !file_view.main_remote_location().is_document() ||
file_view.main_remote_location().is_web()) {
return promise.set_error(Status::Error(7, "Wrong sticker file specified"));
return promise.set_error(Status::Error(400, "Wrong sticker file specified"));
}
td_->create_handler<SetStickerPositionQuery>(std::move(promise))
@ -5697,14 +5689,14 @@ void StickersManager::remove_sticker_from_set(const tl_object_ptr<td_api::InputF
Promise<Unit> &&promise) {
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, sticker, DialogId(), false, false);
if (r_file_id.is_error()) {
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
return promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
}
auto file_id = r_file_id.move_as_ok();
auto file_view = td_->file_manager_->get_file_view(file_id);
if (!file_view.has_remote_location() || !file_view.main_remote_location().is_document() ||
file_view.main_remote_location().is_web()) {
return promise.set_error(Status::Error(7, "Wrong sticker file specified"));
return promise.set_error(Status::Error(400, "Wrong sticker file specified"));
}
td_->create_handler<DeleteStickerFromSetQuery>(std::move(promise))
@ -6011,7 +6003,7 @@ FileSourceId StickersManager::get_recent_stickers_file_source_id(int is_attached
void StickersManager::add_recent_sticker(bool is_attached, const tl_object_ptr<td_api::InputFile> &input_file,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(7, "Method is not available for bots"));
return promise.set_error(Status::Error(400, "Method is not available for bots"));
}
if (!are_recent_stickers_loaded_[is_attached]) {
load_recent_stickers(is_attached, std::move(promise));
@ -6020,7 +6012,7 @@ void StickersManager::add_recent_sticker(bool is_attached, const tl_object_ptr<t
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, input_file, DialogId(), false, false);
if (r_file_id.is_error()) {
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
return promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
}
add_recent_sticker_impl(is_attached, r_file_id.ok(), true, std::move(promise));
@ -6080,21 +6072,21 @@ void StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i
auto sticker = get_sticker(sticker_id);
if (sticker == nullptr) {
return promise.set_error(Status::Error(7, "Sticker not found"));
return promise.set_error(Status::Error(400, "Sticker not found"));
}
if (!sticker->set_id.is_valid()) {
return promise.set_error(Status::Error(7, "Stickers without sticker set can't be added to recent"));
return promise.set_error(Status::Error(400, "Stickers without sticker set can't be added to recent"));
}
auto file_view = td_->file_manager_->get_file_view(sticker_id);
if (!file_view.has_remote_location()) {
return promise.set_error(Status::Error(7, "Can save only sent stickers"));
return promise.set_error(Status::Error(400, "Can save only sent stickers"));
}
if (file_view.remote_location().is_web()) {
return promise.set_error(Status::Error(7, "Can't save web stickers"));
return promise.set_error(Status::Error(400, "Can't save web stickers"));
}
if (!file_view.remote_location().is_document()) {
return promise.set_error(Status::Error(7, "Can't save encrypted stickers"));
return promise.set_error(Status::Error(400, "Can't save encrypted stickers"));
}
need_update_recent_stickers_[is_attached] = true;
@ -6122,7 +6114,7 @@ void StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i
void StickersManager::remove_recent_sticker(bool is_attached, const tl_object_ptr<td_api::InputFile> &input_file,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(7, "Method is not available for bots"));
return promise.set_error(Status::Error(400, "Method is not available for bots"));
}
if (!are_recent_stickers_loaded_[is_attached]) {
load_recent_stickers(is_attached, std::move(promise));
@ -6131,7 +6123,7 @@ void StickersManager::remove_recent_sticker(bool is_attached, const tl_object_pt
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, input_file, DialogId(), false, false);
if (r_file_id.is_error()) {
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
return promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
}
vector<FileId> &sticker_ids = recent_sticker_ids_[is_attached];
@ -6142,7 +6134,7 @@ void StickersManager::remove_recent_sticker(bool is_attached, const tl_object_pt
auto sticker = get_sticker(file_id);
if (sticker == nullptr) {
return promise.set_error(Status::Error(7, "Sticker not found"));
return promise.set_error(Status::Error(400, "Sticker not found"));
}
send_save_recent_sticker_query(is_attached, file_id, true, std::move(promise));
@ -6153,7 +6145,7 @@ void StickersManager::remove_recent_sticker(bool is_attached, const tl_object_pt
void StickersManager::clear_recent_stickers(bool is_attached, Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(7, "Method is not available for bots"));
return promise.set_error(Status::Error(400, "Method is not available for bots"));
}
if (!are_recent_stickers_loaded_[is_attached]) {
load_recent_stickers(is_attached, std::move(promise));
@ -6416,7 +6408,7 @@ FileSourceId StickersManager::get_favorite_stickers_file_source_id() {
void StickersManager::add_favorite_sticker(const tl_object_ptr<td_api::InputFile> &input_file,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(7, "Method is not available for bots"));
return promise.set_error(Status::Error(400, "Method is not available for bots"));
}
if (!are_favorite_stickers_loaded_) {
load_favorite_stickers(std::move(promise));
@ -6425,7 +6417,7 @@ void StickersManager::add_favorite_sticker(const tl_object_ptr<td_api::InputFile
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, input_file, DialogId(), false, false);
if (r_file_id.is_error()) {
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
return promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
}
add_favorite_sticker_impl(r_file_id.ok(), true, std::move(promise));
@ -6481,21 +6473,21 @@ void StickersManager::add_favorite_sticker_impl(FileId sticker_id, bool add_on_s
auto sticker = get_sticker(sticker_id);
if (sticker == nullptr) {
return promise.set_error(Status::Error(7, "Sticker not found"));
return promise.set_error(Status::Error(400, "Sticker not found"));
}
if (!sticker->set_id.is_valid()) {
return promise.set_error(Status::Error(7, "Stickers without sticker set can't be favorite"));
return promise.set_error(Status::Error(400, "Stickers without sticker set can't be favorite"));
}
auto file_view = td_->file_manager_->get_file_view(sticker_id);
if (!file_view.has_remote_location()) {
return promise.set_error(Status::Error(7, "Can add to favorites only sent stickers"));
return promise.set_error(Status::Error(400, "Can add to favorites only sent stickers"));
}
if (file_view.remote_location().is_web()) {
return promise.set_error(Status::Error(7, "Can't add to favorites web stickers"));
return promise.set_error(Status::Error(400, "Can't add to favorites web stickers"));
}
if (!file_view.remote_location().is_document()) {
return promise.set_error(Status::Error(7, "Can't add to favorites encrypted stickers"));
return promise.set_error(Status::Error(400, "Can't add to favorites encrypted stickers"));
}
auto it = std::find_if(favorite_sticker_ids_.begin(), favorite_sticker_ids_.end(), is_equal);
@ -6521,7 +6513,7 @@ void StickersManager::add_favorite_sticker_impl(FileId sticker_id, bool add_on_s
void StickersManager::remove_favorite_sticker(const tl_object_ptr<td_api::InputFile> &input_file,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(7, "Method is not available for bots"));
return promise.set_error(Status::Error(400, "Method is not available for bots"));
}
if (!are_favorite_stickers_loaded_) {
load_favorite_stickers(std::move(promise));
@ -6530,7 +6522,7 @@ void StickersManager::remove_favorite_sticker(const tl_object_ptr<td_api::InputF
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, input_file, DialogId(), false, false);
if (r_file_id.is_error()) {
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
return promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
}
FileId file_id = r_file_id.ok();
@ -6540,7 +6532,7 @@ void StickersManager::remove_favorite_sticker(const tl_object_ptr<td_api::InputF
auto sticker = get_sticker(file_id);
if (sticker == nullptr) {
return promise.set_error(Status::Error(7, "Sticker not found"));
return promise.set_error(Status::Error(400, "Sticker not found"));
}
send_fave_sticker_query(file_id, true, std::move(promise));
@ -6586,7 +6578,7 @@ vector<string> StickersManager::get_sticker_emojis(const tl_object_ptr<td_api::I
Promise<Unit> &&promise) {
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, input_file, DialogId(), false, false);
if (r_file_id.is_error()) {
promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
promise.set_error(Status::Error(400, r_file_id.error().message())); // TODO do not drop error code
return {};
}

View File

@ -6559,7 +6559,7 @@ void Td::on_request(uint64 id, const td_api::getFileDownloadedPrefixSize &reques
}
auto file_view = file_manager_->get_file_view(FileId(request.file_id_, 0));
if (file_view.empty()) {
return send_closure(actor_id(this), &Td::send_error, id, Status::Error(10, "Unknown file ID"));
return send_closure(actor_id(this), &Td::send_error, id, Status::Error(400, "Unknown file ID"));
}
send_closure(actor_id(this), &Td::send_result, id,
td_api::make_object<td_api::count>(narrow_cast<int32>(file_view.downloaded_prefix(request.offset_))));

View File

@ -409,7 +409,7 @@ static Status create_local_lock(const string &path, int32 &max_tries) {
Status FileFd::lock(const LockFlags flags, const string &path, int32 max_tries) {
if (max_tries <= 0) {
return Status::Error(0, "Can't lock file: wrong max_tries");
return Status::Error("Can't lock file: wrong max_tries");
}
bool need_local_unlock = false;