tg_cli: improve as_message_sender.

This commit is contained in:
levlam 2023-06-03 22:12:45 +03:00
parent 4580cfc23b
commit 9b8bb82897

View File

@ -530,8 +530,9 @@ class CliClient final : public Actor {
td_api::object_ptr<td_api::MessageSender> as_message_sender(Slice sender_id) const { td_api::object_ptr<td_api::MessageSender> as_message_sender(Slice sender_id) const {
sender_id = trim(sender_id); sender_id = trim(sender_id);
if (sender_id.empty() || sender_id[0] != '-') { auto user_id = as_user_id(sender_id, true);
return td_api::make_object<td_api::messageSenderUser>(as_user_id(sender_id)); if (sender_id.empty() || user_id > 0) {
return td_api::make_object<td_api::messageSenderUser>(user_id);
} else { } else {
return td_api::make_object<td_api::messageSenderChat>(as_chat_id(sender_id)); return td_api::make_object<td_api::messageSenderChat>(as_chat_id(sender_id));
} }
@ -573,7 +574,7 @@ class CliClient final : public Actor {
return to_integer<int32>(trim(str)); return to_integer<int32>(trim(str));
} }
int64 as_user_id(Slice str) const { int64 as_user_id(Slice str, bool expect_error = false) const {
str = trim(str); str = trim(str);
if (str == "me") { if (str == "me") {
return my_id_; return my_id_;
@ -586,7 +587,9 @@ class CliClient final : public Actor {
if (it != username_to_user_id_.end()) { if (it != username_to_user_id_.end()) {
return it->second; return it->second;
} }
if (!expect_error) {
LOG(ERROR) << "Can't find user " << str; LOG(ERROR) << "Can't find user " << str;
}
return 0; return 0;
} }
return to_integer<int64>(str); return to_integer<int64>(str);