Skip to content

Commit bd36158

Browse files
committed
Modify the parseInlineQueryResult function. Some object->types are the same, which results in the actual type not being parsed during parsing.
1 parent 7fb7f87 commit bd36158

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

src/TgTypeParser.cpp

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3948,46 +3948,64 @@ std::string TgTypeParser::parseInlineQueryResult(const InlineQueryResult::Ptr& o
39483948
appendToJson(result, "id", object->id);
39493949
appendToJson(result, "reply_markup", parseInlineKeyboardMarkup(object->replyMarkup));
39503950

3951-
if (object->type == InlineQueryResultCachedAudio::TYPE) {
3952-
result += parseInlineQueryResultCachedAudio(std::static_pointer_cast<InlineQueryResultCachedAudio>(object));
3953-
} else if (object->type == InlineQueryResultCachedDocument::TYPE) {
3954-
result += parseInlineQueryResultCachedDocument(std::static_pointer_cast<InlineQueryResultCachedDocument>(object));
3955-
} else if (object->type == InlineQueryResultCachedGif::TYPE) {
3956-
result += parseInlineQueryResultCachedGif(std::static_pointer_cast<InlineQueryResultCachedGif>(object));
3957-
} else if (object->type == InlineQueryResultCachedMpeg4Gif::TYPE) {
3958-
result += parseInlineQueryResultCachedMpeg4Gif(std::static_pointer_cast<InlineQueryResultCachedMpeg4Gif>(object));
3959-
} else if (object->type == InlineQueryResultCachedPhoto::TYPE) {
3960-
result += parseInlineQueryResultCachedPhoto(std::static_pointer_cast<InlineQueryResultCachedPhoto>(object));
3961-
} else if (object->type == InlineQueryResultCachedSticker::TYPE) {
3962-
result += parseInlineQueryResultCachedSticker(std::static_pointer_cast<InlineQueryResultCachedSticker>(object));
3963-
} else if (object->type == InlineQueryResultCachedVideo::TYPE) {
3964-
result += parseInlineQueryResultCachedVideo(std::static_pointer_cast<InlineQueryResultCachedVideo>(object));
3965-
} else if (object->type == InlineQueryResultCachedVoice::TYPE) {
3966-
result += parseInlineQueryResultCachedVoice(std::static_pointer_cast<InlineQueryResultCachedVoice>(object));
3967-
} else if (object->type == InlineQueryResultArticle::TYPE) {
3951+
// Single type
3952+
if (object->type == InlineQueryResultArticle::TYPE) {
39683953
result += parseInlineQueryResultArticle(std::static_pointer_cast<InlineQueryResultArticle>(object));
3969-
} else if (object->type == InlineQueryResultAudio::TYPE) {
3970-
result += parseInlineQueryResultAudio(std::static_pointer_cast<InlineQueryResultAudio>(object));
39713954
} else if (object->type == InlineQueryResultContact::TYPE) {
39723955
result += parseInlineQueryResultContact(std::static_pointer_cast<InlineQueryResultContact>(object));
39733956
} else if (object->type == InlineQueryResultGame::TYPE) {
39743957
result += parseInlineQueryResultGame(std::static_pointer_cast<InlineQueryResultGame>(object));
3975-
} else if (object->type == InlineQueryResultDocument::TYPE) {
3976-
result += parseInlineQueryResultDocument(std::static_pointer_cast<InlineQueryResultDocument>(object));
39773958
} else if (object->type == InlineQueryResultLocation::TYPE) {
39783959
result += parseInlineQueryResultLocation(std::static_pointer_cast<InlineQueryResultLocation>(object));
39793960
} else if (object->type == InlineQueryResultVenue::TYPE) {
39803961
result += parseInlineQueryResultVenue(std::static_pointer_cast<InlineQueryResultVenue>(object));
3981-
} else if (object->type == InlineQueryResultVoice::TYPE) {
3982-
result += parseInlineQueryResultVoice(std::static_pointer_cast<InlineQueryResultVoice>(object));
3983-
} else if (object->type == InlineQueryResultPhoto::TYPE) {
3984-
result += parseInlineQueryResultPhoto(std::static_pointer_cast<InlineQueryResultPhoto>(object));
3962+
}else if (object->type == InlineQueryResultCachedSticker::TYPE) {
3963+
result += parseInlineQueryResultCachedSticker(std::static_pointer_cast<InlineQueryResultCachedSticker>(object));
3964+
}
3965+
// Use dynamic_cast to distinguish duplicate types
3966+
else if (object->type == InlineQueryResultPhoto::TYPE) {
3967+
if (auto cachedPhoto = std::dynamic_pointer_cast<InlineQueryResultCachedPhoto>(object)) {
3968+
result += parseInlineQueryResultCachedPhoto(cachedPhoto);
3969+
} else if (auto photo = std::dynamic_pointer_cast<InlineQueryResultPhoto>(object)) {
3970+
result += parseInlineQueryResultPhoto(photo);
3971+
}
39853972
} else if (object->type == InlineQueryResultGif::TYPE) {
3986-
result += parseInlineQueryResultGif(std::static_pointer_cast<InlineQueryResultGif>(object));
3987-
} else if (object->type == InlineQueryResultMpeg4Gif::TYPE) {
3988-
result += parseInlineQueryResultMpeg4Gif(std::static_pointer_cast<InlineQueryResultMpeg4Gif>(object));
3973+
if (auto cachedGif = std::dynamic_pointer_cast<InlineQueryResultCachedGif>(object)) {
3974+
result += parseInlineQueryResultCachedGif(cachedGif);
3975+
} else if (auto gif = std::dynamic_pointer_cast<InlineQueryResultGif>(object)) {
3976+
result += parseInlineQueryResultGif(gif);
3977+
}
39893978
} else if (object->type == InlineQueryResultVideo::TYPE) {
3990-
result += parseInlineQueryResultVideo(std::static_pointer_cast<InlineQueryResultVideo>(object));
3979+
if (auto cachedVideo = std::dynamic_pointer_cast<InlineQueryResultCachedVideo>(object)) {
3980+
result += parseInlineQueryResultCachedVideo(cachedVideo);
3981+
} else if (auto video = std::dynamic_pointer_cast<InlineQueryResultVideo>(object)) {
3982+
result += parseInlineQueryResultVideo(video);
3983+
}
3984+
} else if (object->type == InlineQueryResultAudio::TYPE) {
3985+
if (auto cachedAudio = std::dynamic_pointer_cast<InlineQueryResultCachedAudio>(object)) {
3986+
result += parseInlineQueryResultCachedAudio(cachedAudio);
3987+
} else if (auto audio = std::dynamic_pointer_cast<InlineQueryResultAudio>(object)) {
3988+
result += parseInlineQueryResultAudio(audio);
3989+
}
3990+
} else if (object->type == InlineQueryResultVoice::TYPE) {
3991+
if (auto cachedVoice = std::dynamic_pointer_cast<InlineQueryResultCachedVoice>(object)) {
3992+
result += parseInlineQueryResultCachedVoice(cachedVoice);
3993+
} else if (auto voice = std::dynamic_pointer_cast<InlineQueryResultVoice>(object)) {
3994+
result += parseInlineQueryResultVoice(voice);
3995+
}
3996+
} else if (object->type == InlineQueryResultMpeg4Gif::TYPE) {
3997+
if (auto cachedMpeg4Gif = std::dynamic_pointer_cast<InlineQueryResultCachedMpeg4Gif>(object)) {
3998+
result += parseInlineQueryResultCachedMpeg4Gif(cachedMpeg4Gif);
3999+
} else if (auto mpeg4Gif = std::dynamic_pointer_cast<InlineQueryResultMpeg4Gif>(object)) {
4000+
result += parseInlineQueryResultMpeg4Gif(mpeg4Gif);
4001+
}
4002+
} else if (object->type == InlineQueryResultDocument::TYPE) {
4003+
// Document类型也有冲突
4004+
if (auto cachedDocument = std::dynamic_pointer_cast<InlineQueryResultCachedDocument>(object)) {
4005+
result += parseInlineQueryResultCachedDocument(cachedDocument);
4006+
} else if (auto document = std::dynamic_pointer_cast<InlineQueryResultDocument>(object)) {
4007+
result += parseInlineQueryResultDocument(document);
4008+
}
39914009
}
39924010

39934011
removeLastComma(result);

0 commit comments

Comments
 (0)