From 9e87a0d2f319f87d7edf65db8baba9dae1b8862b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 6 Mar 2024 12:51:38 +0300 Subject: fixes #4262 (NewStory: no nicks in Telegram chat history) --- plugins/NewStory/src/history_array.cpp | 32 +++++++++++++++++++++++++++----- plugins/NewStory/src/history_array.h | 1 + 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'plugins') diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 195cf55896..81a2477619 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -521,9 +521,7 @@ void HistoryArray::addChatEvent(SESSION_INFO *si, const LOGINFO *lin) if (si->pMI->bDatabase && lin->hEvent) { p.hEvent = lin->hEvent; - p.load(); - if (p.dbe.szUserId) - addNick(p, Utf2T(p.dbe.szUserId)); + checkGC(p, si); } else { CMStringW wszText; @@ -577,12 +575,20 @@ bool HistoryArray::addEvent(MCONTACT hContact, MEVENT hEvent, int count) int numItems = getCount(); auto *pPrev = (numItems == 0) ? nullptr : get(numItems - 1); + + SESSION_INFO *si = nullptr; + if (Contact::IsGroupChat(hContact)) + si = Chat_Find(hContact); if (count == 1) { auto &p = allocateItem(); p.hContact = hContact; p.hEvent = hEvent; - pPrev = p.checkPrev(pPrev, hwndOwner); + if (si) { + checkGC(p, si); + pPrev = p.checkPrevGC(pPrev, hwndOwner); + } + else pPrev = p.checkPrev(pPrev, hwndOwner); } else { DB::ECPTR pCursor(DB::Events(hContact, hEvent)); @@ -594,7 +600,11 @@ bool HistoryArray::addEvent(MCONTACT hContact, MEVENT hEvent, int count) auto &p = allocateItem(); p.hContact = hContact; p.hEvent = hEvent; - pPrev = p.checkPrev(pPrev, hwndOwner); + if (si) { + checkGC(p, si); + pPrev = p.checkPrevGC(pPrev, hwndOwner); + } + else pPrev = p.checkPrev(pPrev, hwndOwner); } } @@ -637,6 +647,18 @@ ItemData& HistoryArray::allocateItem() return p.data[iLastPageCounter++]; } +void HistoryArray::checkGC(ItemData &p, SESSION_INFO *si) +{ + p.load(); + if (p.dbe.szUserId) { + Utf2T wszUser(p.dbe.szUserId); + if (auto *pUser = g_chatApi.UM_FindUser(si, wszUser)) + addNick(p, pUser->pszNick); + else + addNick(p, wszUser); + } +} + int HistoryArray::find(MEVENT hEvent) { int i = 0; diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index 04c7be3cd4..04e7469b50 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -143,6 +143,7 @@ public: void addNick(ItemData &pItem, wchar_t *pwszNick); void clear(); + void checkGC(ItemData &pItem, SESSION_INFO *si); int find(MEVENT hEvent); int find(int id, int dir, const Filter &filter); int getCount() const; -- cgit v1.2.3