From c844602f5ce38621c6bd832155a43b0b8f8efc16 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 9 Mar 2023 16:24:26 +0300 Subject: =?UTF-8?q?fixes=20#3406=20(Telegram:=20=D0=BD=D0=B5=20=D1=81?= =?UTF-8?q?=D0=B8=D1=85=D1=80=D0=BE=D0=BD=D0=B8=D0=B7=D0=B8=D1=80=D1=83?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D0=BE=D1=84=D0=B8?= =?UTF-8?q?=D1=86=D0=B8=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=BC=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B8=D0=B5=D0=BD=D1=82=D0=BE=D0=BC=20=D0=B8=20=D0=9C=D0=B8?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B4=D0=BE=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/proto.h | 1 + protocols/Telegram/src/server.cpp | 42 +++++++++++++++++++++++++++++++++++++++ protocols/Telegram/src/stdafx.h | 1 + 3 files changed, 44 insertions(+) diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 8dd9ca1fa9..83909acf1f 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -189,6 +189,7 @@ class CTelegramProto : public PROTO void ProcessAuth(TD::updateAuthorizationState *pObj); void ProcessBasicGroup(TD::updateBasicGroup *pObj); void ProcessChat(TD::updateNewChat *pObj); + void ProcessChatLastMessage(TD::updateChatLastMessage *pObj); void ProcessChatPosition(TD::updateChatPosition *pObj); void ProcessFile(TD::updateFile *pObj); void ProcessGroups(TD::updateChatFilters *pObj); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 167b2badae..d3a5afcacd 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -138,6 +138,10 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response) ProcessGroups((TD::updateChatFilters *)response.object.get()); break; + case TD::updateChatLastMessage::ID: + ProcessChatLastMessage((TD::updateChatLastMessage *)response.object.get()); + break; + case TD::updateChatPosition::ID: ProcessChatPosition((TD::updateChatPosition *)response.object.get()); break; @@ -321,6 +325,29 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) else debugLogA("Unknown chat id %lld, ignoring", chatId); } +void CTelegramProto::ProcessChatLastMessage(TD::updateChatLastMessage *pObj) +{ + auto *pUser = FindChat(pObj->chat_id_); + if (pUser == nullptr) { + debugLogA("Unknown chat, skipping"); + return; + } + + if (pUser->hContact == INVALID_CONTACT_ID) { + debugLogA("Last message for a temporary contact, skipping"); + return; + } + + // according to #3406 we wipe history for the contacts from contacts' list + // but remove the contact itself if it's a temporary one + if (pObj->last_message_ == nullptr) { + if (Contact::OnList(pUser->hContact)) + CallService(MS_HISTORY_EMPTY, pUser->hContact, TRUE); + else + db_delete_contact(pUser->hContact, true); + } +} + void CTelegramProto::ProcessChatPosition(TD::updateChatPosition *pObj) { if (pObj->position_->get_id() != TD::chatPosition::ID) { @@ -429,6 +456,17 @@ void CTelegramProto::ProcessMessage(TD::updateNewMessage *pObj) return; } + // make a temporary contact if needed + if (pUser->hContact == INVALID_CONTACT_ID) { + if (pUser->isGroupChat) { + debugLogA("spam from unknown group chat, ignored"); + return; + } + + AddUser(pUser->id, false); + Contact::RemoveFromList(pUser->hContact); + } + char szId[100], szUserId[100]; _i64toa(pMessage->id_, szId, 10); @@ -501,6 +539,9 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj) if (!pUser->is_contact_) { auto *pu = AddFakeUser(pUser->id_, false); + if (pu->hContact != INVALID_CONTACT_ID) + Contact::RemoveFromList(pu->hContact); + pu->wszFirstName = Utf2T(pUser->first_name_.c_str()); pu->wszLastName = Utf2T(pUser->last_name_.c_str()); if (pUser->usernames_) { @@ -527,6 +568,7 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj) UpdateString(pu->hContact, "Nick", pUser->usernames_->editable_username_); if (pu->hContact == 0) pu->wszNick = Contact::GetInfo(CNF_DISPLAY, 0, m_szModuleName); + Contact::PutOnList(pu->hContact); if (pUser->is_premium_) ExtraIcon_SetIconByName(g_plugin.m_hIcon, pu->hContact, "tg_premium"); diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h index 1e5a33925a..0d24bfcf3c 100644 --- a/protocols/Telegram/src/stdafx.h +++ b/protocols/Telegram/src/stdafx.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3