From f04b54e3fc162d475e8688784631a316f264f733 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 21 May 2023 14:56:39 +0300 Subject: Clist_RemoveEvent became static, pfnRemoveEvent is replaced with pfnFreeEvent --- src/core/stdfile/src/file.cpp | 2 +- src/core/stdmsg/src/msgdialog.cpp | 2 +- src/core/stdmsg/src/msgs.cpp | 2 +- src/core/stdmsg/src/tabs.cpp | 2 +- src/core/stduseronline/src/useronline.cpp | 2 +- src/mir_app/src/chat_log.cpp | 2 +- src/mir_app/src/chat_manager.cpp | 2 +- src/mir_app/src/chat_svc.cpp | 2 +- src/mir_app/src/chat_tools.cpp | 4 +-- src/mir_app/src/clc.h | 2 +- src/mir_app/src/clistcore.cpp | 2 +- src/mir_app/src/clistevents.cpp | 51 +++++++++++++++++++------------ src/mir_app/src/clistsettings.cpp | 2 +- src/mir_app/src/mir_app.def | 2 ++ src/mir_app/src/mir_app64.def | 2 ++ src/mir_app/src/srmm_log_rtf.cpp | 2 +- 16 files changed, 50 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp index 20e9ba44a9..c25d04eed1 100644 --- a/src/core/stdfile/src/file.cpp +++ b/src/core/stdfile/src/file.cpp @@ -268,7 +268,7 @@ static int SRFileProtoAck(WPARAM, LPARAM lParam) int iEvent = 0; while (auto *cle = Clist_GetEvent(ack->hContact, iEvent++)) if (cle->lParam == (LPARAM)ack->hProcess) - g_clistApi.pfnRemoveEvent(ack->hContact, cle->hDbEvent); + Clist_RemoveEvent(ack->hContact, cle->hDbEvent); } return 0; } diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 63fde09620..a13c704257 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -273,7 +273,7 @@ void CMsgDialog::OnActivate() if (db_get_w(m_hContact, m_si->pszModule, "ApparentMode", 0) != 0) db_set_w(m_hContact, m_si->pszModule, "ApparentMode", 0); if (Clist_GetEvent(m_hContact, 0)) - g_clistApi.pfnRemoveEvent(m_hContact, GC_FAKE_EVENT); + Clist_RemoveEvent(m_hContact, GC_FAKE_EVENT); } else { SetupStatusBar(); diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index 88cf6f656a..eab4269b80 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -195,7 +195,7 @@ static int TypingMessage(WPARAM hContact, LPARAM lParam) mir_snwprintf(szTip, TranslateT("%s is typing a message"), Clist_GetContactDisplayName(hContact)); if (g_plugin.bShowTypingClist) { - g_clistApi.pfnRemoveEvent(hContact, 1); + Clist_RemoveEvent(hContact, 1); CLISTEVENT cle = {}; cle.hContact = hContact; diff --git a/src/core/stdmsg/src/tabs.cpp b/src/core/stdmsg/src/tabs.cpp index e6a5d34e93..668050a8a2 100644 --- a/src/core/stdmsg/src/tabs.cpp +++ b/src/core/stdmsg/src/tabs.cpp @@ -477,7 +477,7 @@ void CTabbedWindow::TabClicked() si->wState &= ~GC_EVENT_HIGHLIGHT; if (Clist_GetEvent(si->hContact, 0)) - g_clistApi.pfnRemoveEvent(si->hContact, GC_FAKE_EVENT); + Clist_RemoveEvent(si->hContact, GC_FAKE_EVENT); } if (!si->pDlg) { diff --git a/src/core/stduseronline/src/useronline.cpp b/src/core/stduseronline/src/useronline.cpp index be50bf3165..b9e4b15878 100644 --- a/src/core/stduseronline/src/useronline.cpp +++ b/src/core/stduseronline/src/useronline.cpp @@ -41,7 +41,7 @@ static int UserOnlineSettingChanged(WPARAM hContact, LPARAM lParam) // Remove the event from the queue if it exists since they are now offline MEVENT lastEvent = g_plugin.getDword(hContact, "LastEvent"); if (lastEvent) { - g_clistApi.pfnRemoveEvent(hContact, lastEvent); + Clist_RemoveEvent(hContact, lastEvent); g_plugin.setDword(hContact, "LastEvent", 0); } } diff --git a/src/mir_app/src/chat_log.cpp b/src/mir_app/src/chat_log.cpp index 425f80753e..91895d3046 100644 --- a/src/mir_app/src/chat_log.cpp +++ b/src/mir_app/src/chat_log.cpp @@ -321,7 +321,7 @@ void CRtfLogWindow::CreateChatRtfMessage(RtfChatLogStreamData *streamData, const if (!dbei.markedRead()) { if (dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_FILE || dbei.isSrmm()) { db_event_markRead(si->hContact, lin.hEvent); - g_clistApi.pfnRemoveEvent(si->hContact, lin.hEvent); + Clist_RemoveEvent(si->hContact, lin.hEvent); } } diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 394f0d16e7..b0c4999d89 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -114,7 +114,7 @@ static SESSION_INFO* SM_CreateSession(void) void SM_FreeSession(SESSION_INFO *si) { if (Clist_GetEvent(si->hContact, 0)) - g_clistApi.pfnRemoveEvent(si->hContact, GC_FAKE_EVENT); + Clist_RemoveEvent(si->hContact, GC_FAKE_EVENT); si->wState &= ~STATE_TALK; db_set_w(si->hContact, si->pszModule, "ApparentMode", 0); diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index fc6e001881..e03d826320 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -823,7 +823,7 @@ static int OnEventAdded(WPARAM hContact, LPARAM hDbEvent) Chat_EventToGC(si, hDbEvent); } else { - g_clistApi.pfnRemoveEvent(hContact, 1); + Clist_RemoveEvent(hContact, 1); DB::EventInfo dbei(hDbEvent, false); if (dbei) { diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index cbe06d3d77..e2b4865e12 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -137,7 +137,7 @@ static void AddEvent(MCONTACT hContact, HICON hIcon, int type, const wchar_t *pw } else { if (Clist_GetEvent(hContact, 0)) - g_clistApi.pfnRemoveEvent(hContact, GC_FAKE_EVENT); + Clist_RemoveEvent(hContact, GC_FAKE_EVENT); g_clistApi.pfnAddEvent(&cle); } } @@ -229,7 +229,7 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA SESSION_INFO *si = (SESSION_INFO*)PUGetPluginData(hWnd); if (si->hContact) if (Clist_GetEvent(si->hContact, 0)) - g_clistApi.pfnRemoveEvent(si->hContact, GC_FAKE_EVENT); + Clist_RemoveEvent(si->hContact, GC_FAKE_EVENT); if (si->pDlg && si->pDlg->timerFlash.Stop()) FlashWindow(si->pDlg->GetHwnd(), FALSE); diff --git a/src/mir_app/src/clc.h b/src/mir_app/src/clc.h index 6a38b78e9f..39425f98a6 100644 --- a/src/mir_app/src/clc.h +++ b/src/mir_app/src/clc.h @@ -121,7 +121,7 @@ void UnregisterFileDropping(HWND hwnd); struct CListEvent* fnAddEvent(CLISTEVENT *cle); int fnGetImlIconIndex(HICON hIcon); -int fnRemoveEvent(MCONTACT hContact, MEVENT dbEvent); +int fnRemoveEvent(CListEvent *pEvent); int EventsProcessContactDoubleClick(MCONTACT hContact); diff --git a/src/mir_app/src/clistcore.cpp b/src/mir_app/src/clistcore.cpp index dcb1b64045..dfcc6e81e4 100644 --- a/src/mir_app/src/clistcore.cpp +++ b/src/mir_app/src/clistcore.cpp @@ -101,7 +101,7 @@ void InitClistCore() g_clistApi.pfnAddEvent = fnAddEvent; g_clistApi.pfnGetImlIconIndex = fnGetImlIconIndex; - g_clistApi.pfnRemoveEvent = fnRemoveEvent; + g_clistApi.pfnFreeEvent = fnRemoveEvent; g_clistApi.pfnInvalidateDisplayNameCacheEntry = fnInvalidateDisplayNameCacheEntry; g_clistApi.pfnCreateCacheItem = fnCreateCacheItem; diff --git a/src/mir_app/src/clistevents.cpp b/src/mir_app/src/clistevents.cpp index 51185c681f..1bf064b467 100644 --- a/src/mir_app/src/clistevents.cpp +++ b/src/mir_app/src/clistevents.cpp @@ -146,7 +146,7 @@ static VOID CALLBACK IconFlashTimer(HWND, UINT, UINT_PTR idEvent, DWORD) // decrease eflashes in any case - no need to collect all events if (e.flags & CLEF_ONLYAFEW) if (0 >= --e.flashesDone) - g_clistApi.pfnRemoveEvent(e.hContact, e.hDbEvent); + Clist_RemoveEvent(e.hContact, e.hDbEvent); } if (g_cliEvents.getCount() == 0) { @@ -194,24 +194,14 @@ CListEvent* fnAddEvent(CLISTEVENT *cle) // Removes an event from the contact list's queue // Returns 0 if the event was successfully removed, or nonzero if the event was not found -int fnRemoveEvent(MCONTACT hContact, MEVENT dbEvent) +int fnRemoveEvent(CListEvent *pEvent) { - // Find the event that should be removed - CListEvent *pEvent = nullptr; - for (auto &it : g_cliEvents) { - if (it->hContact == hContact && it->hDbEvent == dbEvent) { - pEvent = it; - break; - } - } - - // Event was not found - if (pEvent == nullptr) - return 1; + // save hContact, because pEvent should be freed + auto hContact = pEvent->hContact; // Update contact's icon char *szProto = Proto_GetBaseAccountName(hContact); - Clist_ChangeContactIcon(pEvent->hContact, Clist_GetContactIcon(pEvent->hContact)); + Clist_ChangeContactIcon(hContact, Clist_GetContactIcon(hContact)); // Free any memory allocated to the event g_cliEvents.remove(pEvent); @@ -242,6 +232,30 @@ int fnRemoveEvent(MCONTACT hContact, MEVENT dbEvent) ///////////////////////////////////////////////////////////////////////////////////////// +MIR_APP_DLL(CListEvent *) Clist_FindEvent(MCONTACT hContact, MEVENT hDbEvent) +{ + for (auto &it : g_cliEvents) { + if ((hContact == it->hContact || hContact == -1) && it->hDbEvent == hDbEvent) + return it; + } + + return nullptr; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Clist_RemoveEvent(MCONTACT hContact, MEVENT hDbEvent) +{ + if (auto *pEvent = Clist_FindEvent(hContact, hDbEvent)) { + g_clistApi.pfnFreeEvent(pEvent); + return 0; + } + + return 1; +} + +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(CListEvent *) Clist_GetEvent(MCONTACT hContact, int idx) { if (hContact == INVALID_CONTACT_ID) { @@ -264,9 +278,8 @@ int EventsProcessContactDoubleClick(MCONTACT hContact) { for (auto &it : g_cliEvents) { if (it->hContact == hContact) { - MEVENT hDbEvent = it->hDbEvent; CallService(it->pszService, 0, (LPARAM)it); - g_clistApi.pfnRemoveEvent(hContact, hDbEvent); + g_clistApi.pfnFreeEvent(it); return 0; } } @@ -338,7 +351,7 @@ MIR_APP_DLL(int) Clist_EventsProcessTrayDoubleClick(int index) MCONTACT hContact = pEvent->hContact; MEVENT hDbEvent = pEvent->hDbEvent; CallService(pEvent->pszService, 0, (LPARAM)pEvent); - g_clistApi.pfnRemoveEvent(hContact, hDbEvent); + Clist_RemoveEvent(hContact, hDbEvent); return 0; } @@ -347,7 +360,7 @@ MIR_APP_DLL(int) Clist_EventsProcessTrayDoubleClick(int index) static int CListEventMarkedRead(WPARAM hContact, LPARAM hDbEvent) { - g_clistApi.pfnRemoveEvent(hContact, hDbEvent); + Clist_RemoveEvent(hContact, hDbEvent); return 0; } diff --git a/src/mir_app/src/clistsettings.cpp b/src/mir_app/src/clistsettings.cpp index 4d3e60b9d4..b19de6d6a9 100644 --- a/src/mir_app/src/clistsettings.cpp +++ b/src/mir_app/src/clistsettings.cpp @@ -161,7 +161,7 @@ int ContactDeleted(WPARAM hContact, LPARAM) // remove events for a contact for (auto &it : g_cliEvents.rev_iter()) if (it->hContact == hContact) - g_clistApi.pfnRemoveEvent(hContact, it->hDbEvent); + Clist_RemoveEvent(hContact, it->hDbEvent); Chat_RemoveContact(hContact); return 0; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 4dba25cc4d..02620ec096 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -870,3 +870,5 @@ Chat_IsMuted @941 NONAME ?setSize@FILE_BLOB@DB@@QAEX_J@Z @985 NONAME ?setUrl@FILE_BLOB@DB@@QAEXPBD@Z @986 NONAME ?Clist_GetEvent@@YGPAUCListEvent@@IH@Z @987 NONAME +?Clist_FindEvent@@YGPAUCListEvent@@II@Z @988 NONAME +Clist_RemoveEvent @989 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 6c56bbbffa..f6b294699f 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -870,3 +870,5 @@ Chat_IsMuted @941 NONAME ?setSize@FILE_BLOB@DB@@QEAAX_J@Z @985 NONAME ?setUrl@FILE_BLOB@DB@@QEAAXPEBD@Z @986 NONAME ?Clist_GetEvent@@YAPEAUCListEvent@@IH@Z @987 NONAME +?Clist_FindEvent@@YAPEAUCListEvent@@II@Z @988 NONAME +Clist_RemoveEvent @989 diff --git a/src/mir_app/src/srmm_log_rtf.cpp b/src/mir_app/src/srmm_log_rtf.cpp index ccd1480ba3..7c40253003 100644 --- a/src/mir_app/src/srmm_log_rtf.cpp +++ b/src/mir_app/src/srmm_log_rtf.cpp @@ -296,7 +296,7 @@ static bool CreateRtfFromDbEvent(RtfLogStreamData *dat) if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || dbei.isSrmm())) { db_event_markRead(dat->hContact, dat->hDbEvent); - g_clistApi.pfnRemoveEvent(dat->hContact, dat->hDbEvent); + Clist_RemoveEvent(dat->hContact, dat->hDbEvent); } else if (dbei.eventType == EVENTTYPE_JABBER_CHATSTATES || dbei.eventType == EVENTTYPE_JABBER_PRESENCE) { db_event_markRead(dat->hContact, dat->hDbEvent); -- cgit v1.2.3