-
Notifications
You must be signed in to change notification settings - Fork 262
Make the fields of Telegram types really optional (right now LinkPreviewOptions, ReplyParameters only) #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
uralm1
wants to merge
3
commits into
reo7sp:master
Choose a base branch
from
uralm1:optional-fields-sendmessage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #ifndef TGBOT_OPTIONAL_H | ||
| #define TGBOT_OPTIONAL_H | ||
|
|
||
| #include <boost/optional.hpp> | ||
|
|
||
| namespace TgBot { | ||
|
|
||
| template<typename T> | ||
| using Optional = boost::optional<T>; | ||
|
|
||
| // use for: OptionalPtr<std::shared/unique_ptr<TYPE>> | ||
| // for pointers, we assume optional value == nullptr (or not owned, etc) | ||
| template<typename T> | ||
| using OptionalPtr = T; | ||
|
|
||
| template<typename T> | ||
| using Required = T; | ||
|
|
||
| } | ||
|
|
||
| #endif //TGBOT_OPTIONAL_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #ifndef TGBOT_MESSAGEENTITY_H | ||
| #define TGBOT_MESSAGEENTITY_H | ||
|
|
||
| #include "tgbot/Optional.h" | ||
| #include "tgbot/types/User.h" | ||
|
|
||
| #include <cstdint> | ||
|
|
@@ -33,40 +34,40 @@ class MessageEntity { | |
| * | ||
| * Currently, can be Type::Mention (@username), Type::Hashtag (#hashtag), Type::Cashtag ($USD), Type::BotCommand (/start@jobs_bot), Type::Url (https://telegram.org), Type::Email ([email protected]), Type::PhoneNumber (+1-212-555-0123), Type::Bold (bold text), Type::Italic (italic text), Type::Underline (underlined text), Type::Strikethrough (strikethrough text), Type::Spoiler (spoiler message), Type::Blockquote (block quotation), Type::Code (monowidth string), Type::Pre (monowidth block), Type::TextLink (for clickable text URLs), Type::TextMention (for users [without usernames](https://telegram.org/blog/edit#new-mentions)), Type::CustomEmoji (for inline custom emoji stickers) | ||
| */ | ||
| Type type; | ||
| Required<Type> type; | ||
|
|
||
| /** | ||
| * @brief Offset in [UTF-16 code units](https://core.telegram.org/api/entities#entity-length) to the start of the entity | ||
| * | ||
| */ | ||
| std::int32_t offset; | ||
| Required<std::int32_t> offset; | ||
|
|
||
| /** | ||
| * @brief Length of the entity in [UTF-16 code units](https://core.telegram.org/api/entities#entity-length) | ||
| */ | ||
| std::int32_t length; | ||
| Required<std::int32_t> length; | ||
|
|
||
| /** | ||
| * @brief Optional. For Type::TextLink only, URL that will be opened after user taps on the text | ||
| */ | ||
| std::string url; | ||
| Optional<std::string> url; | ||
|
|
||
| /** | ||
| * @brief Optional. For Type::TextMention only, the mentioned user | ||
| */ | ||
| User::Ptr user; | ||
| OptionalPtr<User::Ptr> user; | ||
|
|
||
| /** | ||
| * @brief Optional. For Type::Pre only, the programming language of the entity text | ||
| */ | ||
| std::string language; | ||
| Optional<std::string> language; | ||
|
|
||
| /** | ||
| * @brief Optional. For Type::CustomEmoji only, unique identifier of the custom emoji. | ||
| * | ||
| * Use Api::getCustomEmojiStickers to get full information about the sticker | ||
| */ | ||
| std::string customEmojiId; | ||
| Optional<std::string> customEmojiId; | ||
| }; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can specialize the Optional template to create a specific implementation for certain types.