From af546e2f55ccb9a270ce4967d1942aebfcbbea19 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 22 Dec 2023 17:55:36 +0300 Subject: DB::EventInfo::wipeNotify - useful helper to hide blinking event both from database & contact list --- include/m_database.h | 1 + libs/win32/mir_app.lib | Bin 276274 -> 276564 bytes libs/win64/mir_app.lib | Bin 275574 -> 275870 bytes plugins/IEView/src/HTMLBuilder.cpp | 6 ++---- plugins/NewStory/src/history_array.cpp | 7 ++----- plugins/TabSRMM/src/msglog.cpp | 7 ++----- protocols/Facebook/src/server.cpp | 7 +++---- protocols/JabberG/src/jabber_rc.cpp | 4 +--- protocols/VKontakte/src/misc.cpp | 5 +---- src/mir_app/src/chat_log.cpp | 8 +++----- src/mir_app/src/db_events.cpp | 10 ++++++++++ src/mir_app/src/file.cpp | 8 ++++---- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/srmm_log_rtf.cpp | 14 +++++++++----- 15 files changed, 40 insertions(+), 39 deletions(-) diff --git a/include/m_database.h b/include/m_database.h index 7362c7ead9..5d2d4ccab8 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -690,6 +690,7 @@ namespace DB bool fetch(MEVENT hEvent, bool bFetchBlob = true); void unload(); + void wipeNotify(MEVENT hEvent); __forceinline operator bool() const { return bValid; } diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index f919926783..f2af590140 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index 1c2d8e4c3a..0b3f8fe898 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp index 6a0f3a1d43..3c251572c4 100644 --- a/plugins/IEView/src/HTMLBuilder.cpp +++ b/plugins/IEView/src/HTMLBuilder.cpp @@ -204,10 +204,8 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) continue; } - if (!(dbei.flags & DBEF_SENT) && dbei.eventType == EVENTTYPE_MESSAGE) { - db_event_markRead(event->hContact, hDbEvent); - Clist_RemoveEvent(-1, hDbEvent); - } + if (dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_FILE) + dbei.wipeNotify(hDbEvent); if (!isDbEventShown(dbei)) { hDbEvent = db_event_next(event->hContact, hDbEvent); diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 3050e5af52..8ffa8c3106 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -469,11 +469,8 @@ void ItemData::load(int flags) void ItemData::markRead() { - if (!(dbe.flags & DBEF_SENT)) { - if (!dbe.markedRead()) - db_event_markRead(hContact, hEvent); - Clist_RemoveEvent(-1, hEvent); - } + if (!(dbe.flags & DBEF_SENT)) + dbe.wipeNotify(hEvent); } void ItemData::setText(HWND hwnd) diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index 352063b2dd..2ae3bd5186 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -570,11 +570,8 @@ bool CLogWindow::CreateRtfEvent(RtfLogStreamData *streamData, DB::EventInfo &dbe BOOL isSent = (dbei.flags & DBEF_SENT); BOOL bIsStatusChangeEvent = IsStatusEvent(dbei.eventType); - if (!isSent && bIsStatusChangeEvent) { - if (!dbei.markedRead()) - db_event_markRead(streamData->hContact, streamData->hDbEvent); - Clist_RemoveEvent(-1, streamData->hDbEvent); - } + if (!isSent && bIsStatusChangeEvent) + dbei.wipeNotify(streamData->hDbEvent); CMStringW msg(ptrW(DbEvent_GetTextW(&dbei, CP_UTF8))); if (msg.IsEmpty()) diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp index fcf1aacb2e..8601cd6db5 100644 --- a/protocols/Facebook/src/server.cpp +++ b/protocols/Facebook/src/server.cpp @@ -958,16 +958,15 @@ void FacebookProto::OnPublishReadReceipt(const JSONNode &root) uint32_t timestamp = _wtoi64(root["watermarkTimestampMs"].as_mstring()); for (MEVENT ev = db_event_firstUnread(pUser->hContact); ev != 0; ev = db_event_next(pUser->hContact, ev)) { - DBEVENTINFO dbei = {}; - if (db_event_get(ev, &dbei)) + DB::EventInfo dbei(ev); + if (!dbei) continue; if (dbei.timestamp > timestamp) break; if (dbei.flags & DBEF_SENT) - if (!dbei.markedRead()) - db_event_markRead(pUser->hContact, ev, true); + dbei.wipeNotify(ev); } } diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp index 75a7ffa3b8..bd49cf6adf 100644 --- a/protocols/JabberG/src/jabber_rc.cpp +++ b/protocols/JabberG/src/jabber_rc.cpp @@ -560,9 +560,7 @@ int CJabberProto::AdhocForwardHandler(const TiXmlElement*, CJabberIqInfo *pInfo, nEventsSent++; - db_event_markRead(hContact, hDbEvent, true); - if (bRemoveCListEvents) - Clist_RemoveEvent(hContact, hDbEvent); + dbei.wipeNotify(hDbEvent); } } diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 977e215386..6c5dcc8341 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -888,14 +888,11 @@ void CVkProto::MarkDialogAsRead(MCONTACT hContact) return; MEVENT hDBEvent = db_event_firstUnread(hContact); - MCONTACT hMContact = db_mc_tryMeta(hContact); while (hDBEvent != 0) { DBEVENTINFO dbei = {}; if (!db_event_get(hDBEvent, &dbei) && !mir_strcmp(m_szModuleName, dbei.szModule)) { db_event_markRead(hContact, hDBEvent, true); - Clist_RemoveEvent(hMContact, hDBEvent); - if (hContact != hMContact) - Clist_RemoveEvent(hContact, hDBEvent); + Clist_RemoveEvent(-1, hDBEvent); } hDBEvent = db_event_next(hContact, hDBEvent); diff --git a/src/mir_app/src/chat_log.cpp b/src/mir_app/src/chat_log.cpp index 8ef8ffca1e..830430b0d5 100644 --- a/src/mir_app/src/chat_log.cpp +++ b/src/mir_app/src/chat_log.cpp @@ -319,15 +319,13 @@ void CRtfLogWindow::CreateChatRtfMessage(RtfChatLogStreamData *streamData, const if (lin.hEvent) { DB::EventInfo dbei(lin.hEvent); if (dbei) { - if (dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_FILE || dbei.isSrmm()) { - if (!dbei.markedRead()) - db_event_markRead(si->hContact, lin.hEvent); - Clist_RemoveEvent(-1, lin.hEvent); - } + if (dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_FILE || dbei.isSrmm()) + dbei.wipeNotify(lin.hEvent); if (dbei.eventType == EVENTTYPE_FILE) { DB::FILE_BLOB blob(dbei); if (blob.isOffline()) { + dbei.wipeNotify(lin.hEvent); InsertFileLink(buf, lin.hEvent, blob); return; } diff --git a/src/mir_app/src/db_events.cpp b/src/mir_app/src/db_events.cpp index 78d00685ef..1fb1a25a12 100644 --- a/src/mir_app/src/db_events.cpp +++ b/src/mir_app/src/db_events.cpp @@ -287,6 +287,16 @@ void DB::EventInfo::unload() bValid = false; } +void DB::EventInfo::wipeNotify(MEVENT hEvent) +{ + if (!bValid) + return; + + if (!markedRead()) + db_event_markRead(hContact, hEvent); + Clist_RemoveEvent(-1, hEvent); +} + // could be displayed in a SRMM window bool DB::EventInfo::isSrmm() const { diff --git a/src/mir_app/src/file.cpp b/src/mir_app/src/file.cpp index 8fa9291276..ed674f402a 100644 --- a/src/mir_app/src/file.cpp +++ b/src/mir_app/src/file.cpp @@ -77,10 +77,10 @@ static void RemoveUnreadFileEvents(void) for (auto &hContact : Contacts()) { MEVENT hDbEvent = db_event_firstUnread(hContact); while (hDbEvent) { - DBEVENTINFO dbei = {}; - db_event_get(hDbEvent, &dbei); - if (!dbei.markedRead() && dbei.eventType == EVENTTYPE_FILE) - db_event_markRead(hContact, hDbEvent); + DB::EventInfo dbei(hDbEvent, false); + if (dbei.eventType == EVENTTYPE_FILE) + dbei.wipeNotify(hDbEvent); + hDbEvent = db_event_next(hContact, hDbEvent); } } diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 83ab5e5a8f..889d6acbf5 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -920,3 +920,4 @@ Clist_GroupSaveExpanded @1003 NONAME ?Send@File@@YGPAUHWND__@@IQAPA_W@Z @1038 NONAME ?GetReceivedFolder@File@@YGPA_WIPA_WI_N@Z @1039 NONAME ?DlgProc@CUserInfoPageDlg@@UAEHIIJ@Z @1040 NONAME +?wipeNotify@EventInfo@DB@@QAEXI@Z @1047 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index a768154279..6ec4da466d 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -920,3 +920,4 @@ Clist_GroupSaveExpanded @1003 NONAME ?Send@File@@YAPEAUHWND__@@IQEAPEA_W@Z @1038 NONAME ?GetReceivedFolder@File@@YAPEA_WIPEA_W_K_N@Z @1039 NONAME ?DlgProc@CUserInfoPageDlg@@UEAA_JI_K_J@Z @1040 NONAME +?wipeNotify@EventInfo@DB@@QEAAXI@Z @1041 NONAME diff --git a/src/mir_app/src/srmm_log_rtf.cpp b/src/mir_app/src/srmm_log_rtf.cpp index af3cd6426e..94174b7dce 100644 --- a/src/mir_app/src/srmm_log_rtf.cpp +++ b/src/mir_app/src/srmm_log_rtf.cpp @@ -327,10 +327,14 @@ static bool CreateRtfFromDbEvent(RtfLogStreamData *dat) if (!dat->pLog->CreateRtfEvent(dat, dbei)) return false; - if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || dbei.isSrmm())) { - if (!dbei.markedRead()) - db_event_markRead(dat->hContact, dat->hDbEvent); - Clist_RemoveEvent(-1, dat->hDbEvent); + if (!(dbei.flags & DBEF_SENT)) { + if (dbei.eventType == EVENTTYPE_MESSAGE || dbei.isSrmm()) + dbei.wipeNotify(dat->hDbEvent); + else if (dbei.eventType == EVENTTYPE_FILE) { + DB::FILE_BLOB blob(dbei); + if (blob.isOffline()) + dbei.wipeNotify(dat->hDbEvent); + } } else if (dbei.eventType == EVENTTYPE_JABBER_CHATSTATES || dbei.eventType == EVENTTYPE_JABBER_PRESENCE) { db_event_markRead(dat->hContact, dat->hDbEvent); @@ -620,7 +624,7 @@ INT_PTR CRtfLogWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) return 0; } - LRESULT res = mir_callNextSubclass(m_rtf.GetHwnd(), stubLogProc, msg, wParam, lParam); + LRESULT res = mir_callNextSubclass(m_rtf.GetHwnd(), stubLogProc, msg, wParam, lParam); if (msg == WM_GETDLGCODE) return res & ~DLGC_HASSETSEL; return res; -- cgit v1.2.3