summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-02-21 16:44:57 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-02-21 16:45:09 +0300
commit4d2f4fab80174f6ab5e730b62fdf7abda015768b (patch)
treee73b02c0677310deadb527c87fe563750f2625f5 /protocols/Telegram/src
parentdd04ab6b71d069bdf227762e9af05ec7811ce9a2 (diff)
Telegram: зародыш файл трансферов
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/proto.cpp28
-rw-r--r--protocols/Telegram/src/proto.h8
-rw-r--r--protocols/Telegram/src/server.cpp2
-rw-r--r--protocols/Telegram/src/utils.cpp36
4 files changed, 69 insertions, 5 deletions
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<CTelegramProto>
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;