diff options
author | George Hazan <ghazan@miranda.im> | 2023-04-25 20:00:55 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-04-25 20:00:55 +0300 |
commit | 9ea18ddc413a8c1eae6c32fe16e162a1998079c1 (patch) | |
tree | 0fcf08adc603e6420fae94bf79d7ede357b96edb /protocols/Telegram | |
parent | c104e058686d3d36bc9b15d84bfd9b84740cd3fa (diff) |
Telegram: offline files to be links from the very beginning
Diffstat (limited to 'protocols/Telegram')
-rw-r--r-- | protocols/Telegram/src/avatars.cpp | 29 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 20 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 6 | ||||
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 2 |
4 files changed, 27 insertions, 30 deletions
diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp index 07ae3e4e45..a588bfa76f 100644 --- a/protocols/Telegram/src/avatars.cpp +++ b/protocols/Telegram/src/avatars.cpp @@ -76,6 +76,7 @@ INT_PTR CTelegramProto::SvcSetMyAvatar(WPARAM, LPARAM) }
/////////////////////////////////////////////////////////////////////////////////////////
+// Offline file downloader
void CTelegramProto::OnGetFileInfo(td::ClientManager::Response &response, void *pUserInfo)
{
@@ -96,12 +97,6 @@ void CTelegramProto::OnGetFileInfo(td::ClientManager::Response &response, void * SendQuery(new TD::downloadFile(pFile->id_, 10, 0, 0, true));
}
-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;
@@ -123,6 +118,25 @@ void __cdecl CTelegramProto::OfflineFileThread(void *pParam) delete ofd;
}
+INT_PTR __cdecl CTelegramProto::OfflineFile(WPARAM param, LPARAM)
+{
+ ForkThread((MyThreadFunc)&CTelegramProto::OfflineFileThread, (void *)param);
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Offline file pre-creator
+
+void CTelegramProto::OnCreateOfflineFile(DB::FILE_BLOB &blob, void *pHandle)
+{
+ if (auto *ft = (TG_FILE_REQUEST *)pHandle) {
+ blob.setUrl(ft->m_uniqueId.GetBuffer());
+ blob.setSize(ft->m_fileSize);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
TG_FILE_REQUEST* CTelegramProto::PopFile(const char *pszUniqueId)
{
mir_cslock lck(m_csFiles);
@@ -134,6 +148,9 @@ TG_FILE_REQUEST* CTelegramProto::PopFile(const char *pszUniqueId) return nullptr;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// handles file info updates
+
void CTelegramProto::ProcessFile(TD::updateFile *pObj)
{
if (auto *pFile = pObj->file_.get()) {
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 172b299ebc..a8f36fbe2e 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -278,26 +278,6 @@ INT_PTR CTelegramProto::GetCaps(int type, MCONTACT) } } -//////////////////////////////////////////////////////////////////////////////////////// -// RecvFile - writes down an incoming file transfer to db - -MEVENT CTelegramProto::RecvFile(MCONTACT hContact, PROTORECVFILE *pre) -{ - MEVENT hEvent = CSuper::RecvFile(hContact, pre); - if (hEvent) { - if (auto *ft = (TG_FILE_REQUEST *)pre->lParam) { - DBVARIANT dbv = { DBVT_UTF8 }; - dbv.pszVal = ft->m_uniqueId.GetBuffer(); - db_event_setJson(hEvent, "u", &dbv); - - dbv.type = DBVT_DWORD; - dbv.dVal = ft->m_fileId; - db_event_setJson(hEvent, "id", &dbv); - } - } - return hEvent; -} - ///////////////////////////////////////////////////////////////////////////////////////// void CTelegramProto::OnSearchResults(td::ClientManager::Response &response) diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 9dca2f81ec..0228ef285a 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -73,7 +73,7 @@ struct TG_FILE_REQUEST : public MZeroedObject Type m_type; bool m_bOpen = false; MEVENT m_hEvent = 0; - TD::int53 m_fileId; + TD::int53 m_fileId, m_fileSize = 0; CMStringA m_uniqueId; CMStringW m_destPath, m_fileName; }; @@ -290,8 +290,6 @@ public: INT_PTR GetCaps(int type, MCONTACT hContact = NULL) override; - MEVENT RecvFile(MCONTACT hContact, PROTORECVFILE *pre) override; - HANDLE SearchByName(const wchar_t *nick, const wchar_t *firstName, const wchar_t *lastName) override; int SendMsg(MCONTACT hContact, int flags, const char *pszMessage) override; int SetStatus(int iNewStatus) override; @@ -299,6 +297,7 @@ public: void OnBuildProtoMenu() override; void OnContactDeleted(MCONTACT hContact) override; MWindow OnCreateAccMgrUI(MWindow hwndParent) override; + void OnCreateOfflineFile(DB::FILE_BLOB &blob, void *ft) override; void OnEventDeleted(MCONTACT, MEVENT) override; void OnMarkRead(MCONTACT, MEVENT) override; void OnModulesLoaded() override; @@ -318,6 +317,7 @@ public: INT_PTR __cdecl AddByPhone(WPARAM, LPARAM); INT_PTR __cdecl OfflineFile(WPARAM, LPARAM); + INT_PTR __cdecl PreCreateOfflineFile(WPARAM, LPARAM); // Options /////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index e63dd889e3..5529dd2418 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -259,7 +259,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg auto *pRequest = new TG_FILE_REQUEST(TG_FILE_REQUEST::FILE, pFile->id_, pFile->remote_->id_.c_str());
pRequest->m_fileName = Utf2T(pDoc->document_->file_name_.c_str());
- pRequest->m_destPath = GetProtoFolder() + L"\\tmpfiles";
+ pRequest->m_fileSize = pFile->size_;
{
mir_cslock lck(m_csFiles);
m_arFiles.insert(pRequest);
|