diff options
author | George Hazan <george.hazan@gmail.com> | 2025-02-11 19:55:32 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2025-02-11 19:55:32 +0300 |
commit | f34b6e62e80f8dd1e8c20ba26665a17301e5fbb8 (patch) | |
tree | 6e8884a4951a7e644630a2047f0008aa16c44332 | |
parent | 924e1a992d88c3f0f2a7cc25b83a8b94c58329b6 (diff) |
Telegram: offline thread messages always fall into the main thread
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 11 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 3 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 1 | ||||
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 19 |
4 files changed, 26 insertions, 8 deletions
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<CTelegramProto> OBJLIST<TG_USER> 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);
}
|