From d3261a063d470c00a3544829ebdac906e3f9b9a9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 13 Nov 2023 15:25:34 +0300 Subject: =?UTF-8?q?fixes=20#3883=20(Telegram:=20=D0=B5=D1=81=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=B2=20Saved=20Messages=20=D0=BD=D0=B8=D0=BA=D0=BE=D0=B3?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=BD=D0=B8=D1=87=D0=B5=D0=B3=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F=D0=BB=D0=B8?= =?UTF-8?q?,=20=D1=82=D0=BE=20=D0=9C=D0=B8=D1=80=D0=B0=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B5=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20=D1=82=D1=83?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=BD=D0=B8=D1=87=D0=B5=D0=B3=D0=BE=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D1=82=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/proto.cpp | 12 ++++++++++++ protocols/Telegram/src/proto.h | 4 ++-- protocols/Telegram/src/server.cpp | 12 ++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'protocols') diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index fff388caa5..cc386b8a11 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -68,6 +68,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) : HookProtoEvent(ME_HISTORY_EMPTY, &CTelegramProto::OnEmptyHistory); HookProtoEvent(ME_OPT_INITIALISE, &CTelegramProto::OnOptionsInit); + HookProtoEvent(ME_MSG_WINDOWEVENT, &CTelegramProto::OnWindowEvent); // avatar CreateDirectoryTreeW(GetAvatarPath()); @@ -160,6 +161,17 @@ void CTelegramProto::OnShutdown() m_bTerminated = true; } +int CTelegramProto::OnWindowEvent(WPARAM wParam, LPARAM lParam) +{ + if (wParam == MSG_WINDOW_EVT_OPENING) { + auto *pDlg = (CMsgDialog *)lParam; + auto *pUser = FindUser(GetId(pDlg->m_hContact)); + if (pUser->chatId == -1 && !pDlg->isChat()) + SendQuery(new TD::createPrivateChat(pUser->id, true)); + } + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// void CTelegramProto::OnBuildProtoMenu() diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index b90f6e9d45..c5566472d8 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -92,7 +92,6 @@ struct TG_USER : public MZeroedObject hContact(_2), isGroupChat(_3) { - chatId = (isGroupChat) ? -1 : id; } ~TG_USER() @@ -100,7 +99,7 @@ struct TG_USER : public MZeroedObject delete pReactions; } - int64_t id, chatId; + int64_t id, chatId = -1; MCONTACT hContact; bool isGroupChat, bLoadMembers; CMStringA szAvatarHash; @@ -363,6 +362,7 @@ public: int __cdecl OnEmptyHistory(WPARAM, LPARAM); int __cdecl OnOptionsInit(WPARAM, LPARAM); + int __cdecl OnWindowEvent(WPARAM, LPARAM); int __cdecl GcMenuHook(WPARAM, LPARAM); int __cdecl GcMuteHook(WPARAM, LPARAM); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 0bd26786be..e2eb723e68 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -418,23 +418,23 @@ void CTelegramProto::ProcessBasicGroup(TD::updateBasicGroup *pObj) void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) { - int64_t chatId; + int64_t userId; auto *pChat = pObj->chat_.get(); std::string szTitle; switch(pChat->type_->get_id()) { case TD::chatTypePrivate::ID: case TD::chatTypeSecret::ID: - chatId = pChat->id_; + userId = pChat->id_; break; case TD::chatTypeBasicGroup::ID: - chatId = ((TD::chatTypeBasicGroup*)pChat->type_.get())->basic_group_id_; + userId = ((TD::chatTypeBasicGroup*)pChat->type_.get())->basic_group_id_; szTitle = pChat->title_; break; case TD::chatTypeSupergroup::ID: - chatId = ((TD::chatTypeSupergroup *)pChat->type_.get())->supergroup_id_; + userId = ((TD::chatTypeSupergroup *)pChat->type_.get())->supergroup_id_; szTitle = pChat->title_; break; @@ -443,7 +443,7 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) return; } - if (auto *pUser = FindUser(chatId)) { + if (auto *pUser = FindUser(userId)) { pUser->chatId = pChat->id_; MCONTACT hContact = (pUser->id == m_iOwnId) ? 0 : pUser->hContact; @@ -463,7 +463,7 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) if (pUser->isGroupChat && pUser->hContact != INVALID_CONTACT_ID) InitGroupChat(pUser, pChat); } - else debugLogA("Unknown chat id %lld, ignoring", chatId); + else debugLogA("Unknown user id %lld, ignoring", userId); } void CTelegramProto::ProcessChatLastMessage(TD::updateChatLastMessage *pObj) -- cgit v1.2.3