summaryrefslogtreecommitdiff
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
parent46e67c5053479beafce3716ec8be4f7e997e7fc9 (diff)
fixes #4733 (NewStory: отметки о прочтении пропадают при переоткрытии окна)
-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
-rw-r--r--protocols/Telegram/src/main.cpp1
-rw-r--r--protocols/Telegram/src/proto.cpp19
-rw-r--r--protocols/Telegram/src/proto.h1
-rw-r--r--protocols/Telegram/src/server.cpp13
-rw-r--r--protocols/Telegram/src/stdafx.h2
8 files changed, 75 insertions, 46 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();
diff --git a/protocols/Telegram/src/main.cpp b/protocols/Telegram/src/main.cpp
index a6b8ff67e8..3038e826b7 100644
--- a/protocols/Telegram/src/main.cpp
+++ b/protocols/Telegram/src/main.cpp
@@ -48,6 +48,7 @@ static IconItem iconList[] =
static int OnModuleLoaded(WPARAM, LPARAM)
{
+ g_plugin.hasNewStory = ServiceExists("NewStory/RemoteRead");
g_plugin.hasMessageState = ServiceExists(MS_MESSAGESTATE_UPDATE);
return 0;
}
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index 355d137256..17c8e04cb7 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -184,13 +184,18 @@ void CTelegramProto::OnShutdown()
int CTelegramProto::OnWindowEvent(WPARAM wParam, LPARAM lParam)
{
- if (wParam == MSG_WINDOW_EVT_OPENING) {
- auto *pDlg = (CMsgDialog *)lParam;
- if (Proto_IsProtoOnContact(pDlg->m_hContact, m_szModuleName))
- if (auto *pUser = FindUser(GetId(pDlg->m_hContact)))
- if (pUser->chatId == -1 && !pDlg->isChat())
- SendQuery(new TD::createPrivateChat(pUser->id, true));
- }
+ auto *pDlg = (CMsgDialog *)lParam;
+ if (!Proto_IsProtoOnContact(pDlg->m_hContact, m_szModuleName))
+ return 0;
+
+ auto *pUser = FindUser(GetId(pDlg->m_hContact));
+ if (pUser == nullptr)
+ return 0;
+
+ if (wParam == MSG_WINDOW_EVT_OPENING)
+ if (pUser->chatId == -1 && !pDlg->isChat())
+ SendQuery(new TD::createPrivateChat(pUser->id, true));
+
return 0;
}
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index 5801fb30dc..4d76651b48 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -5,6 +5,7 @@
#define DBKEY_OWNER "OwnerId"
#define DBKEY_THREAD "ThreadId"
#define DBKEY_AUTHORIZED "Authorized"
+#define DBKEY_REMOTE_READ "RemoteRead"
#define DBKEY_AVATAR_HASH "AvatarHash"
#define DBKEY_AVATAR_TYPE "AvatarType"
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 2d3062d700..681a4344be 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -1087,10 +1087,15 @@ void CTelegramProto::ProcessRemoteMarkRead(TD::updateChatReadOutbox *pObj)
CMStringA szMaxId(msg2id(pUser->chatId, pObj->last_read_outbox_message_id_));
MarkRead(pUser->hContact, szMaxId, true);
- CallService(MS_MESSAGESTATE_UPDATE, GetRealContact(pUser), MRD_TYPE_READ);
-
- if (auto hEvent = db_event_getById(m_szModuleName, szMaxId))
- NS_NotifyRemoteRead(GetRealContact(pUser), hEvent);
+ auto hContact = GetRealContact(pUser);
+ if (g_plugin.hasMessageState)
+ CallService(MS_MESSAGESTATE_UPDATE, hContact, MRD_TYPE_READ);
+
+ if (auto hEvent = db_event_getById(m_szModuleName, szMaxId)) {
+ setDword(hContact, DBKEY_REMOTE_READ, hEvent);
+ if (g_plugin.hasNewStory)
+ NS_NotifyRemoteRead(hContact, hEvent);
+ }
}
void CTelegramProto::ProcessScopeNotification(TD::updateScopeNotificationSettings *pObj)
diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h
index 11bfb43809..8b583a6cba 100644
--- a/protocols/Telegram/src/stdafx.h
+++ b/protocols/Telegram/src/stdafx.h
@@ -52,7 +52,7 @@ struct CMPlugin : public ACCPROTOPLUGIN<CTelegramProto>
{
CMPlugin();
- bool hasMessageState = false;
+ bool hasMessageState = false, hasNewStory = false;
HANDLE m_hIcon = 0;
int Load() override;