From 529c9641612e912e05161fd928ce62169c753daa Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 9 Feb 2024 19:58:07 +0300 Subject: Telegram: fix for fetching files sent by me from another device --- protocols/Telegram/src/proto.cpp | 8 -------- protocols/Telegram/src/proto.h | 1 - protocols/Telegram/src/server.cpp | 8 +++++++- protocols/Telegram/src/utils.cpp | 18 ++++++++++++++---- 4 files changed, 21 insertions(+), 14 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index f28ff289a1..555a336b5b 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -354,14 +354,6 @@ INT_PTR CTelegramProto::GetCaps(int type, MCONTACT) ///////////////////////////////////////////////////////////////////////////////////////// -MEVENT CTelegramProto::RecvFile(MCONTACT hContact, DB::FILE_BLOB &blob, DB::EventInfo &dbei) -{ - auto *ft = (TG_FILE_REQUEST *)blob.getUserInfo(); - return (ft->m_bRecv) ? CSuper::RecvFile(hContact, blob, dbei) : 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - void CTelegramProto::OnSearchResults(td::ClientManager::Response &response) { int iCount = ::InterlockedDecrement(&m_iSearchCount); diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 830b937e05..2b628abfc2 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -358,7 +358,6 @@ public: INT_PTR GetCaps(int type, MCONTACT hContact = NULL) override; HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override; - MEVENT RecvFile(MCONTACT hContact, DB::FILE_BLOB &blob, DB::EventInfo &dbei) override; HANDLE SearchByName(const wchar_t *nick, const wchar_t *firstName, const wchar_t *lastName) override; int SendMsg(MCONTACT hContact, MEVENT hReplyEvent, const char *pszMessage) override; diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 2082a73e13..762d6d121a 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -820,16 +820,22 @@ void CTelegramProto::ProcessMessageContent(TD::updateMessageContent *pObj) return; } - MEVENT hDbEvent = db_event_getById(m_szModuleName, msg2id(pObj->chat_id_, pObj->message_id_)); + auto szMsgId = msg2id(pObj->chat_id_, pObj->message_id_); + MEVENT hDbEvent = db_event_getById(m_szModuleName, szMsgId); if (hDbEvent == 0) { debugLogA("Unknown message with id=%lld (chat id %lld, ignored", pObj->message_id_, pObj->chat_id_); return; } auto msg = TD::make_object(); + msg->id_ = pObj->message_id_; msg->sender_id_ = TD::make_object(pObj->chat_id_); msg->content_ = std::move(pObj->new_content_); + TG_OWN_MESSAGE tmp(0, 0, szMsgId); + if (auto *pOwnMsg = m_arOwnMsg.find(&tmp)) + msg->is_outgoing_ = true; + CMStringA szText(GetMessageText(pUser, msg.get())); if (szText.IsEmpty()) { debugLogA("this message was not processed, ignored"); diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 8a4ef0dc0e..c3c13e594b 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -396,6 +396,7 @@ bool CTelegramProto::GetMessageFile( pRequest->m_fileName = Utf2T(pszFileName); pRequest->m_fileSize = pFile->size_; pRequest->m_bRecv = !pMsg->is_outgoing_; + pRequest->m_hContact = GetRealContact(pUser); { mir_cslock lck(m_csFiles); m_arFiles.insert(pRequest); @@ -403,8 +404,9 @@ bool CTelegramProto::GetMessageFile( char szReplyId[100]; const char *szDesc = nullptr; - MCONTACT hContact = GetRealContact(pUser); - DB::EventInfo dbei; + + MEVENT hDbEvent = db_event_getById(m_szModuleName, pszId); + DB::EventInfo dbei(hDbEvent); dbei.flags = DBEF_TEMPORARY; dbei.timestamp = pMsg->date_; dbei.szId = pszId; @@ -413,13 +415,21 @@ bool CTelegramProto::GetMessageFile( szDesc = caption.c_str(); if (pMsg->is_outgoing_) dbei.flags |= DBEF_SENT; - if (Contact::IsGroupChat(hContact) || !pUser->bInited) + if (Contact::IsGroupChat(pRequest->m_hContact) || !pUser->bInited) dbei.flags |= DBEF_READ; if (pMsg->reply_to_message_id_) { _i64toa(pMsg->reply_to_message_id_, szReplyId, 10); dbei.szReplyId = szReplyId; } - ProtoChainRecvFile(hContact, DB::FILE_BLOB(pRequest, pszFileName, szDesc), dbei); + + if (dbei) { + DB::FILE_BLOB blob(dbei); + OnReceiveOfflineFile(blob, pRequest); + blob.write(dbei); + db_event_edit(hDbEvent, &dbei, true); + delete pRequest; + } + else ProtoChainRecvFile(pRequest->m_hContact, DB::FILE_BLOB(pRequest, pszFileName, szDesc), dbei); return true; } -- cgit v1.2.3