aboutsummaryrefslogtreecommitdiffhomepage
path: root/td/telegram/BotVerifierSettings.cpp
blob: 475589004fa9a891081342c7847d729128f291da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026
//
// 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)
//
#include "td/telegram/BotVerifierSettings.h"

#include "td/telegram/MessageEntity.h"
#include "td/telegram/Td.h"

#include "td/utils/logging.h"

namespace td {

BotVerifierSettings::BotVerifierSettings(
    telegram_api::object_ptr<telegram_api::botVerifierSettings> &&bot_verifier_settings) {
  if (bot_verifier_settings == nullptr) {
    return;
  }
  icon_ = CustomEmojiId(bot_verifier_settings->icon_);
  company_ = std::move(bot_verifier_settings->company_);
  description_ = std::move(bot_verifier_settings->custom_description_);
  can_modify_custom_description_ = bot_verifier_settings->can_modify_custom_description_;
}

unique_ptr<BotVerifierSettings> BotVerifierSettings::get_bot_verifier_settings(
    telegram_api::object_ptr<telegram_api::botVerifierSettings> &&bot_verifier_settings) {
  if (bot_verifier_settings == nullptr) {
    return nullptr;
  }
  auto result = td::make_unique<BotVerifierSettings>(std::move(bot_verifier_settings));
  if (!result->is_valid()) {
    LOG(ERROR) << "Receive invalid " << *result;
    return nullptr;
  }
  return result;
}

td_api::object_ptr<td_api::botVerificationParameters> BotVerifierSettings::get_bot_verification_parameters_object(
    Td *td) const {
  if (!is_valid()) {
    return nullptr;
  }
  td_api::object_ptr<td_api::formattedText> description;
  if (!description_.empty() || can_modify_custom_description_) {
    FormattedText text;
    text.text = description_;
    text.entities = find_entities(text.text, true, true);
    description = get_formatted_text_object(td->user_manager_.get(), text, true, -1);
  }
  return td_api::make_object<td_api::botVerificationParameters>(icon_.get(), company_, std::move(description),
                                                                can_modify_custom_description_);
}

bool operator==(const BotVerifierSettings &lhs, const BotVerifierSettings &rhs) {
  return lhs.icon_ == rhs.icon_ && lhs.company_ == rhs.company_ && lhs.description_ == rhs.description_ &&
         lhs.can_modify_custom_description_ == rhs.can_modify_custom_description_;
}

StringBuilder &operator<<(StringBuilder &string_builder, const BotVerifierSettings &bot_verifier_settings) {
  return string_builder << "VerificationSettings[" << bot_verifier_settings.icon_ << " by "
                        << bot_verifier_settings.company_ << ']';
}

}  // namespace td