summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-10-16 17:20:43 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-10-16 17:20:43 +0300
commit33688bc55f818f5c0c1229605b407279e66b7499 (patch)
tree5a2f525f20c73219f5fe27a031a2036ba9ba1e23 /plugins
parent46e67c5053479beafce3716ec8be4f7e997e7fc9 (diff)
fixes #4733 (NewStory: отметки о прочтении пропадают при переоткрытии окна)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/NewStory/src/history_array.cpp38
-rw-r--r--plugins/NewStory/src/history_array.h2
-rw-r--r--plugins/NewStory/src/history_control.cpp45
3 files changed, 51 insertions, 34 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index b356038208..c510c0f7f8 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -559,7 +559,7 @@ void HistoryArray::addChatEvent(NewstoryListData *pOwner, SESSION_INFO *si, cons
}
}
-ItemData* HistoryArray::addEvent(NewstoryListData *pOwner, MCONTACT hContact, MEVENT hEvent, int count)
+void HistoryArray::addEvent(NewstoryListData *pOwner, MCONTACT hContact, MEVENT hEvent, int count, bool bNew)
{
if (count == -1)
count = MAXINT;
@@ -577,34 +577,32 @@ ItemData* HistoryArray::addEvent(NewstoryListData *pOwner, MCONTACT hContact, ME
p.pOwner = pOwner;
p.dbe.hContact = hContact;
p.dbe = hEvent;
+ p.m_bNew = bNew;
if (isChat) {
checkGC(p, si);
pPrev = p.checkPrevGC(pPrev);
}
else pPrev = p.checkPrev(pPrev);
- return &p;
}
+ else {
+ DB::ECPTR pCursor(DB::Events(hContact, hEvent));
+ for (int i = 0; i < count; i++) {
+ hEvent = pCursor.FetchNext();
+ if (!hEvent)
+ break;
- ItemData *pRet = nullptr;
- DB::ECPTR pCursor(DB::Events(hContact, hEvent));
- for (int i = 0; i < count; i++) {
- hEvent = pCursor.FetchNext();
- if (!hEvent)
- break;
-
- auto &p = allocateItem();
- p.pOwner = pOwner;
- p.dbe.hContact = hContact;
- p.dbe = hEvent;
- if (isChat) {
- checkGC(p, si);
- pPrev = p.checkPrevGC(pPrev);
+ auto &p = allocateItem();
+ p.pOwner = pOwner;
+ p.dbe.hContact = hContact;
+ p.dbe = hEvent;
+ p.m_bNew = bNew;
+ if (isChat) {
+ checkGC(p, si);
+ pPrev = p.checkPrevGC(pPrev);
+ }
+ else pPrev = p.checkPrev(pPrev);
}
- else pPrev = p.checkPrev(pPrev);
- pRet = &p;
}
-
- return pRet;
}
void HistoryArray::addNick(ItemData &pItem, wchar_t *pwszNick)
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index 9ac69b659d..f4794d6584 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -140,7 +140,7 @@ public:
HistoryArray();
~HistoryArray();
- ItemData* addEvent(NewstoryListData *pOwner, MCONTACT hContact, MEVENT hEvent, int count);
+ void addEvent(NewstoryListData *pOwner, MCONTACT hContact, MEVENT hEvent, int count, bool bNew = false);
void addChatEvent(NewstoryListData *pOwner, SESSION_INFO *si, const LOGINFO *pEvent);
void addResults(NewstoryListData *pOwner, const OBJLIST<SearchResult> &pArray);
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 9e7f7c0856..fb55dee379 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -132,9 +132,13 @@ void NewstoryListData::AddChatEvent(SESSION_INFO *si, const LOGINFO *lin)
void NewstoryListData::AddEvent(MCONTACT hContact, MEVENT hFirstEvent, int iCount, bool bNew)
{
ScheduleDraw();
- if (auto *p = items.addEvent(this, hContact, hFirstEvent, iCount))
- p->m_bNew = bNew;
+ items.addEvent(this, hContact, hFirstEvent, iCount, bNew);
totalCount = items.getCount();
+
+ if (iCount == -1)
+ if (auto *szProto = Proto_GetBaseAccountName(hContact))
+ if (auto hEvent = db_get_dw(hContact, szProto, "RemoteRead"))
+ RemoteRead(hContact, hEvent);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -438,17 +442,17 @@ void NewstoryListData::DeleteItems(void)
void NewstoryListData::DeliverEvent(MCONTACT hContact, MEVENT hEvent)
{
- bool isChanged = false;
+ bool isChanged = false, isActive = false;
- for (int i = 0; i < totalCount; i++) {
+ for (int i = totalCount - 1; i >= 0; i--) {
auto *pItem = GetItem(i);
if (pItem->dbe.hContact != hContact || !(pItem->dbe.flags & DBEF_SENT))
continue;
- if (pItem->dbe.getEvent() > hEvent)
- break;
+ if (pItem->dbe.getEvent() == hEvent)
+ isActive = true;
- if (pItem->m_bNew && !pItem->m_bDelivered) {
+ if (isActive && pItem->m_bNew && !pItem->m_bDelivered) {
pItem->m_bDelivered = true;
pItem->savedHeight = -1;
pItem->calcHeight(cachedWindowWidth);
@@ -917,17 +921,20 @@ void NewstoryListData::RecalcScrollBar()
void NewstoryListData::RemoteRead(MCONTACT hContact, MEVENT hEvent)
{
- bool isChanged = false;
+ bool isChanged = false, isActive = false;
- for (int i = 0; i < totalCount; i++) {
+ for (int i = totalCount-1; i >= 0; i--) {
auto *pItem = GetItem(i);
+ if (!pItem->m_bLoaded)
+ pItem->fetch();
+
if (pItem->dbe.hContact != hContact || !(pItem->dbe.flags & DBEF_SENT))
continue;
- if (pItem->dbe.getEvent() > hEvent)
- break;
+ if (pItem->dbe.getEvent() == hEvent)
+ isActive = true;
- if (pItem->m_bNew && !pItem->m_bRemoteRead) {
+ if (isActive && pItem->m_bNew && !pItem->m_bRemoteRead) {
pItem->m_bRemoteRead = true;
pItem->savedHeight = -1;
pItem->calcHeight(cachedWindowWidth);
@@ -1060,6 +1067,13 @@ void NewstoryListData::TryUp(int iCount)
if (hContact == 0)
return;
+ bool hasRead = false;
+ for (int i=0; i < totalCount; i++)
+ if (GetItem(i)->m_bRemoteRead) {
+ hasRead = true;
+ break;
+ }
+
int i;
for (i = 0; i < iCount; i++) {
MEVENT hPrev = (hTopEvent == -1) ? db_event_last(hContact) : db_event_prev(hContact, hTopEvent);
@@ -1070,13 +1084,18 @@ void NewstoryListData::TryUp(int iCount)
p->pOwner = this;
p->dbe.hContact = hContact;
p->dbe = hPrev;
+ p->m_bNew = true;
totalCount++;
}
ItemData *pPrev = nullptr;
for (int j = 0; j < i + 1; j++)
- if (auto *pItem = GetItem(j))
+ if (auto *pItem = GetItem(j)) {
+ pItem->fetch();
+ if (pItem->dbe.flags & DBEF_SENT)
+ pItem->m_bRemoteRead = hasRead;
pPrev = pItem->checkNext(pPrev);
+ }
caret = 0;
CalcBottom();