summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-05-16 18:24:28 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-05-16 18:24:28 +0300
commit2c17233720ff8b78b8a2ef44724b3218a0029589 (patch)
tree53a4008407dab539c6e741af563734e83c826485
parentb320ce679f51799ca9d63a146958ec8e3944a839 (diff)
Telegram: support for animated emoji messages
-rw-r--r--protocols/Telegram/src/proto.h1
-rw-r--r--protocols/Telegram/src/utils.cpp55
2 files changed, 41 insertions, 15 deletions
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index b5fce735ca..a656671e53 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -226,6 +226,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
void ProcessUser(TD::updateUser *pObj);
bool GetMessageFile(TG_FILE_REQUEST::Type, TG_USER *pUser, const TD::file *pFile, const char *pszFileName, const std::string &caption, const char *szId, const char *szUser, time_t);
+ CMStringA GetMessageSticker(const TD::file *pFile, const char *pwszExtension);
CMStringA GetMessageText(TG_USER *pUser, const TD::message *pMsg);
void UpdateString(MCONTACT hContact, const char *pszSetting, const std::string &str);
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp
index a385b616e5..47ca4f4648 100644
--- a/protocols/Telegram/src/utils.cpp
+++ b/protocols/Telegram/src/utils.cpp
@@ -277,6 +277,24 @@ bool CTelegramProto::GetMessageFile(
return true;
}
+CMStringA CTelegramProto::GetMessageSticker(const TD::file *pFile, const char *pwszExtension)
+{
+ auto *pFileId = pFile->remote_->unique_id_.c_str();
+
+ auto *pRequest = new TG_FILE_REQUEST(TG_FILE_REQUEST::AVATAR, pFile->id_, pFileId);
+ pRequest->m_destPath = GetAvatarPath() + L"\\Stickers";
+ CreateDirectoryW(pRequest->m_destPath, 0);
+
+ pRequest->m_fileName.Format(L"STK{%S}.%S", pFileId, pwszExtension);
+ {
+ mir_cslock lck(m_csFiles);
+ m_arFiles.insert(pRequest);
+ }
+
+ SendQuery(new TD::downloadFile(pFile->id_, 10, 0, 0, true));
+ return CMStringA(FORMAT, "STK{%s}", pFileId);
+}
+
CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg)
{
const TD::MessageContent *pBody = pMsg->content_.get();
@@ -339,15 +357,33 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg
}
break;
+ case TD::messageAnimatedEmoji::ID:
+ if (m_bSmileyAdd) {
+ auto *pSticker = ((TD::messageAnimatedEmoji *)pBody)->animated_emoji_->sticker_.get();
+ if (pSticker->type_->get_id() != TD::stickerTypeRegular::ID)
+ break;
+
+ const char *pwszFileExt;
+ switch (pSticker->thumbnail_->format_->get_id()) {
+ case TD::thumbnailFormatGif::ID: pwszFileExt = "gif"; break;
+ case TD::thumbnailFormatPng::ID: pwszFileExt = "png"; break;
+ case TD::thumbnailFormatTgs::ID: pwszFileExt = "tga"; break;
+ case TD::thumbnailFormatJpeg::ID: pwszFileExt = "jpg"; break;
+ case TD::thumbnailFormatWebm::ID: pwszFileExt = "webm"; break;
+ case TD::thumbnailFormatWebp::ID: pwszFileExt = "webp"; break;
+ default:pwszFileExt = "jpeg"; break;
+ }
+
+ return GetMessageSticker(pSticker->thumbnail_->file_.get(), pwszFileExt);
+ }
+ break;
+
case TD::messageSticker::ID:
if (m_bSmileyAdd) {
auto *pSticker = ((TD::messageSticker *)pBody)->sticker_.get();
if (pSticker->type_->get_id() != TD::stickerTypeRegular::ID)
break;
- auto *pFile = pSticker->thumbnail_->file_.get();
- auto *pFileId = pFile->remote_->unique_id_.c_str();
-
const char *pwszFileExt;
switch (pSticker->format_->get_id()) {
case TD::stickerFormatTgs::ID: pwszFileExt = "tga"; break;
@@ -356,18 +392,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg
default:pwszFileExt = "jpeg"; break;
}
- auto *pRequest = new TG_FILE_REQUEST(TG_FILE_REQUEST::AVATAR, pFile->id_, pFileId);
- pRequest->m_destPath = GetAvatarPath() + L"\\Stickers";
- CreateDirectoryW(pRequest->m_destPath, 0);
-
- pRequest->m_fileName.Format(L"STK{%S}.%S", pFileId, pwszFileExt);
- {
- mir_cslock lck(m_csFiles);
- m_arFiles.insert(pRequest);
- }
-
- SendQuery(new TD::downloadFile(pFile->id_, 10, 0, 0, true));
- return CMStringA(FORMAT, "STK{%s}", pFileId);
+ return GetMessageSticker(pSticker->thumbnail_->file_.get(), pwszFileExt);
}
else debugLogA("SmileyAdd plugin isn't installed, skipping sticker");
break;