Pass Contact to add_contact.
This commit is contained in:
parent
5f19e0267f
commit
44efa70789
@ -36,10 +36,18 @@ UserId Contact::get_user_id() const {
|
|||||||
return user_id_;
|
return user_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Contact::get_phone_number() const {
|
const string &Contact::get_phone_number() const {
|
||||||
return phone_number_;
|
return phone_number_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const string &Contact::get_first_name() const {
|
||||||
|
return first_name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string &Contact::get_last_name() const {
|
||||||
|
return last_name_;
|
||||||
|
}
|
||||||
|
|
||||||
tl_object_ptr<td_api::contact> Contact::get_contact_object() const {
|
tl_object_ptr<td_api::contact> Contact::get_contact_object() const {
|
||||||
return make_tl_object<td_api::contact>(phone_number_, first_name_, last_name_, vcard_, user_id_.get());
|
return make_tl_object<td_api::contact>(phone_number_, first_name_, last_name_, vcard_, user_id_.get());
|
||||||
}
|
}
|
||||||
@ -82,10 +90,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const Contact &contact)
|
|||||||
<< ", vCard size = " << contact.vcard_.size() << contact.user_id_ << "]";
|
<< ", vCard size = " << contact.vcard_.size() << contact.user_id_ << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Contact> process_input_message_contact(tl_object_ptr<td_api::InputMessageContent> &&input_message_content) {
|
Result<Contact> get_contact(td_api::object_ptr<td_api::contact> &&contact) {
|
||||||
CHECK(input_message_content != nullptr);
|
|
||||||
CHECK(input_message_content->get_id() == td_api::inputMessageContact::ID);
|
|
||||||
auto contact = std::move(static_cast<td_api::inputMessageContact *>(input_message_content.get())->contact_);
|
|
||||||
if (contact == nullptr) {
|
if (contact == nullptr) {
|
||||||
return Status::Error(400, "Contact must be non-empty");
|
return Status::Error(400, "Contact must be non-empty");
|
||||||
}
|
}
|
||||||
@ -103,8 +108,14 @@ Result<Contact> process_input_message_contact(tl_object_ptr<td_api::InputMessage
|
|||||||
return Status::Error(400, "vCard must be encoded in UTF-8");
|
return Status::Error(400, "vCard must be encoded in UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Contact(contact->phone_number_, contact->first_name_, contact->last_name_, contact->vcard_,
|
return Contact(std::move(contact->phone_number_), std::move(contact->first_name_), std::move(contact->last_name_),
|
||||||
UserId(contact->user_id_));
|
std::move(contact->vcard_), UserId(contact->user_id_));
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<Contact> process_input_message_contact(tl_object_ptr<td_api::InputMessageContent> &&input_message_content) {
|
||||||
|
CHECK(input_message_content != nullptr);
|
||||||
|
CHECK(input_message_content->get_id() == td_api::inputMessageContact::ID);
|
||||||
|
return get_contact(std::move(static_cast<td_api::inputMessageContact *>(input_message_content.get())->contact_));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -46,7 +46,11 @@ class Contact {
|
|||||||
|
|
||||||
UserId get_user_id() const;
|
UserId get_user_id() const;
|
||||||
|
|
||||||
string get_phone_number() const;
|
const string &get_phone_number() const;
|
||||||
|
|
||||||
|
const string &get_first_name() const;
|
||||||
|
|
||||||
|
const string &get_last_name() const;
|
||||||
|
|
||||||
tl_object_ptr<td_api::contact> get_contact_object() const;
|
tl_object_ptr<td_api::contact> get_contact_object() const;
|
||||||
|
|
||||||
@ -139,6 +143,8 @@ struct ContactHash {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Result<Contact> get_contact(td_api::object_ptr<td_api::contact> &&contact) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
Result<Contact> process_input_message_contact(tl_object_ptr<td_api::InputMessageContent> &&input_message_content)
|
Result<Contact> process_input_message_contact(tl_object_ptr<td_api::InputMessageContent> &&input_message_content)
|
||||||
TD_WARN_UNUSED_RESULT;
|
TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
@ -444,15 +444,16 @@ class AddContactQuery final : public Td::ResultHandler {
|
|||||||
explicit AddContactQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
explicit AddContactQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(UserId user_id, tl_object_ptr<telegram_api::InputUser> &&input_user, const string &first_name,
|
void send(UserId user_id, tl_object_ptr<telegram_api::InputUser> &&input_user, const Contact &contact,
|
||||||
const string &last_name, const string &phone_number, bool share_phone_number) {
|
bool share_phone_number) {
|
||||||
user_id_ = user_id;
|
user_id_ = user_id;
|
||||||
int32 flags = 0;
|
int32 flags = 0;
|
||||||
if (share_phone_number) {
|
if (share_phone_number) {
|
||||||
flags |= telegram_api::contacts_addContact::ADD_PHONE_PRIVACY_EXCEPTION_MASK;
|
flags |= telegram_api::contacts_addContact::ADD_PHONE_PRIVACY_EXCEPTION_MASK;
|
||||||
}
|
}
|
||||||
send_query(G()->net_query_creator().create(telegram_api::contacts_addContact(
|
send_query(G()->net_query_creator().create(
|
||||||
flags, false /*ignored*/, std::move(input_user), first_name, last_name, phone_number)));
|
telegram_api::contacts_addContact(flags, false /*ignored*/, std::move(input_user), contact.get_first_name(),
|
||||||
|
contact.get_last_name(), contact.get_phone_number())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_result(uint64 id, BufferSlice packet) final {
|
void on_result(uint64 id, BufferSlice packet) final {
|
||||||
@ -5324,12 +5325,7 @@ void ContactsManager::reload_contacts(bool force) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::add_contact(td_api::object_ptr<td_api::contact> &&contact, bool share_phone_number,
|
void ContactsManager::add_contact(Contact contact, bool share_phone_number, Promise<Unit> &&promise) {
|
||||||
Promise<Unit> &&promise) {
|
|
||||||
if (contact == nullptr) {
|
|
||||||
return promise.set_error(Status::Error(400, "Added contact must be non-empty"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (G()->close_flag()) {
|
if (G()->close_flag()) {
|
||||||
return promise.set_error(Status::Error(500, "Request aborted"));
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
||||||
}
|
}
|
||||||
@ -5342,17 +5338,16 @@ void ContactsManager::add_contact(td_api::object_ptr<td_api::contact> &&contact,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Add " << oneline(to_string(contact)) << " with share_phone_number = " << share_phone_number;
|
LOG(INFO) << "Add " << contact << " with share_phone_number = " << share_phone_number;
|
||||||
|
|
||||||
UserId user_id{contact->user_id_};
|
auto user_id = contact.get_user_id();
|
||||||
auto input_user = get_input_user(user_id);
|
auto input_user = get_input_user(user_id);
|
||||||
if (input_user == nullptr) {
|
if (input_user == nullptr) {
|
||||||
return promise.set_error(Status::Error(400, "User not found"));
|
return promise.set_error(Status::Error(400, "User not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
td_->create_handler<AddContactQuery>(std::move(promise))
|
td_->create_handler<AddContactQuery>(std::move(promise))
|
||||||
->send(user_id, std::move(input_user), contact->first_name_, contact->last_name_, contact->phone_number_,
|
->send(user_id, std::move(input_user), contact, share_phone_number);
|
||||||
share_phone_number);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<vector<UserId>, vector<int32>> ContactsManager::import_contacts(
|
std::pair<vector<UserId>, vector<int32>> ContactsManager::import_contacts(
|
||||||
|
@ -288,7 +288,7 @@ class ContactsManager final : public Actor {
|
|||||||
void disconnect_website(int64 authorizations_id, Promise<Unit> &&promise) const;
|
void disconnect_website(int64 authorizations_id, Promise<Unit> &&promise) const;
|
||||||
void disconnect_all_websites(Promise<Unit> &&promise) const;
|
void disconnect_all_websites(Promise<Unit> &&promise) const;
|
||||||
|
|
||||||
void add_contact(td_api::object_ptr<td_api::contact> &&contact, bool share_phone_number, Promise<Unit> &&promise);
|
void add_contact(Contact contact, bool share_phone_number, Promise<Unit> &&promise);
|
||||||
|
|
||||||
std::pair<vector<UserId>, vector<int32>> import_contacts(const vector<tl_object_ptr<td_api::contact>> &contacts,
|
std::pair<vector<UserId>, vector<int32>> import_contacts(const vector<tl_object_ptr<td_api::contact>> &contacts,
|
||||||
int64 &random_id, Promise<Unit> &&promise);
|
int64 &random_id, Promise<Unit> &&promise);
|
||||||
|
@ -6645,14 +6645,12 @@ void Td::on_request(uint64 id, const td_api::getBlockedMessageSenders &request)
|
|||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::addContact &request) {
|
void Td::on_request(uint64 id, td_api::addContact &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
if (request.contact_ == nullptr) {
|
auto r_contact = get_contact(std::move(request.contact_));
|
||||||
return send_error_raw(id, 400, "Contact must be non-empty");
|
if (r_contact.is_error()) {
|
||||||
|
return send_closure(actor_id(this), &Td::send_error, id, r_contact.move_as_error());
|
||||||
}
|
}
|
||||||
CLEAN_INPUT_STRING(request.contact_->phone_number_);
|
|
||||||
CLEAN_INPUT_STRING(request.contact_->first_name_);
|
|
||||||
CLEAN_INPUT_STRING(request.contact_->last_name_);
|
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
contacts_manager_->add_contact(std::move(request.contact_), request.share_phone_number_, std::move(promise));
|
contacts_manager_->add_contact(r_contact.move_as_ok(), request.share_phone_number_, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::importContacts &request) {
|
void Td::on_request(uint64 id, td_api::importContacts &request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user