2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/SecretInputMedia.h"
|
2020-04-19 15:30:04 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/UserId.h"
|
2018-06-28 01:45:06 +02:00
|
|
|
#include "td/telegram/Version.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2022-11-23 17:37:32 +01:00
|
|
|
#include "td/utils/HashTableUtils.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/utils/Status.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Contact {
|
|
|
|
string phone_number_;
|
|
|
|
string first_name_;
|
|
|
|
string last_name_;
|
2018-06-25 23:10:53 +02:00
|
|
|
string vcard_;
|
2018-12-31 20:04:05 +01:00
|
|
|
UserId user_id_;
|
|
|
|
|
|
|
|
friend bool operator==(const Contact &lhs, const Contact &rhs);
|
|
|
|
friend bool operator!=(const Contact &lhs, const Contact &rhs);
|
|
|
|
|
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const Contact &contact);
|
|
|
|
|
|
|
|
friend struct ContactEqual;
|
|
|
|
friend struct ContactHash;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Contact() = default;
|
|
|
|
|
2021-03-29 07:20:54 +02:00
|
|
|
Contact(string phone_number, string first_name, string last_name, string vcard, UserId user_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void set_user_id(UserId user_id);
|
|
|
|
|
|
|
|
UserId get_user_id() const;
|
|
|
|
|
2021-09-30 12:53:16 +02:00
|
|
|
const string &get_phone_number() const;
|
|
|
|
|
|
|
|
const string &get_first_name() const;
|
|
|
|
|
|
|
|
const string &get_last_name() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
tl_object_ptr<td_api::contact> get_contact_object() const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::inputMediaContact> get_input_media_contact() const;
|
|
|
|
|
|
|
|
SecretInputMedia get_secret_input_media_contact() const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::inputPhoneContact> get_input_phone_contact(int64 client_id) const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::inputBotInlineMessageMediaContact> get_input_bot_inline_message_media_contact(
|
2021-03-31 01:54:29 +02:00
|
|
|
tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
using td::store;
|
2018-06-25 23:10:53 +02:00
|
|
|
bool has_first_name = !first_name_.empty();
|
|
|
|
bool has_last_name = !last_name_.empty();
|
|
|
|
bool has_vcard = !vcard_.empty();
|
|
|
|
bool has_user_id = user_id_.is_valid();
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_first_name);
|
|
|
|
STORE_FLAG(has_last_name);
|
|
|
|
STORE_FLAG(has_vcard);
|
|
|
|
STORE_FLAG(has_user_id);
|
|
|
|
END_STORE_FLAGS();
|
2018-12-31 20:04:05 +01:00
|
|
|
store(phone_number_, storer);
|
2018-06-25 23:10:53 +02:00
|
|
|
if (has_first_name) {
|
|
|
|
store(first_name_, storer);
|
|
|
|
}
|
|
|
|
if (has_last_name) {
|
|
|
|
store(last_name_, storer);
|
|
|
|
}
|
|
|
|
if (has_vcard) {
|
|
|
|
store(vcard_, storer);
|
|
|
|
}
|
|
|
|
if (has_user_id) {
|
|
|
|
store(user_id_, storer);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
|
|
|
using td::parse;
|
2018-06-25 23:10:53 +02:00
|
|
|
bool has_first_name = true;
|
|
|
|
bool has_last_name = true;
|
|
|
|
bool has_vcard = false;
|
|
|
|
bool has_user_id = true;
|
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddContactVcard)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_first_name);
|
|
|
|
PARSE_FLAG(has_last_name);
|
|
|
|
PARSE_FLAG(has_vcard);
|
|
|
|
PARSE_FLAG(has_user_id);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
parse(phone_number_, parser);
|
2018-06-25 23:10:53 +02:00
|
|
|
if (has_first_name) {
|
|
|
|
parse(first_name_, parser);
|
|
|
|
}
|
|
|
|
if (has_last_name) {
|
|
|
|
parse(last_name_, parser);
|
|
|
|
}
|
|
|
|
if (has_vcard) {
|
|
|
|
parse(vcard_, parser);
|
|
|
|
}
|
|
|
|
if (has_user_id) {
|
|
|
|
parse(user_id_, parser);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const Contact &lhs, const Contact &rhs);
|
|
|
|
bool operator!=(const Contact &lhs, const Contact &rhs);
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const Contact &contact);
|
|
|
|
|
|
|
|
struct ContactEqual {
|
2022-11-23 17:37:32 +01:00
|
|
|
bool operator()(const Contact &lhs, const Contact &rhs) const {
|
2018-12-31 20:04:05 +01:00
|
|
|
return std::tie(lhs.phone_number_, lhs.first_name_, lhs.last_name_) ==
|
|
|
|
std::tie(rhs.phone_number_, rhs.first_name_, rhs.last_name_);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ContactHash {
|
2022-11-23 17:37:32 +01:00
|
|
|
uint32 operator()(const Contact &contact) const {
|
|
|
|
return (Hash<string>()(contact.phone_number_) * 2023654985u + Hash<string>()(contact.first_name_)) * 2023654985u +
|
|
|
|
Hash<string>()(contact.last_name_);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-30 12:53:16 +02:00
|
|
|
Result<Contact> get_contact(td_api::object_ptr<td_api::contact> &&contact) TD_WARN_UNUSED_RESULT;
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
Result<Contact> process_input_message_contact(tl_object_ptr<td_api::InputMessageContent> &&input_message_content)
|
|
|
|
TD_WARN_UNUSED_RESULT;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|