From bad63f163e2821b04b0647a696500bfea58005c2 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 18 May 2023 19:38:36 +0300 Subject: Telegram: fix for getting the biggest photo size --- protocols/Telegram/src/utils.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'protocols/Telegram') diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 47ca4f4648..a694069694 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -295,6 +295,19 @@ CMStringA CTelegramProto::GetMessageSticker(const TD::file *pFile, const char *p return CMStringA(FORMAT, "STK{%s}", pFileId); } +///////////////////////////////////////////////////////////////////////////////////////// + +static const TD::photoSize* GetBiggestPhoto(const TD::photo *pPhoto) +{ + const char *types[] = {"y", "x", "m", "s"}; + for (auto *pType : types) + for (auto &it : pPhoto->sizes_) + if (it->type_ == pType) + return it.get(); + + return nullptr; +} + CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg) { const TD::MessageContent *pBody = pMsg->content_.get(); @@ -308,16 +321,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg case TD::messagePhoto::ID: { auto *pDoc = (TD::messagePhoto *)pBody; - TD::photoSize *pPhoto = nullptr; - - const char *types[] = { "x", "m", "s" }; - for (auto *pType : types) - for (auto &it: pDoc->photo_->sizes_) - if (it->type_ == pType) { - pPhoto = it.get(); - break; - } - + auto *pPhoto = GetBiggestPhoto(pDoc->photo_.get()); if (pPhoto == nullptr) { debugLogA("cannot find photo, exiting"); break; -- cgit v1.2.3