summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-24 13:10:07 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-24 13:10:07 +0300
commitcce43e30dca000d713131a87ddd78265d71eb763 (patch)
treef65cff1ee61dae9bee7fa462aa98e8c45cbe554c /protocols
parente4a77876719997918082cb4973fe33558292e9a0 (diff)
Telegram: introducing offline files processing
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Telegram/src/avatars.cpp36
-rw-r--r--protocols/Telegram/src/main.cpp2
-rw-r--r--protocols/Telegram/src/proto.cpp3
-rw-r--r--protocols/Telegram/src/proto.h2
-rw-r--r--protocols/Telegram/src/stdafx.h3
5 files changed, 45 insertions, 1 deletions
diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp
index 0253152df0..6add2ae982 100644
--- a/protocols/Telegram/src/avatars.cpp
+++ b/protocols/Telegram/src/avatars.cpp
@@ -77,6 +77,42 @@ INT_PTR CTelegramProto::SvcSetMyAvatar(WPARAM, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
+
+INT_PTR __cdecl CTelegramProto::OfflineFile(WPARAM param, LPARAM)
+{
+ ForkThread((MyThreadFunc)&CTelegramProto::OfflineFileThread, (void *)param);
+ return 0;
+}
+
+void __cdecl CTelegramProto::OfflineFileThread(void *pParam)
+{
+ auto *ofd = (OFDTHREAD *)pParam;
+
+ DB::EventInfo dbei(ofd->hDbEvent);
+ if (dbei && !strcmp(dbei.szModule, m_szModuleName) && dbei.eventType == EVENTTYPE_FILE) {
+ JSONNode root = JSONNode::parse((const char *)dbei.pBlob);
+ if (root) {
+ int iFileId = root["id"].as_int();
+ auto *ft = new TG_FILE_REQUEST(TG_FILE_REQUEST::FILE, iFileId, root["u"].as_string().c_str());
+ ft->m_fileName = ofd->wszPath;
+ m_arFiles.insert(ft);
+
+ SendQuery(new TD::downloadFile(iFileId, 10, 0, 0, true));
+
+ DBVARIANT dbv = { DBVT_DWORD };
+ dbv.dVal = ft->pfts.currentFileSize;
+ db_event_setJson(ofd->hDbEvent, "ft", &dbv);
+ db_event_setJson(ofd->hDbEvent, "fs", &dbv);
+ NotifyEventHooks(g_plugin.m_hevEventEdited, 0, ofd->hDbEvent);
+
+ if (ofd->bOpen)
+ ShellExecuteW(nullptr, L"open", ofd->wszPath, nullptr, nullptr, SW_SHOWDEFAULT);
+ }
+ }
+
+ delete ofd;
+}
+
TG_FILE_REQUEST* CTelegramProto::PopFile(const char *pszUniqueId)
{
mir_cslock lck(m_csFiles);
diff --git a/protocols/Telegram/src/main.cpp b/protocols/Telegram/src/main.cpp
index e3f59b0d6b..8da16989ec 100644
--- a/protocols/Telegram/src/main.cpp
+++ b/protocols/Telegram/src/main.cpp
@@ -48,5 +48,7 @@ int CMPlugin::Load()
registerIcon("Protocols/Telegram", iconList, "tg");
m_hIcon = ExtraIcon_RegisterIcolib("tg_premium", "Telegram Premium User", getIconHandle(IDI_PREMIUM));
+
+ m_hevEventEdited = CreateHookableEvent(ME_DB_EVENT_EDITED);
return 0;
}
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index a07932b3d4..11bed96d85 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -68,6 +68,9 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) :
// default contacts group
m_iBaseGroup = Clist_GroupCreate(0, m_wszDefaultGroup);
+ // Offline file transfer
+ CreateProtoService(PS_OFFLINEFILE, &CTelegramProto::OfflineFile);
+
// create standard network connection
NETLIBUSER nlu = {};
nlu.flags = NUF_UNICODE;
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index 562be0e434..25c4bd9af3 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -319,6 +319,7 @@ public:
// Services //////////////////////////////////////////////////////////////////////////
INT_PTR __cdecl AddByPhone(WPARAM, LPARAM);
+ INT_PTR __cdecl OfflineFile(WPARAM, LPARAM);
// Options ///////////////////////////////////////////////////////////////////////////
@@ -335,6 +336,7 @@ public:
// Processing Threads ////////////////////////////////////////////////////////////////
+ void __cdecl OfflineFileThread(void *);
void __cdecl ServerThread(void *);
};
diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h
index 0d24bfcf3c..41799575cc 100644
--- a/protocols/Telegram/src/stdafx.h
+++ b/protocols/Telegram/src/stdafx.h
@@ -21,6 +21,7 @@
#include <m_extraicons.h>
#include <m_history.h>
#include <m_icolib.h>
+#include <m_json.h>
#include <m_langpack.h>
#include <m_message.h>
#include <m_netlib.h>
@@ -47,7 +48,7 @@ struct CMPlugin : public ACCPROTOPLUGIN<CTelegramProto>
{
CMPlugin();
- HANDLE m_hIcon;
+ HANDLE m_hIcon, m_hevEventEdited;
int Load() override;
};