Use std::cout instead of std::cerr in C++ example.
GitOrigin-RevId: a61c925e7f432d5df46792ff6d4ccbcb3fda5b85
This commit is contained in:
parent
3d614f6ac2
commit
90eb543819
@ -64,7 +64,7 @@ class TdExample {
|
|||||||
} else if (!are_authorized_) {
|
} else if (!are_authorized_) {
|
||||||
process_response(client_->receive(10));
|
process_response(client_->receive(10));
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Enter action [q] quit [u] check for updates and request results [c] show chats [m <id> <text>] "
|
std::cout << "Enter action [q] quit [u] check for updates and request results [c] show chats [m <id> <text>] "
|
||||||
"send message [me] show self [l] logout: "
|
"send message [me] show self [l] logout: "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::string line;
|
std::string line;
|
||||||
@ -78,7 +78,7 @@ class TdExample {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (action == "u") {
|
if (action == "u") {
|
||||||
std::cerr << "Checking for updates..." << std::endl;
|
std::cout << "Checking for updates..." << std::endl;
|
||||||
while (true) {
|
while (true) {
|
||||||
auto response = client_->receive(0);
|
auto response = client_->receive(0);
|
||||||
if (response.object) {
|
if (response.object) {
|
||||||
@ -88,13 +88,13 @@ class TdExample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (action == "close") {
|
} else if (action == "close") {
|
||||||
std::cerr << "Closing..." << std::endl;
|
std::cout << "Closing..." << std::endl;
|
||||||
send_query(td_api::make_object<td_api::close>(), {});
|
send_query(td_api::make_object<td_api::close>(), {});
|
||||||
} else if (action == "me") {
|
} else if (action == "me") {
|
||||||
send_query(td_api::make_object<td_api::getMe>(),
|
send_query(td_api::make_object<td_api::getMe>(),
|
||||||
[this](Object object) { std::cerr << to_string(object) << std::endl; });
|
[this](Object object) { std::cout << to_string(object) << std::endl; });
|
||||||
} else if (action == "l") {
|
} else if (action == "l") {
|
||||||
std::cerr << "Logging out..." << std::endl;
|
std::cout << "Logging out..." << std::endl;
|
||||||
send_query(td_api::make_object<td_api::logOut>(), {});
|
send_query(td_api::make_object<td_api::logOut>(), {});
|
||||||
} else if (action == "m") {
|
} else if (action == "m") {
|
||||||
std::int64_t chat_id;
|
std::int64_t chat_id;
|
||||||
@ -103,7 +103,7 @@ class TdExample {
|
|||||||
std::string text;
|
std::string text;
|
||||||
std::getline(ss, text);
|
std::getline(ss, text);
|
||||||
|
|
||||||
std::cerr << "Sending message to chat " << chat_id << "..." << std::endl;
|
std::cout << "Sending message to chat " << chat_id << "..." << std::endl;
|
||||||
auto send_message = td_api::make_object<td_api::sendMessage>();
|
auto send_message = td_api::make_object<td_api::sendMessage>();
|
||||||
send_message->chat_id_ = chat_id;
|
send_message->chat_id_ = chat_id;
|
||||||
auto message_content = td_api::make_object<td_api::inputMessageText>();
|
auto message_content = td_api::make_object<td_api::inputMessageText>();
|
||||||
@ -113,7 +113,7 @@ class TdExample {
|
|||||||
|
|
||||||
send_query(std::move(send_message), {});
|
send_query(std::move(send_message), {});
|
||||||
} else if (action == "c") {
|
} else if (action == "c") {
|
||||||
std::cerr << "Loading chat list..." << std::endl;
|
std::cout << "Loading chat list..." << std::endl;
|
||||||
send_query(td_api::make_object<td_api::getChats>(nullptr, std::numeric_limits<std::int64_t>::max(), 0, 20),
|
send_query(td_api::make_object<td_api::getChats>(nullptr, std::numeric_limits<std::int64_t>::max(), 0, 20),
|
||||||
[this](Object object) {
|
[this](Object object) {
|
||||||
if (object->get_id() == td_api::error::ID) {
|
if (object->get_id() == td_api::error::ID) {
|
||||||
@ -121,7 +121,7 @@ class TdExample {
|
|||||||
}
|
}
|
||||||
auto chats = td::move_tl_object_as<td_api::chats>(object);
|
auto chats = td::move_tl_object_as<td_api::chats>(object);
|
||||||
for (auto chat_id : chats->chat_ids_) {
|
for (auto chat_id : chats->chat_ids_) {
|
||||||
std::cerr << "[id:" << chat_id << "] [title:" << chat_title_[chat_id] << "]" << std::endl;
|
std::cout << "[id:" << chat_id << "] [title:" << chat_title_[chat_id] << "]" << std::endl;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ class TdExample {
|
|||||||
if (!response.object) {
|
if (!response.object) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//std::cerr << response.id << " " << to_string(response.object) << std::endl;
|
//std::cout << response.id << " " << to_string(response.object) << std::endl;
|
||||||
if (response.id == 0) {
|
if (response.id == 0) {
|
||||||
return process_update(std::move(response.object));
|
return process_update(std::move(response.object));
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ class TdExample {
|
|||||||
if (update_new_message.message_->content_->get_id() == td_api::messageText::ID) {
|
if (update_new_message.message_->content_->get_id() == td_api::messageText::ID) {
|
||||||
text = static_cast<td_api::messageText &>(*update_new_message.message_->content_).text_->text_;
|
text = static_cast<td_api::messageText &>(*update_new_message.message_->content_).text_->text_;
|
||||||
}
|
}
|
||||||
std::cerr << "Got message: [chat_id:" << chat_id << "] [from:" << sender_user_name << "] ["
|
std::cout << "Got message: [chat_id:" << chat_id << "] [from:" << sender_user_name << "] ["
|
||||||
<< text << "]" << std::endl;
|
<< text << "]" << std::endl;
|
||||||
},
|
},
|
||||||
[](auto &update) {}));
|
[](auto &update) {}));
|
||||||
@ -225,20 +225,20 @@ class TdExample {
|
|||||||
overloaded(
|
overloaded(
|
||||||
[this](td_api::authorizationStateReady &) {
|
[this](td_api::authorizationStateReady &) {
|
||||||
are_authorized_ = true;
|
are_authorized_ = true;
|
||||||
std::cerr << "Got authorization" << std::endl;
|
std::cout << "Got authorization" << std::endl;
|
||||||
},
|
},
|
||||||
[this](td_api::authorizationStateLoggingOut &) {
|
[this](td_api::authorizationStateLoggingOut &) {
|
||||||
are_authorized_ = false;
|
are_authorized_ = false;
|
||||||
std::cerr << "Logging out" << std::endl;
|
std::cout << "Logging out" << std::endl;
|
||||||
},
|
},
|
||||||
[this](td_api::authorizationStateClosing &) { std::cerr << "Closing" << std::endl; },
|
[this](td_api::authorizationStateClosing &) { std::cout << "Closing" << std::endl; },
|
||||||
[this](td_api::authorizationStateClosed &) {
|
[this](td_api::authorizationStateClosed &) {
|
||||||
are_authorized_ = false;
|
are_authorized_ = false;
|
||||||
need_restart_ = true;
|
need_restart_ = true;
|
||||||
std::cerr << "Terminated" << std::endl;
|
std::cout << "Terminated" << std::endl;
|
||||||
},
|
},
|
||||||
[this](td_api::authorizationStateWaitCode &) {
|
[this](td_api::authorizationStateWaitCode &) {
|
||||||
std::cerr << "Enter authentication code: ";
|
std::cout << "Enter authentication code: " << std::flush;
|
||||||
std::string code;
|
std::string code;
|
||||||
std::cin >> code;
|
std::cin >> code;
|
||||||
send_query(td_api::make_object<td_api::checkAuthenticationCode>(code),
|
send_query(td_api::make_object<td_api::checkAuthenticationCode>(code),
|
||||||
@ -247,29 +247,29 @@ class TdExample {
|
|||||||
[this](td_api::authorizationStateWaitRegistration &) {
|
[this](td_api::authorizationStateWaitRegistration &) {
|
||||||
std::string first_name;
|
std::string first_name;
|
||||||
std::string last_name;
|
std::string last_name;
|
||||||
std::cerr << "Enter your first name: ";
|
std::cout << "Enter your first name: " << std::flush;
|
||||||
std::cin >> first_name;
|
std::cin >> first_name;
|
||||||
std::cerr << "Enter your last name: ";
|
std::cout << "Enter your last name: " << std::flush;
|
||||||
std::cin >> last_name;
|
std::cin >> last_name;
|
||||||
send_query(td_api::make_object<td_api::registerUser>(first_name, last_name),
|
send_query(td_api::make_object<td_api::registerUser>(first_name, last_name),
|
||||||
create_authentication_query_handler());
|
create_authentication_query_handler());
|
||||||
},
|
},
|
||||||
[this](td_api::authorizationStateWaitPassword &) {
|
[this](td_api::authorizationStateWaitPassword &) {
|
||||||
std::cerr << "Enter authentication password: ";
|
std::cout << "Enter authentication password: " << std::flush;
|
||||||
std::string password;
|
std::string password;
|
||||||
std::cin >> password;
|
std::cin >> password;
|
||||||
send_query(td_api::make_object<td_api::checkAuthenticationPassword>(password),
|
send_query(td_api::make_object<td_api::checkAuthenticationPassword>(password),
|
||||||
create_authentication_query_handler());
|
create_authentication_query_handler());
|
||||||
},
|
},
|
||||||
[this](td_api::authorizationStateWaitPhoneNumber &) {
|
[this](td_api::authorizationStateWaitPhoneNumber &) {
|
||||||
std::cerr << "Enter phone number: ";
|
std::cout << "Enter phone number: " << std::flush;
|
||||||
std::string phone_number;
|
std::string phone_number;
|
||||||
std::cin >> phone_number;
|
std::cin >> phone_number;
|
||||||
send_query(td_api::make_object<td_api::setAuthenticationPhoneNumber>(phone_number, nullptr),
|
send_query(td_api::make_object<td_api::setAuthenticationPhoneNumber>(phone_number, nullptr),
|
||||||
create_authentication_query_handler());
|
create_authentication_query_handler());
|
||||||
},
|
},
|
||||||
[this](td_api::authorizationStateWaitEncryptionKey &) {
|
[this](td_api::authorizationStateWaitEncryptionKey &) {
|
||||||
std::cerr << "Enter encryption key or DESTROY: ";
|
std::cout << "Enter encryption key or DESTROY: " << std::flush;
|
||||||
std::string key;
|
std::string key;
|
||||||
std::getline(std::cin, key);
|
std::getline(std::cin, key);
|
||||||
if (key == "DESTROY") {
|
if (key == "DESTROY") {
|
||||||
@ -299,7 +299,7 @@ class TdExample {
|
|||||||
void check_authentication_error(Object object) {
|
void check_authentication_error(Object object) {
|
||||||
if (object->get_id() == td_api::error::ID) {
|
if (object->get_id() == td_api::error::ID) {
|
||||||
auto error = td::move_tl_object_as<td_api::error>(object);
|
auto error = td::move_tl_object_as<td_api::error>(object);
|
||||||
std::cerr << "Error: " << to_string(error);
|
std::cout << "Error: " << to_string(error) << std::flush;
|
||||||
on_authorization_state_update();
|
on_authorization_state_update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user