diff options
author | George Hazan <george.hazan@gmail.com> | 2023-08-23 17:51:31 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-08-23 17:51:31 +0300 |
commit | a07c815acbe342e6f5122c280ecbc0501688015e (patch) | |
tree | 6fa04fed6aa57fa18db53473d00df5b77dbc6b3f /plugins | |
parent | 96f4d0b60a1b019a18e7ebcc392b21628c77f602 (diff) |
fixes #3653 (NewStory: не работает группировка в чатах)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 55 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.h | 2 |
2 files changed, 49 insertions, 8 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index f6c2b13268..be26830325 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -60,15 +60,17 @@ ItemData::~ItemData() MTextDestroy(data); } -bool ItemData::isEqual(const ItemData *p) const +///////////////////////////////////////////////////////////////////////////////////////// + +static bool isEqual(const ItemData *p1, const ItemData *p2) { - if (p->hContact != hContact) + if (p1->hContact != p2->hContact) return false; - if (p->dbe.eventType != dbe.eventType) + if (p1->dbe.eventType != p2->dbe.eventType) return false; - if ((p->dbe.flags & DBEF_SENT) != (dbe.flags & DBEF_SENT)) + if ((p1->dbe.flags & DBEF_SENT) != (p2->dbe.flags & DBEF_SENT)) return false; - if (p->dbe.timestamp / 86400 != dbe.timestamp / 86400) + if (p1->dbe.timestamp / 86400 != p2->dbe.timestamp / 86400) return false; return true; } @@ -82,11 +84,46 @@ ItemData* ItemData::checkPrev(ItemData *pPrev) // we don't group anything but messages if (db_event_get(hEvent, &dbe)) return this; - + + if (dbe.eventType != EVENTTYPE_MESSAGE) + return this; + + if (isEqual(this, pPrev)) { + if (pPrev->m_grouping == GROUPING_NONE) { + pPrev->m_grouping = GROUPING_HEAD; + if (pPrev->m_bLoaded) + pPrev->setText(); + } + m_grouping = GROUPING_ITEM; + } + return this; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static bool isEqualGC(const ItemData *p1, const ItemData *p2) +{ + if (!p1->wszNick || !p2->wszNick) + return false; + + if (wcscmp(p1->wszNick, p2->wszNick)) + return false; + + if (p1->dbe.timestamp / 86400 != p2->dbe.timestamp / 86400) + return false; + return true; +} + +ItemData* ItemData::checkPrevGC(ItemData *pPrev) +{ + m_grouping = GROUPING_NONE; + if (!pPrev || !g_plugin.bMsgGrouping) + return this; + if (dbe.eventType != EVENTTYPE_MESSAGE) return this; - if (isEqual(pPrev)) { + if (isEqualGC(this, pPrev)) { if (pPrev->m_grouping == GROUPING_NONE) { pPrev->m_grouping = GROUPING_HEAD; if (pPrev->m_bLoaded) @@ -97,6 +134,8 @@ ItemData* ItemData::checkPrev(ItemData *pPrev) return this; } +///////////////////////////////////////////////////////////////////////////////////////// + void ItemData::checkCreate(HWND hwnd) { if (data == nullptr) { @@ -351,6 +390,7 @@ void HistoryArray::addChatEvent(SESSION_INFO *si, const LOGINFO *lin) wszText.Append(g_chatApi.RemoveFormatting(lin->ptszText)); } + int numItems = getCount(); auto &p = allocateItem(); p.hContact = si->hContact; p.wtext = wszText.Detach(); @@ -386,6 +426,7 @@ void HistoryArray::addChatEvent(SESSION_INFO *si, const LOGINFO *lin) p.wszNick = mir_wstrdup(lin->ptszNick); strings.insert(p.wszNick); } + p.checkPrevGC((numItems == 0) ? nullptr : get(numItems - 1)); } } diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index b38024f28a..bc1f15f19f 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -31,11 +31,11 @@ struct ItemData ~ItemData(); ItemData* checkPrev(ItemData *pPrev); + ItemData* checkPrevGC(ItemData *pPrev); void checkCreate(HWND hwnd); void setText(); void load(bool bFullLoad); - bool isEqual(const ItemData *p) const; bool isLink(POINT pt, CMStringW *url = nullptr) const; bool isLinkChar(int idx) const; |