From f34b6e62e80f8dd1e8c20ba26665a17301e5fbb8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 11 Feb 2025 19:55:32 +0300 Subject: Telegram: offline thread messages always fall into the main thread --- protocols/Telegram/src/proto.cpp | 11 ++++++++++- protocols/Telegram/src/proto.h | 3 ++- protocols/Telegram/src/server.cpp | 1 + protocols/Telegram/src/utils.cpp | 19 +++++++++++++------ 4 files changed, 26 insertions(+), 8 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index d8d6f3a842..c4042f1d52 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -17,7 +17,10 @@ static int CompareRequests(const TG_REQUEST_BASE *p1, const TG_REQUEST_BASE *p2) } static int CompareChats(const TG_USER *p1, const TG_USER *p2) -{ return CompareId(p1->chatId, p2->chatId); +{ + if (p1->chatId != p2->chatId) + return CompareId(p1->chatId, p2->chatId); + return CompareId(p1->forumId, p2->forumId); } static int CompareUsers(const TG_USER *p1, const TG_USER *p2) @@ -125,6 +128,12 @@ void CTelegramProto::OnCacheInit() if (int64_t id = GetId(cc)) { bool isGroupChat = isChatRoom(cc); auto *pUser = new TG_USER(id, cc, isGroupChat); + if (auto iThreadId = GetId(cc, DBKEY_THREAD)) { + pUser->isForum = true; + pUser->chatId = pUser->id; + pUser->forumId = iThreadId; + m_arChats.insert(pUser); + } pUser->szAvatarHash = getMStringA(cc, DBKEY_AVATAR_HASH); m_arUsers.insert(pUser); if (isGroupChat && iCompatLevel < 3) diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 4040125506..d9a2e647b6 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -99,7 +99,7 @@ struct TG_USER : public MZeroedObject delete pReactions; } - int64_t id, chatId = -1; + int64_t id, chatId = -1, forumId = -1; MCONTACT hContact; int folderId = -1, nHistoryChunks, nTopics; bool isGroupChat, isChannel, isBot, isForum, bLoadMembers, bStartChat, bInited, bDelOwn = true, bDelAll = true; @@ -353,6 +353,7 @@ class CTelegramProto : public PROTO OBJLIST m_arUsers; TG_USER* FindChat(int64_t id); + TG_USER* FindChat(int64_t id, int64_t forumId); TG_USER* FindUser(int64_t id); TG_USER* AddUser(int64_t id, bool bIsChat); TG_USER* AddFakeUser(int64_t id, bool bIsChat); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 9e7974035f..e6d2c4c800 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -594,6 +594,7 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) } pUser->chatId = pChat->id_; + pUser->forumId = -1; pUser->isChannel = isChannel; pUser->bDelAll = pChat->can_be_deleted_for_all_users_; pUser->bDelOwn = pChat->can_be_deleted_only_for_self_; diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 4e8a22192e..b1f98bb3f0 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -234,12 +234,10 @@ int CTelegramProto::GetDefaultMute(const TG_USER *pUser) MCONTACT CTelegramProto::GetRealContact(const TG_USER *pUser, int64_t threadId) { - if (threadId) { - wchar_t buf[100]; - mir_snwprintf(buf, L"%lld_%lld", pUser->chatId, threadId); - if (auto *si = Chat_Find(buf, m_szModuleName)) - return si->hContact; - } + if (threadId) + if (auto *pu = FindChat(pUser->chatId, threadId)) + return pu->hContact; + return (pUser->hContact != 0) ? pUser->hContact : m_iSavedMessages; } @@ -330,6 +328,15 @@ TG_USER* CTelegramProto::FindChat(int64_t id) { auto *tmp = (TG_USER *)_alloca(sizeof(TG_USER)); tmp->chatId = id; + tmp->forumId = -1; + return m_arChats.find(tmp); +} + +TG_USER* CTelegramProto::FindChat(int64_t id, int64_t forumId) +{ + auto *tmp = (TG_USER *)_alloca(sizeof(TG_USER)); + tmp->chatId = id; + tmp->forumId = forumId; return m_arChats.find(tmp); } -- cgit v1.2.3