From ec677fe11c84c09d10b3bbf7c7bca53ff105df22 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 9 Apr 2024 12:30:16 +0300 Subject: NewStory: control attempts to fetch events up even if the history is empty --- plugins/NewStory/src/history_control.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'plugins/NewStory/src') diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 669e5f40f3..43a0cf6e4a 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -930,17 +930,27 @@ void NewstoryListData::ToggleSelection(int iFirst, int iLast) void NewstoryListData::TryUp(int iCount) { - if (totalCount == 0) + MEVENT hTopEvent = 0; + MCONTACT hContact; + + if (totalCount != 0) { + auto *pTop = GetItem(0); + hContact = pTop->hContact; + hTopEvent = pTop->dbe.getEvent(); + if (hTopEvent == 0) + return; + } + else { + hContact = (pMsgDlg) ? pMsgDlg->m_hContact : 0; + hTopEvent = -1; + } + + if (hContact == 0) return; - auto *pTop = GetItem(0); - MCONTACT hContact = pTop->hContact; - if (pTop->dbe.getEvent() == 0 || hContact == 0) - return; - int i; for (i = 0; i < iCount; i++) { - MEVENT hPrev = db_event_prev(hContact, pTop->dbe.getEvent()); + MEVENT hPrev = (hTopEvent == -1) ? db_event_last(hContact) : db_event_prev(hContact, hTopEvent); if (hPrev == 0) break; @@ -952,10 +962,9 @@ void NewstoryListData::TryUp(int iCount) } ItemData *pPrev = nullptr; - for (int j = 0; j < i + 1; j++) { - auto *pItem = GetItem(j); - pPrev = pItem->checkNext(pPrev); - } + for (int j = 0; j < i + 1; j++) + if (auto *pItem = GetItem(j)) + pPrev = pItem->checkNext(pPrev); caret = 0; CalcBottom(); -- cgit v1.2.3