diff options
author | George Hazan <george.hazan@gmail.com> | 2023-05-18 19:38:36 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-05-18 19:38:36 +0300 |
commit | bad63f163e2821b04b0647a696500bfea58005c2 (patch) | |
tree | f4728d4de0daac8e9aa04a622ea169fccb8d391f /protocols/Telegram/src | |
parent | 7eb308deaca4c8057338e39f2a27ea5e5f1c5786 (diff) |
Telegram: fix for getting the biggest photo size
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
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;
|