diff options
author | George Hazan <george.hazan@gmail.com> | 2024-03-30 18:12:14 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-03-30 18:12:14 +0300 |
commit | 79353069a2cc268c37c3bf8c50e8d74039298231 (patch) | |
tree | 7ff8604ea709895a960c86dbf2709c87954a8e59 | |
parent | a0d3ac9fe7dd5ae3654342b874039dbaf03e81ac (diff) |
fixes #4318 (Telegram: url preview)
-rw-r--r-- | protocols/Telegram/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 42 |
2 files changed, 42 insertions, 1 deletions
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index d7c6587c70..2fcc8b65d6 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -282,6 +282,7 @@ class CTelegramProto : public PROTO<CTelegramProto> void UnregisterSession(); 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, const TD::message *pMsg); + CMStringA GetMessagePreview(const TD::file *pFile); CMStringA GetMessageSticker(const TD::file *pFile, const char *pwszExtension); CMStringA GetMessageText(TG_USER *pUser, const TD::message *pMsg, bool bSkipJoin = false); diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 1d0fdd4a66..f3416fbf46 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -444,6 +444,24 @@ bool CTelegramProto::GetMessageFile( return true;
}
+CMStringA CTelegramProto::GetMessagePreview(const TD::file *pFile)
+{
+ 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"\\Preview";
+ CreateDirectoryW(pRequest->m_destPath, 0);
+
+ pRequest->m_fileName.Format(L"{%S}.jpg", pFileId);
+ {
+ mir_cslock lck(m_csFiles);
+ m_arFiles.insert(pRequest);
+ }
+
+ SendQuery(new TD::downloadFile(pFile->id_, 10, 0, 0, true));
+ return T2Utf(pRequest->m_destPath + L"\\" + pRequest->m_fileName).get();
+}
+
CMStringA CTelegramProto::GetMessageSticker(const TD::file *pFile, const char *pwszExtension)
{
auto *pFileId = pFile->remote_->unique_id_.c_str();
@@ -654,7 +672,29 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg break;
case TD::messageText::ID:
- ret = getFormattedText(((TD::messageText *)pBody)->text_);
+ if (auto *pText = ((TD::messageText *)pBody)) {
+ ret = getFormattedText(pText->text_);
+
+ if (auto *pWeb = pText->web_page_.get()) {
+ ret.AppendFormat("\r\n[url]%s[/url]", pWeb->embed_url_.c_str());
+
+ if (pWeb->photo_) {
+ const TD::photoSize *pSize = nullptr;
+ for (auto &it : pWeb->photo_->sizes_)
+ if (it->type_ == "m")
+ pSize = it.get();
+
+ if (pSize == nullptr)
+ pSize = pWeb->photo_->sizes_[0].get();
+
+ if (auto szText = GetMessagePreview(pSize->photo_.get()))
+ ret.AppendFormat("\r\n[img=%s][/img]", szText.c_str());
+ }
+
+ if (auto szText = getFormattedText(pWeb->description_))
+ ret.AppendFormat("\r\n%s", szText.c_str());
+ }
+ }
break;
}
|