aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-02-02 21:33:42 +0300
committerlevlam <levlam@telegram.org>2026-02-02 21:33:42 +0300
commitc3676da9296de7ebd1687927bfe2993450ed1558 (patch)
treee7ce06157f75921820048fd63a0b5080be89d412
parent9bd0bbcd99fde3d695948707a48d3c0239d0f8d2 (diff)
Add KeyboardButtonStyle class.
-rw-r--r--CMakeLists.txt3
-rw-r--r--SplitSource.php1
-rw-r--r--td/generate/scheme/td_api.tl15
-rw-r--r--td/telegram/KeyboardButtonStyle.cpp74
-rw-r--r--td/telegram/KeyboardButtonStyle.h46
-rw-r--r--td/telegram/KeyboardButtonStyle.hpp47
6 files changed, 186 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9aaaf0d46..1eb570ed7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -484,6 +484,7 @@ set(TDLIB_SOURCE_PART1
td/telegram/InputInvoice.cpp
td/telegram/InputMessageText.cpp
td/telegram/JsonValue.cpp
+ td/telegram/KeyboardButtonStyle.cpp
td/telegram/LanguagePackManager.cpp
td/telegram/LinkManager.cpp
td/telegram/Location.cpp
@@ -862,6 +863,7 @@ set(TDLIB_SOURCE_PART2
td/telegram/InputInvoice.h
td/telegram/InputMessageText.h
td/telegram/JsonValue.h
+ td/telegram/KeyboardButtonStyle.h
td/telegram/LabeledPricePart.h
td/telegram/LanguagePackManager.h
td/telegram/LinkManager.h
@@ -1159,6 +1161,7 @@ set(TDLIB_SOURCE_PART2
td/telegram/GroupCallMessageLimit.hpp
td/telegram/InputInvoice.hpp
td/telegram/InputMessageText.hpp
+ td/telegram/KeyboardButtonStyle.hpp
td/telegram/MediaArea.hpp
td/telegram/MediaAreaCoordinates.hpp
td/telegram/MessageEntity.hpp
diff --git a/SplitSource.php b/SplitSource.php
index 3cc9db11e..f6b9a436c 100644
--- a/SplitSource.php
+++ b/SplitSource.php
@@ -370,6 +370,7 @@ function split_file($file, $chunks, $undo) {
'inline_queries_manager[_(-](?![.]get[(][)])|InlineQueriesManager' => 'InlineQueriesManager',
'InputBusinessChatLink' => 'InputBusinessChatLink',
'InputGroupCall' => 'InputGroupCall',
+ 'KeyboardButtonStyle' => 'KeyboardButtonStyle',
'language_pack_manager[_(-]|LanguagePackManager' => 'LanguagePackManager',
'link_manager[_(-](?![.]get[(][)])|LinkManager' => 'LinkManager',
'LogeventIdWithGeneration|add_log_event|delete_log_event|get_erase_log_event_promise|parse_time|store_time' => 'logevent/LogEventHelper',
diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl
index 04dfefef2..887fc3e4f 100644
--- a/td/generate/scheme/td_api.tl
+++ b/td/generate/scheme/td_api.tl
@@ -3306,6 +3306,21 @@ chatActionBarSharePhoneNumber = ChatActionBar;
chatActionBarJoinRequest title:string is_channel:Bool request_date:int32 = ChatActionBar;
+//@class ButtonStyle @description Describes style of a button
+
+//@description The button has default style
+buttonStyleDefault = ButtonStyle;
+
+//@description The button is a primary button
+buttonStylePrimary = ButtonStyle;
+
+//@description The button has "danger" style
+buttonStyleDanger = ButtonStyle;
+
+//@description The button has "success" style
+buttonStyleSuccess = ButtonStyle;
+
+
//@class KeyboardButtonType @description Describes a keyboard button type
//@description A simple button, with text that must be sent when the button is pressed
diff --git a/td/telegram/KeyboardButtonStyle.cpp b/td/telegram/KeyboardButtonStyle.cpp
new file mode 100644
index 000000000..f27378a97
--- /dev/null
+++ b/td/telegram/KeyboardButtonStyle.cpp
@@ -0,0 +1,74 @@
+//
+// 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 {
+ 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());
+}
+
+} // namespace td
diff --git a/td/telegram/KeyboardButtonStyle.h b/td/telegram/KeyboardButtonStyle.h
new file mode 100644
index 000000000..691c50f46
--- /dev/null
+++ b/td/telegram/KeyboardButtonStyle.h
@@ -0,0 +1,46 @@
+//
+// 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)
+//
+#pragma once
+
+#include "td/telegram/CustomEmojiId.h"
+#include "td/telegram/td_api.h"
+#include "td/telegram/telegram_api.h"
+
+#include "td/utils/common.h"
+
+namespace td {
+
+class Td;
+
+class KeyboardButtonStyle {
+ enum class Type : int32 { Default, Primary, Danger, Success };
+ Type type_ = Type::Default;
+ CustomEmojiId icon_custom_emoji_id_;
+
+ public:
+ KeyboardButtonStyle() = default;
+
+ KeyboardButtonStyle(td_api::object_ptr<td_api::ButtonStyle> &&style, int64 icon_custom_emoji_id);
+
+ explicit KeyboardButtonStyle(telegram_api::object_ptr<telegram_api::keyboardButtonStyle> &&style);
+
+ td_api::object_ptr<td_api::ButtonStyle> get_button_style_object() const;
+
+ CustomEmojiId get_icon_custom_emoji_id() const {
+ return icon_custom_emoji_id_;
+ }
+
+ telegram_api::object_ptr<telegram_api::keyboardButtonStyle> get_input_keyboard_button_style() const;
+
+ template <class StorerT>
+ void store(StorerT &storer) const;
+
+ template <class ParserT>
+ void parse(ParserT &parser);
+};
+
+} // namespace td
diff --git a/td/telegram/KeyboardButtonStyle.hpp b/td/telegram/KeyboardButtonStyle.hpp
new file mode 100644
index 000000000..3c5de8f13
--- /dev/null
+++ b/td/telegram/KeyboardButtonStyle.hpp
@@ -0,0 +1,47 @@
+//
+// 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)
+//
+#pragma once
+
+#include "td/telegram/KeyboardButtonStyle.h"
+
+#include "td/utils/tl_helpers.h"
+
+namespace td {
+
+template <class StorerT>
+void KeyboardButtonStyle::store(StorerT &storer) const {
+ bool has_type = type_ != Type::Default;
+ bool has_icon_custom_emoji_id = icon_custom_emoji_id_.is_valid();
+ BEGIN_STORE_FLAGS();
+ STORE_FLAG(has_type);
+ STORE_FLAG(has_icon_custom_emoji_id);
+ END_STORE_FLAGS();
+ if (has_type) {
+ td::store(type_, storer);
+ }
+ if (has_icon_custom_emoji_id) {
+ td::store(icon_custom_emoji_id_, storer);
+ }
+}
+
+template <class ParserT>
+void KeyboardButtonStyle::parse(ParserT &parser) {
+ bool has_type;
+ bool has_icon_custom_emoji_id;
+ BEGIN_PARSE_FLAGS();
+ PARSE_FLAG(has_type);
+ PARSE_FLAG(has_icon_custom_emoji_id);
+ END_PARSE_FLAGS();
+ if (has_type) {
+ td::parse(type_, parser);
+ }
+ if (has_icon_custom_emoji_id) {
+ td::parse(icon_custom_emoji_id_, parser);
+ }
+}
+
+} // namespace td