summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-07-26 17:02:53 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-07-26 17:02:53 +0300
commite0bf792776131deef8f2634fb3eeb8bd8239c059 (patch)
treea004484e81d10505af43d1efa66726d4a9bb6d39 /protocols
parent6f0837663b1aac2ede278e7dd8fb416290f82dad (diff)
.
Diffstat (limited to 'protocols')
-rw-r--r--protocols/ICQ-WIM/src/proto.cpp20
-rw-r--r--protocols/ICQ-WIM/src/proto.h3
-rw-r--r--protocols/JabberG/src/jabber_file.cpp2
-rw-r--r--protocols/JabberG/src/jabber_proto.h2
-rw-r--r--protocols/Telegram/src/avatars.cpp37
-rw-r--r--protocols/Telegram/src/proto.cpp29
-rw-r--r--protocols/Telegram/src/proto.h9
-rw-r--r--protocols/Telegram/src/server.cpp30
-rw-r--r--protocols/Telegram/src/utils.cpp2
9 files changed, 112 insertions, 22 deletions
diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp
index 27af8879f2..078fc8885e 100644
--- a/protocols/ICQ-WIM/src/proto.cpp
+++ b/protocols/ICQ-WIM/src/proto.cpp
@@ -169,14 +169,30 @@ void CIcqProto::OnContactDeleted(MCONTACT hContact)
<< AIMSID(this) << WCHAR_PARAM("buddy", szId) << INT_PARAM("allGroups", 1));
}
-void CIcqProto::OnCreateOfflineFile(DB::FILE_BLOB &blob, void *hTransfer)
+void CIcqProto::OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *ft)
{
- if (auto *pFileInfo = (IcqFileInfo *)hTransfer) {
+ if (auto *pFileInfo = (IcqFileInfo *)ft) {
blob.setUrl(pFileInfo->szOrigUrl);
blob.setSize(pFileInfo->dwFileSize);
}
}
+void CIcqProto::OnSendOfflineFile(DB::EventInfo &dbei, DB::FILE_BLOB &blob, void *hTransfer)
+{
+ auto *ft = (IcqFileTransfer *)hTransfer;
+
+ auto *p = wcsrchr(ft->m_wszFileName, '\\');
+ if (p == nullptr)
+ p = ft->m_wszFileName;
+ else
+ p++;
+ blob.setName(p);
+
+ blob.setUrl("boo");
+ blob.complete(ft->pfts.currentFileSize);
+ blob.setLocalName(ft->m_wszFileName);
+}
+
void CIcqProto::OnEventEdited(MCONTACT, MEVENT)
{
diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h
index 9b91e02383..7ca0874770 100644
--- a/protocols/ICQ-WIM/src/proto.h
+++ b/protocols/ICQ-WIM/src/proto.h
@@ -415,10 +415,11 @@ class CIcqProto : public PROTO<CIcqProto>
void OnContactAdded(MCONTACT) override;
void OnContactDeleted(MCONTACT) override;
MWindow OnCreateAccMgrUI(MWindow) override;
- void OnCreateOfflineFile(DB::FILE_BLOB &blob, void *ft) override;
void OnEventEdited(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 *ft) override;
void OnShutdown() override;
public:
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp
index 863874a011..18ca3c59b3 100644
--- a/protocols/JabberG/src/jabber_file.cpp
+++ b/protocols/JabberG/src/jabber_file.cpp
@@ -108,7 +108,7 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *ofd)
delete ofd;
}
-void CJabberProto::OnCreateOfflineFile(DB::FILE_BLOB &blob, void *pHandle)
+void CJabberProto::OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *pHandle)
{
if (auto *ft = (filetransfer *)pHandle)
if (ft->type == FT_HTTP && ft->httpPath)
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index bc41a58f3c..4a645a894b 100644
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -151,9 +151,9 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
void OnBuildProtoMenu(void) override;
void OnContactDeleted(MCONTACT) override;
MWindow OnCreateAccMgrUI(MWindow) override;
- void OnCreateOfflineFile(DB::FILE_BLOB &blob, void *pHandle);
void OnMarkRead(MCONTACT, MEVENT) override;
void OnModulesLoaded() override;
+ void OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *ft) override;
void OnShutdown() override;
//====| Services |====================================================================
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)