diff options
author | George Hazan <ghazan@miranda.im> | 2023-04-24 13:10:07 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-04-24 13:10:07 +0300 |
commit | cce43e30dca000d713131a87ddd78265d71eb763 (patch) | |
tree | f65cff1ee61dae9bee7fa462aa98e8c45cbe554c | |
parent | e4a77876719997918082cb4973fe33558292e9a0 (diff) |
Telegram: introducing offline files processing
-rw-r--r-- | protocols/Telegram/src/avatars.cpp | 36 | ||||
-rw-r--r-- | protocols/Telegram/src/main.cpp | 2 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 3 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 2 | ||||
-rw-r--r-- | protocols/Telegram/src/stdafx.h | 3 | ||||
-rw-r--r-- | src/mir_app/src/chat_log.cpp | 26 |
6 files changed, 65 insertions, 7 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;
};
diff --git a/src/mir_app/src/chat_log.cpp b/src/mir_app/src/chat_log.cpp index 8bbf25805b..5ec5afe834 100644 --- a/src/mir_app/src/chat_log.cpp +++ b/src/mir_app/src/chat_log.cpp @@ -303,14 +303,28 @@ void CRtfLogWindow::CreateChatRtfMessage(RtfChatLogStreamData *streamData, const CMStringW wszCaption;
bool bTextUsed = Chat_GetDefaultEventDescr(streamData->si, &lin, wszCaption);
- if (!wszCaption.IsEmpty())
+ if (!wszCaption.IsEmpty()) {
+ wszCaption.AppendChar(' ');
lin.write(streamData, !bTextUsed, buf, wszCaption);
-
- if (!bTextUsed && lin.ptszText) {
- if (!wszCaption.IsEmpty())
- lin.write(streamData, false, buf, L" ");
- lin.write(streamData, false, buf, lin.ptszText);
}
+ if (bTextUsed)
+ return;
+
+ if (lin.hEvent) {
+ DB::EventInfo dbei(lin.hEvent);
+ if (dbei) {
+ if (dbei.eventType == EVENTTYPE_FILE) {
+ DB::FILE_BLOB blob(dbei);
+ if (blob.isOffline())
+ InsertFileLink(buf, lin.hEvent, blob);
+ else
+ lin.write(streamData, false, buf, ptrW(DbEvent_GetTextW(&dbei, CP_UTF8)));
+ }
+ return;
+ }
+ }
+ if (lin.ptszText)
+ lin.write(streamData, false, buf, lin.ptszText);
}
/////////////////////////////////////////////////////////////////////////////////////////
|