From 4d2f4fab80174f6ab5e730b62fdf7abda015768b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 21 Feb 2023 16:44:57 +0300 Subject: =?UTF-8?q?Telegram:=20=D0=B7=D0=B0=D1=80=D0=BE=D0=B4=D1=8B=D1=88?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=20=D1=82=D1=80=D0=B0=D0=BD=D1=81?= =?UTF-8?q?=D1=84=D0=B5=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/proto.cpp | 28 ++++++++++++++++++++++++++++ protocols/Telegram/src/proto.h | 8 ++++++-- protocols/Telegram/src/server.cpp | 2 +- protocols/Telegram/src/utils.cpp | 36 ++++++++++++++++++++++++++++++++++-- 4 files changed, 69 insertions(+), 5 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index c823679106..b9f362fea0 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -213,6 +213,34 @@ INT_PTR CTelegramProto::GetCaps(int type, MCONTACT) ///////////////////////////////////////////////////////////////////////////////////////// +HANDLE CTelegramProto::FileAllow(MCONTACT, HANDLE hTransfer, const wchar_t *pwszSavePath) +{ + auto *ft = (TG_FILE_REQUEST *)hTransfer; + if (ft == nullptr) + return nullptr; + + return ft; +} + +int CTelegramProto::FileCancel(MCONTACT hContact, HANDLE hTransfer) +{ + auto *ft = (TG_FILE_REQUEST *)hTransfer; + + return 1; +} + +int CTelegramProto::FileResume(HANDLE hTransfer, int, const wchar_t *pwszFilename) +{ + auto *ft = (TG_FILE_REQUEST *)hTransfer; + if (ft == nullptr) + return 1; + + ft->m_destPath = pwszFilename; + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + void CTelegramProto::OnSearchResults(td::ClientManager::Response &response) { m_searchIds.clear(); diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 4b5c1afa13..f16a650c94 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -61,7 +61,7 @@ struct TG_REQUEST_FULL : public TG_REQUEST_BASE struct TG_FILE_REQUEST { - enum Type { AVATAR = 1 }; + enum Type { AVATAR = 1, FILE = 2 }; TG_FILE_REQUEST(Type _1, const char *_2, const wchar_t *_3) : m_type(_1), @@ -196,7 +196,7 @@ class CTelegramProto : public PROTO void ProcessSuperGroup(TD::updateSupergroup *pObj); void ProcessUser(TD::updateUser *pObj); - CMStringA GetMessageText(TD::MessageContent *pBody); + CMStringA GetMessageText(TG_USER *pUser, TD::MessageContent *pBody); void UpdateString(MCONTACT hContact, const char *pszSetting, const std::string &str); @@ -251,6 +251,10 @@ public: MCONTACT AddToList(int flags, PROTOSEARCHRESULT *psr); + HANDLE FileAllow(MCONTACT hContact, HANDLE hTransfer, const wchar_t *szPath) override; + int FileCancel(MCONTACT hContact, HANDLE hTransfer) override; + int FileResume(HANDLE hTransfer, int action, const wchar_t *szFilename) override; + INT_PTR GetCaps(int type, MCONTACT hContact = NULL) override; HANDLE SearchByName(const wchar_t *nick, const wchar_t *firstName, const wchar_t *lastName) override; diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 66fcd2f6f8..f4dfd60353 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -413,7 +413,7 @@ void CTelegramProto::ProcessMessage(TD::updateNewMessage *pObj) return; } - CMStringA szText(GetMessageText(pMessage->content_.get())); + CMStringA szText(GetMessageText(pUser, pMessage->content_.get())); if (szText.IsEmpty()) { debugLogA("this message was not processed, ignored"); return; diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 8a5a1ddb87..3bba3e0e3f 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -201,12 +201,44 @@ void CTelegramProto::Popup(MCONTACT hContact, const wchar_t *szMsg, const wchar_ ///////////////////////////////////////////////////////////////////////////////////////// -CMStringA CTelegramProto::GetMessageText(TD::MessageContent *pBody) +CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, TD::MessageContent *pBody) { switch (pBody->get_id()) { + case TD::messageDocument::ID: + { + auto *pDoc = ((TD::messageDocument *)pBody); + auto *pFile = pDoc->document_->document_.get(); + + if (pFile->get_id() != TD::file::ID) { + debugLogA("Document contains unsupported type %d, exiting", pDoc->document_->get_id()); + break; + } + + auto *pFileId = pFile->remote_->unique_id_.c_str(); + + CMStringW wszDest(GetProtoFolder() + L"\\tmpfiles"); + CreateDirectoryW(wszDest, 0); + wszDest.AppendFormat(L"\\%s", Utf2T(pDoc->document_->file_name_.c_str()).get()); + + auto *pRequest = new TG_FILE_REQUEST(TG_FILE_REQUEST::FILE, pFileId, wszDest); + m_arFiles.insert(pRequest); + + auto *pszFileName = pDoc->document_->file_name_.c_str(); + + PROTORECVFILE pre = {}; + pre.fileCount = 1; + pre.timestamp = time(0); + pre.files.a = &pszFileName; + pre.lParam = (LPARAM)pRequest; + if (!pDoc->caption_->text_.empty()) + pre.descr.a = pDoc->caption_->text_.c_str(); + ProtoChainRecvFile(pUser->hContact, &pre); + } + break; + case TD::messageSticker::ID: if (m_bSmileyAdd) { - auto pSticker = ((TD::messageSticker *)pBody)->sticker_.get(); + auto *pSticker = ((TD::messageSticker *)pBody)->sticker_.get(); if (pSticker->type_->get_id() != TD::stickerTypeRegular::ID) break; -- cgit v1.2.3