From 670e1de41f7239592dc8e66fa3be3fc103ff0603 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 1 Mar 2024 12:20:23 +0300 Subject: fixes #4257 (Telegram: ignore Main folder) --- protocols/Telegram/src/proto.h | 1 + protocols/Telegram/src/server.cpp | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 6b778deda6..c0bb072248 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -99,6 +99,7 @@ struct TG_USER : public MZeroedObject int64_t id, chatId = -1; MCONTACT hContact; + int folderId = -1; bool isGroupChat, isBot, isForum, bLoadMembers, bStartChat, bInited; CMStringA szAvatarHash; CMStringW wszNick, wszFirstName, wszLastName; diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 12a2c6defe..828d8e19dd 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -625,19 +625,23 @@ void CTelegramProto::ProcessChatPosition(TD::updateChatPosition *pObj) wszGroup = TranslateT("Archive"); break; - case TD::chatListMain::ID: - wszGroup = TranslateT("Main"); + case TD::chatListMain::ID: // leave group empty + if (pUser->folderId != -1) + return; break; case TD::chatListFolder::ID: { - int iGroupId = ((TD::chatListFolder *)pList)->chat_folder_id_; - CMStringA szSetting(FORMAT, "ChatFilter%d", iGroupId); + int iFolderId = ((TD::chatListFolder *)pList)->chat_folder_id_; + CMStringA szSetting(FORMAT, "ChatFilter%d", iFolderId); wszGroup = getMStringW(szSetting); if (wszGroup.IsEmpty()) { - debugLogA("Empty group name for group #%d, ignored", iGroupId); + debugLogA("Empty group name for group #%d, ignored", iFolderId); return; } + if (wszGroup == "Unread") + return; + pUser->folderId = iFolderId; } break; @@ -648,13 +652,16 @@ void CTelegramProto::ProcessChatPosition(TD::updateChatPosition *pObj) MCONTACT hContact = GetRealContact(pUser); ptrW pwszExistingGroup(Clist_GetGroup(hContact)); - debugLogW(L"Existing contact group %s, calculated %s", pwszExistingGroup.get(), wszGroup.c_str()); + debugLogW(L"Existing contact group <%s>, calculated <%s>", pwszExistingGroup.get(), wszGroup.c_str()); - if (!pwszExistingGroup - || (!pUser->isGroupChat && !mir_wstrcmp(pwszExistingGroup, m_wszDefaultGroup)) + wchar_t *pwszDefaultGroup = m_wszDefaultGroup; + if (!pwszExistingGroup || pUser->isForum + || !mir_wstrncmp(pwszExistingGroup, pwszDefaultGroup, mir_wstrlen(pwszDefaultGroup)) || (pUser->isGroupChat && !mir_wstrcmp(pwszExistingGroup, ptrW(Chat_GetGroup())))) { - CMStringW wszNewGroup(FORMAT, L"%s\\%s", (wchar_t *)m_wszDefaultGroup, wszGroup.c_str()); + CMStringW wszNewGroup(pwszDefaultGroup); + if (!wszGroup.IsEmpty()) + wszNewGroup.AppendFormat(L"\\%s", wszGroup.c_str()); if (pUser->isForum) wszNewGroup.AppendFormat(L"\\%s", pUser->wszNick.c_str()); -- cgit v1.2.3