blob: 23c01f95df0cb527f3a68fa82c0db92797412460 (
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
//
// 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/KeyboardButtonStyle.h"
namespace td {
KeyboardButtonStyle::KeyboardButtonStyle(td_api::object_ptr<td_api::ButtonStyle> &&style, int64 icon_custom_emoji_id)
: icon_custom_emoji_id_(icon_custom_emoji_id) {
if (style == nullptr) {
return;
}
switch (style->get_id()) {
case td_api::buttonStyleDefault::ID:
break;
case td_api::buttonStylePrimary::ID:
type_ = Type::Primary;
break;
case td_api::buttonStyleDanger::ID:
type_ = Type::Danger;
break;
case td_api::buttonStyleSuccess::ID:
type_ = Type::Success;
break;
default:
UNREACHABLE();
break;
}
}
KeyboardButtonStyle::KeyboardButtonStyle(telegram_api::object_ptr<telegram_api::keyboardButtonStyle> &&style) {
if (style == nullptr) {
return;
}
if (style->bg_primary_) {
type_ = Type::Primary;
} else if (style->bg_danger_) {
type_ = Type::Danger;
} else if (style->bg_success_) {
type_ = Type::Success;
}
icon_custom_emoji_id_ = CustomEmojiId(style->icon_);
}
td_api::object_ptr<td_api::ButtonStyle> KeyboardButtonStyle::get_button_style_object() const {
switch (type_) {
case Type::Default:
return td_api::make_object<td_api::buttonStyleDefault>();
case Type::Primary:
return td_api::make_object<td_api::buttonStylePrimary>();
case Type::Danger:
return td_api::make_object<td_api::buttonStyleDanger>();
case Type::Success:
return td_api::make_object<td_api::buttonStyleSuccess>();
default:
UNREACHABLE();
return nullptr;
}
}
telegram_api::object_ptr<telegram_api::keyboardButtonStyle> KeyboardButtonStyle::get_input_keyboard_button_style()
const {
if (is_default()) {
return nullptr;
}
int32 flags = 0;
if (icon_custom_emoji_id_.is_valid()) {
flags |= telegram_api::keyboardButtonStyle::ICON_MASK;
}
return telegram_api::make_object<telegram_api::keyboardButtonStyle>(
flags, type_ == Type::Primary, type_ == Type::Danger, type_ == Type::Success, icon_custom_emoji_id_.get());
}
bool operator==(const KeyboardButtonStyle &lhs, const KeyboardButtonStyle &rhs) {
return lhs.type_ == rhs.type_ && lhs.icon_custom_emoji_id_ == rhs.icon_custom_emoji_id_;
}
StringBuilder &operator<<(StringBuilder &string_builder, const KeyboardButtonStyle &style) {
if (style.is_default()) {
return string_builder;
}
string_builder << ", ";
switch (style.type_) {
case KeyboardButtonStyle::Type::Default:
string_builder << "Default";
break;
case KeyboardButtonStyle::Type::Primary:
string_builder << "Primary";
break;
case KeyboardButtonStyle::Type::Danger:
string_builder << "Danger";
break;
case KeyboardButtonStyle::Type::Success:
string_builder << "Success";
break;
default:
UNREACHABLE();
}
if (style.icon_custom_emoji_id_.is_valid()) {
string_builder << style.icon_custom_emoji_id_.get();
}
return string_builder;
}
} // namespace td
|