From ce18ece5cb16e75938a7277625c1f3d0635eead7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 17 Jul 2024 21:39:24 +0300 Subject: fixes #4543 completely --- plugins/NewStory/src/history_array.cpp | 41 ++++++++++++++++++++++++++++++---- plugins/NewStory/src/history_array.h | 1 + 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 0fa3433720..c78484dd7a 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -569,7 +569,8 @@ bool HistoryArray::addEvent(NewstoryListData *pOwner, MCONTACT hContact, MEVENT auto *pPrev = (numItems == 0) ? nullptr : get(numItems - 1); SESSION_INFO *si = nullptr; - if (Contact::IsGroupChat(hContact)) + bool isChat = Contact::IsGroupChat(hContact); + if (isChat) si = Chat_Find(hContact); if (count == 1) { @@ -577,7 +578,7 @@ bool HistoryArray::addEvent(NewstoryListData *pOwner, MCONTACT hContact, MEVENT p.pOwner = pOwner; p.hContact = hContact; p.dbe = hEvent; - if (si) { + if (isChat) { checkGC(p, si); pPrev = p.checkPrevGC(pPrev); } @@ -594,7 +595,7 @@ bool HistoryArray::addEvent(NewstoryListData *pOwner, MCONTACT hContact, MEVENT p.pOwner = pOwner; p.hContact = hContact; p.dbe = hEvent; - if (si) { + if (isChat) { checkGC(p, si); pPrev = p.checkPrevGC(pPrev); } @@ -649,8 +650,40 @@ void HistoryArray::checkGC(ItemData &p, SESSION_INFO *si) Utf2T wszUser(p.dbe.szUserId); if (auto *pUser = g_chatApi.UM_FindUser(si, wszUser)) addNick(p, pUser->pszNick); - else + else { + if (si == nullptr) { + MCONTACT hContact = INVALID_CONTACT_ID; + auto *szProto = Proto_GetBaseAccountName(p.hContact); + + if (gcCache.size() == 0) { + ptrW wszNick(Contact::GetInfo(CNF_UNIQUEID, 0, szProto)); + gcCache[wszNick.get()] = 0; + } + + auto pCache = gcCache.find(wszUser.get()); + if (pCache == gcCache.end()) { + for (auto &cc : Contacts(szProto)) { + ptrW wszId(Contact::GetInfo(CNF_UNIQUEID, cc)); + if (!mir_wstrcmp(wszId, wszUser)) { + gcCache[wszId.get()] = cc; + hContact = cc; + break; + } + } + } + else hContact = (*pCache).second; + + if (hContact != INVALID_CONTACT_ID) { + if (hContact == 0) + addNick(p, ptrW(Contact::GetInfo(CNF_DISPLAY, 0, szProto))); + else + addNick(p, Clist_GetContactDisplayName(hContact)); + return; + } + } + addNick(p, wszUser); + } } } diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index eb535c83b5..d56bc7fd2b 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -124,6 +124,7 @@ struct SearchResult class HistoryArray { + std::map gcCache; LIST strings; OBJLIST pages; int iLastPageCounter = 0; -- cgit v1.2.3