1
- #include " tgbot/TgTypeParser.h"
1
+ #include < tgbot/TgTypeParser.h>
2
+ #include < tgbot/TgException.h>
2
3
3
4
#include < json/value.h>
4
5
5
6
#include < cstdint>
6
7
#include < utility>
7
8
8
- #include " tgbot/types/InlineKeyboardMarkup.h"
9
-
10
9
namespace TgBot {
11
10
12
11
// T should be instance of std::shared_ptr.
@@ -3342,33 +3341,28 @@ DECLARE_PARSER_TO_JSON(InlineKeyboardButton) {
3342
3341
return ptree;
3343
3342
}
3344
3343
3344
+ template <typename T, typename CachedT>
3345
+ auto put (const InlineQueryResult::Ptr& ptr) {
3346
+ if (const auto cached = std::dynamic_pointer_cast<CachedT>(ptr)) {
3347
+ return put<typename CachedT::Ptr>(cached);
3348
+ } else if (const auto result = std::dynamic_pointer_cast<T>(ptr)) {
3349
+ return put<typename T::Ptr>(result);
3350
+ } else {
3351
+ throw TgBot::TgException (" Invalid inline query result type" , TgException::ErrorCode::Internal);
3352
+ }
3353
+ }
3354
+
3345
3355
DECLARE_PARSER_TO_JSON (InlineQueryResult) {
3346
3356
if (!object) return {};
3347
3357
JsonWrapper ptree;
3348
3358
ptree.put (" type" , object->type );
3349
3359
ptree.put (" id" , object->id );
3350
3360
ptree.put (" reply_markup" , put (object->replyMarkup ));
3351
3361
3352
- if (object->type == InlineQueryResultCachedAudio::TYPE) {
3353
- ptree.put (" data" , put<InlineQueryResultCachedAudio>(object));
3354
- } else if (object->type == InlineQueryResultCachedDocument::TYPE) {
3355
- ptree.put (" data" , put<InlineQueryResultCachedDocument>(object));
3356
- } else if (object->type == InlineQueryResultCachedGif::TYPE) {
3357
- ptree.put (" data" , put<InlineQueryResultCachedGif>(object));
3358
- } else if (object->type == InlineQueryResultCachedMpeg4Gif::TYPE) {
3359
- ptree.put (" data" , put<InlineQueryResultCachedMpeg4Gif>(object));
3360
- } else if (object->type == InlineQueryResultCachedPhoto::TYPE) {
3361
- ptree.put (" data" , put<InlineQueryResultCachedPhoto>(object));
3362
- } else if (object->type == InlineQueryResultCachedSticker::TYPE) {
3363
- ptree.put (" data" , put<InlineQueryResultCachedSticker>(object));
3364
- } else if (object->type == InlineQueryResultCachedVideo::TYPE) {
3365
- ptree.put (" data" , put<InlineQueryResultCachedVideo>(object));
3366
- } else if (object->type == InlineQueryResultCachedVoice::TYPE) {
3367
- ptree.put (" data" , put<InlineQueryResultCachedVoice>(object));
3368
- } else if (object->type == InlineQueryResultArticle::TYPE) {
3362
+ if (object->type == InlineQueryResultArticle::TYPE) {
3369
3363
ptree.put (" data" , put<InlineQueryResultArticle>(object));
3370
3364
} else if (object->type == InlineQueryResultAudio::TYPE) {
3371
- ptree.put (" data" , put<InlineQueryResultAudio>(object));
3365
+ ptree.put (" data" , put<InlineQueryResultAudio, InlineQueryResultCachedAudio >(object));
3372
3366
} else if (object->type == InlineQueryResultContact::TYPE) {
3373
3367
ptree.put (" data" , put<InlineQueryResultContact>(object));
3374
3368
} else if (object->type == InlineQueryResultGame::TYPE) {
@@ -3380,15 +3374,15 @@ DECLARE_PARSER_TO_JSON(InlineQueryResult) {
3380
3374
} else if (object->type == InlineQueryResultVenue::TYPE) {
3381
3375
ptree.put (" data" , put<InlineQueryResultVenue>(object));
3382
3376
} else if (object->type == InlineQueryResultVoice::TYPE) {
3383
- ptree.put (" data" , put<InlineQueryResultVoice>(object));
3377
+ ptree.put (" data" , put<InlineQueryResultVoice,InlineQueryResultCachedVoice >(object));
3384
3378
} else if (object->type == InlineQueryResultPhoto::TYPE) {
3385
- ptree.put (" data" , put<InlineQueryResultPhoto>(object));
3379
+ ptree.put (" data" , put<InlineQueryResultPhoto, InlineQueryResultCachedPhoto >(object));
3386
3380
} else if (object->type == InlineQueryResultGif::TYPE) {
3387
- ptree.put (" data" , put<InlineQueryResultGif>(object));
3381
+ ptree.put (" data" , put<InlineQueryResultGif, InlineQueryResultCachedGif >(object));
3388
3382
} else if (object->type == InlineQueryResultMpeg4Gif::TYPE) {
3389
- ptree.put (" data" , put<InlineQueryResultMpeg4Gif>(object));
3383
+ ptree.put (" data" , put<InlineQueryResultMpeg4Gif, InlineQueryResultCachedMpeg4Gif >(object));
3390
3384
} else if (object->type == InlineQueryResultVideo::TYPE) {
3391
- ptree.put (" data" , put<InlineQueryResultVideo>(object));
3385
+ ptree.put (" data" , put<InlineQueryResultVideo, InlineQueryResultCachedVideo >(object));
3392
3386
}
3393
3387
return ptree;
3394
3388
}
0 commit comments