diff options
author | George Hazan <george.hazan@gmail.com> | 2023-07-26 17:02:53 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-07-26 17:02:53 +0300 |
commit | e0bf792776131deef8f2634fb3eeb8bd8239c059 (patch) | |
tree | a004484e81d10505af43d1efa66726d4a9bb6d39 /protocols/Telegram | |
parent | 6f0837663b1aac2ede278e7dd8fb416290f82dad (diff) |
.
Diffstat (limited to 'protocols/Telegram')
-rw-r--r-- | protocols/Telegram/src/avatars.cpp | 37 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 29 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 9 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 30 | ||||
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 2 |
5 files changed, 90 insertions, 17 deletions
diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp index 48236fd9e7..8551dda5b8 100644 --- a/protocols/Telegram/src/avatars.cpp +++ b/protocols/Telegram/src/avatars.cpp @@ -124,7 +124,7 @@ INT_PTR __cdecl CTelegramProto::SvcOfflineFile(WPARAM param, LPARAM) /////////////////////////////////////////////////////////////////////////////////////////
// Offline file pre-creator
-void CTelegramProto::OnCreateOfflineFile(DB::FILE_BLOB &blob, void *pHandle)
+void CTelegramProto::OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *pHandle)
{
if (auto *ft = (TG_FILE_REQUEST *)pHandle) {
blob.setUrl(ft->m_uniqueId.GetBuffer());
@@ -132,6 +132,26 @@ void CTelegramProto::OnCreateOfflineFile(DB::FILE_BLOB &blob, void *pHandle) }
}
+void CTelegramProto::OnSendOfflineFile(DB::EventInfo &dbei, DB::FILE_BLOB &blob, void *hTransfer)
+{
+ auto *ft = (TG_FILE_REQUEST *)hTransfer;
+
+ dbei.szId = ft->m_uniqueId;
+ if (!ft->m_szUserId.IsEmpty())
+ dbei.szUserId = ft->m_szUserId;
+
+ auto *p = wcsrchr(ft->m_fileName, '\\');
+ if (p == nullptr)
+ p = ft->m_fileName;
+ else
+ p++;
+ blob.setName(p);
+
+ blob.setUrl("boo");
+ blob.complete(ft->m_fileSize);
+ blob.setLocalName(ft->m_fileName);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
TG_FILE_REQUEST* CTelegramProto::PopFile(const char *pszUniqueId)
@@ -216,6 +236,21 @@ void CTelegramProto::ProcessFile(TD::updateFile *pObj) return;
}
+ for (auto &it : m_arOwnMsg) {
+ if (it->tmpFileId == pFile->id_) {
+ if (!pFile->remote_->id_.empty()) {
+ char szId[100];
+ _i64toa(it->tmpMsgId, szId, 10);
+ if (auto hDbEvent = db_event_getById(m_szModuleName, szId)) {
+ DBVARIANT dbv = { DBVT_UTF8 };
+ dbv.pszVal = (char *)pFile->remote_->id_.c_str();
+ db_event_setJson(hDbEvent, "u", &dbv);
+ }
+ }
+ return;
+ }
+ }
+
for (auto &it : m_arUsers) {
if (it->szAvatarHash == pFile->remote_->unique_id_.c_str()) {
PROTO_AVATAR_INFORMATION pai;
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 731d7babf1..849c0469f8 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -415,11 +415,36 @@ HANDLE CTelegramProto::SendFile(MCONTACT hContact, const wchar_t *szDescription, return pTransfer; } -void CTelegramProto::OnSendFile(td::ClientManager::Response &, void *pUserInfo) +void CTelegramProto::OnSendFile(td::ClientManager::Response &response, void *pUserInfo) { auto *ft = (TG_FILE_REQUEST *)pUserInfo; + + if (response.object->get_id() == TD::message::ID) { + auto *pMsg = (TD::message *)response.object.get(); + ft->m_uniqueId.Format("%lld", pMsg->id_); + + if (auto *pUser = FindChat(pMsg->chat_id_)) { + char szUserId[100]; + if (this->GetGcUserId(pUser, pMsg, szUserId)) + ft->m_szUserId = szUserId; + + auto *pOwnMsg = new TG_OWN_MESSAGE(pUser->hContact, 0, pMsg->id_); + const TD::MessageContent *pBody = pMsg->content_.get(); + switch (pBody->get_id()) { + case TD::messagePhoto::ID: + pOwnMsg->tmpFileId = ((TD::messagePhoto*)pBody)->photo_->sizes_[0]->photo_->id_; + break; + + case TD::messageDocument::ID: + pOwnMsg->tmpFileId = ((TD::messageDocument *)pBody)->document_->document_->id_; + break; + } + m_arOwnMsg.insert(pOwnMsg); + } + } + ProtoBroadcastAck(ft->m_hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ft); - delete ft; + delete ft; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 4fefc25766..32376a5710 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -80,7 +80,7 @@ struct TG_FILE_REQUEST : public MZeroedObject Type m_type; MCONTACT m_hContact = 0; TD::int53 m_fileId, m_fileSize = 0; - CMStringA m_uniqueId; + CMStringA m_uniqueId, m_szUserId; CMStringW m_destPath, m_fileName, m_wszDescr; OFDTHREAD *ofd = 0; }; @@ -137,7 +137,7 @@ struct TG_OWN_MESSAGE tmpMsgId(_3) {} - int64_t tmpMsgId; + int64_t tmpMsgId, tmpFileId = -1; HANDLE hAck; MCONTACT hContact; }; @@ -340,12 +340,13 @@ public: void OnBuildProtoMenu() override; void OnContactDeleted(MCONTACT hContact) override; MWindow OnCreateAccMgrUI(MWindow hwndParent) override; - void OnCreateOfflineFile(DB::FILE_BLOB &blob, void *ft) override; + void OnErase() override; void OnEventDeleted(MCONTACT, MEVENT) override; void OnMarkRead(MCONTACT, MEVENT) override; void OnModulesLoaded() override; + void OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *ft) override; + void OnSendOfflineFile(DB::EventInfo &dbei, DB::FILE_BLOB &blob, void *hTransfer) override; void OnShutdown() override; - void OnErase() override; // Events //////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index b702e95177..7241123e9b 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -1,4 +1,4 @@ --/*
+/*
Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
@@ -184,12 +184,24 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response) case TD::updateMessageSendSucceeded::ID:
{
auto *pMessage = (TD::updateMessageSendSucceeded *)response.object.get();
+
+ if (pMessage->old_message_id_) {
+ char szId[100];
+ _i64toa(pMessage->old_message_id_, szId, 10);
+ if (auto hDbEvent = db_event_getById(m_szModuleName, szId)) {
+ _i64toa(pMessage->message_->id_, szId, 10);
+ db_event_updateId(hDbEvent, szId);
+ }
+ }
+
ProcessMessage(pMessage->message_.get());
if (auto *pOwnMsg = m_arOwnMsg.find((TG_OWN_MESSAGE *)&pMessage->old_message_id_)) {
- char szMsgId[100];
- _i64toa(pMessage->message_->id_, szMsgId, 10);
- ProtoBroadcastAck(pOwnMsg->hContact ? pOwnMsg->hContact : m_iSavedMessages, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, pOwnMsg->hAck, (LPARAM)szMsgId);
+ if (pOwnMsg->hAck) {
+ char szMsgId[100];
+ _i64toa(pMessage->message_->id_, szMsgId, 10);
+ ProtoBroadcastAck(pOwnMsg->hContact ? pOwnMsg->hContact : m_iSavedMessages, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, pOwnMsg->hAck, (LPARAM)szMsgId);
+ }
m_arOwnMsg.remove(pOwnMsg);
}
@@ -623,6 +635,11 @@ void CTelegramProto::ProcessMessage(const TD::message *pMessage) if (pMessage->sending_state_->get_id() == TD::messageSendingStatePending::ID)
return;
+ char szId[100], szUserId[100];
+ _i64toa(pMessage->id_, szId, 10);
+ if (db_event_getById(m_szModuleName, szId))
+ return;
+
CMStringA szText(GetMessageText(pUser, pMessage));
if (szText.IsEmpty()) {
debugLogA("this message was not processed, ignored");
@@ -640,11 +657,6 @@ void CTelegramProto::ProcessMessage(const TD::message *pMessage) Contact::RemoveFromList(pUser->hContact);
}
- char szId[100], szUserId[100];
- _i64toa(pMessage->id_, szId, 10);
- if (db_event_getById(m_szModuleName, szId))
- return;
-
PROTORECVEVENT pre = {};
pre.szMessage = szText.GetBuffer();
pre.szMsgId = szId;
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 849f5c2399..b3d3598c82 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -330,7 +330,7 @@ CMStringA CTelegramProto::GetMessageSticker(const TD::file *pFile, const char *p static const TD::photoSize* GetBiggestPhoto(const TD::photo *pPhoto)
{
- const char *types[] = {"y", "x", "m", "s"};
+ const char *types[] = { "y", "x", "m", "s" };
for (auto *pType : types)
for (auto &it : pPhoto->sizes_)
if (it->type_ == pType)
|