summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-14 18:48:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-14 18:48:50 +0300
commit357bb36c10405e7571f9ebd41d8e11837ebd6175 (patch)
treea1cd0dabe39ce913f7bf3356e47fc1d18363940e /src
parentf12d6a4000cfce521392200635d1cadc63dba934 (diff)
duplicate code removed
Diffstat (limited to 'src')
-rw-r--r--src/core/stdmsg/src/msgdialog.cpp10
-rw-r--r--src/core/stdmsg/src/msglog.cpp14
-rw-r--r--src/core/stdmsg/src/msgs.cpp13
-rw-r--r--src/core/stdmsg/src/msgs.h5
-rw-r--r--src/mir_app/src/chat_svc.cpp4
-rw-r--r--src/mir_app/src/db_events.cpp14
-rw-r--r--src/mir_app/src/mir_app.def2
-rw-r--r--src/mir_app/src/mir_app64.def2
8 files changed, 37 insertions, 27 deletions
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp
index cfeca501ef..ef28b8fd99 100644
--- a/src/core/stdmsg/src/msgdialog.cpp
+++ b/src/core/stdmsg/src/msgdialog.cpp
@@ -1209,14 +1209,14 @@ void CMsgDialog::DrawNickList(USERINFO *ui, DRAWITEMSTRUCT *dis)
/////////////////////////////////////////////////////////////////////////////////////////
-void CMsgDialog::EventAdded(MEVENT hDbEvent, const DBEVENTINFO &dbei)
+void CMsgDialog::EventAdded(MEVENT hDbEvent, const DB::EventInfo &dbei)
{
if (m_hDbEventFirst == 0)
m_hDbEventFirst = hDbEvent;
bool isMessage = (dbei.eventType == EVENTTYPE_MESSAGE), isSent = ((dbei.flags & DBEF_SENT) != 0);
bool isActive = IsActive();
- if (DbEventIsShown(&dbei)) {
+ if (DbEventIsShown(dbei)) {
// Sounds *only* for sent messages, not for custom events
if (isMessage && !isSent) {
if (isActive)
@@ -1255,10 +1255,10 @@ bool CMsgDialog::GetFirstEvent()
if (hPrevEvent == 0)
break;
- DBEVENTINFO dbei = {};
m_hDbEventFirst = hPrevEvent;
- db_event_get(hPrevEvent, &dbei);
- if (!DbEventIsShown(&dbei))
+
+ DB::EventInfo dbei(hPrevEvent, false);
+ if (!DbEventIsShown(dbei))
i++;
}
break;
diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp
index d9c7c5f69b..063c990114 100644
--- a/src/core/stdmsg/src/msglog.cpp
+++ b/src/core/stdmsg/src/msglog.cpp
@@ -189,15 +189,9 @@ static void SetToStyle(int style, CMStringA &dest)
dest.AppendFormat("\\f%u\\cf%u\\b%d\\i%d\\fs%u ", style, style, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / logPixelSY);
}
-bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei)
+bool DbEventIsShown(const DB::EventInfo &dbei)
{
- DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType);
- return et && (et->flags & DETF_MSGWINDOW);
-}
-
-bool DbEventIsShown(const DBEVENTINFO *dbei)
-{
- return dbei->eventType == EVENTTYPE_MESSAGE || dbei->eventType == EVENTTYPE_FILE || DbEventIsForMsgWindow(dbei);
+ return dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_FILE || dbei.isSrmm();
}
#define RTFPICTHEADERMAXSIZE 78
@@ -288,10 +282,10 @@ public:
if (!dbei)
return false;
- if (!DbEventIsShown(&dbei))
+ if (!DbEventIsShown(dbei))
return false;
- if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) {
+ 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);
}
diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp
index c7303ce01d..c0e216c262 100644
--- a/src/core/stdmsg/src/msgs.cpp
+++ b/src/core/stdmsg/src/msgs.cpp
@@ -70,11 +70,11 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDbEvent)
if (hContact == 0 || Contact::IsGroupChat(hContact))
return 0;
- DBEVENTINFO dbei = {};
- if (db_event_get(hDbEvent, &dbei))
+ DB::EventInfo dbei(hDbEvent, false);
+ if (!dbei)
return 0;
- if (dbei.flags & (DBEF_SENT | DBEF_READ) || !(dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei)))
+ if (dbei.markedRead() || !DbEventIsShown(dbei))
return 0;
bool bPopup = false;
@@ -265,12 +265,11 @@ static void RestoreUnreadMessageAlerts(void)
for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) {
bool autoPopup = false;
- DBEVENTINFO dbei = {};
- dbei.cbBlob = 0;
- if (db_event_get(hDbEvent, &dbei))
+ DB::EventInfo dbei(hDbEvent, false);
+ if (!dbei)
continue;
- if (!dbei.markedRead() && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) {
+ if (!dbei.markedRead() && DbEventIsShown(dbei)) {
int windowAlreadyExists = Srmm_FindWindow(hContact) != nullptr;
if (windowAlreadyExists)
continue;
diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h
index 2dc98a0e66..ce79ce26fa 100644
--- a/src/core/stdmsg/src/msgs.h
+++ b/src/core/stdmsg/src/msgs.h
@@ -138,7 +138,7 @@ public:
void CloseTab() override;
void DrawNickList(USERINFO *ui, DRAWITEMSTRUCT *dis) override;
- void EventAdded(MEVENT, const DBEVENTINFO &dbei) override;
+ void EventAdded(MEVENT, const DB::EventInfo &dbei) override;
bool GetFirstEvent() override;
bool IsActive() const override;
void LoadSettings() override;
@@ -158,8 +158,7 @@ extern LIST<CMsgDialog> g_arDialogs;
/////////////////////////////////////////////////////////////////////////////////////////
-bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei);
-bool DbEventIsShown(const DBEVENTINFO *dbei);
+bool DbEventIsShown(const DB::EventInfo &dbei);
int SendMessageDirect(const wchar_t *szMsg, MCONTACT hContact);
INT_PTR SendMessageCmd(MCONTACT hContact, wchar_t *msg);
diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp
index e1257c5ea2..0e590cdeb3 100644
--- a/src/mir_app/src/chat_svc.cpp
+++ b/src/mir_app/src/chat_svc.cpp
@@ -842,8 +842,8 @@ static int OnEventAdded(WPARAM hContact, LPARAM hDbEvent)
else {
g_clistApi.pfnRemoveEvent(hContact, 1);
- DBEVENTINFO dbei = {};
- if (!db_event_get(hDbEvent, &dbei)) {
+ DB::EventInfo dbei(hDbEvent, false);
+ if (dbei) {
if (auto *pDlg = Srmm_FindDialog(hContact))
pDlg->EventAdded(hDbEvent, dbei);
diff --git a/src/mir_app/src/db_events.cpp b/src/mir_app/src/db_events.cpp
index 29436c5f51..25b7cf0da8 100644
--- a/src/mir_app/src/db_events.cpp
+++ b/src/mir_app/src/db_events.cpp
@@ -273,6 +273,20 @@ DB::EventInfo::~EventInfo()
mir_free(pBlob);
}
+// could be displayed in a SRMM window
+bool DB::EventInfo::isSrmm() const
+{
+ auto *et = DbEvent_GetType(szModule, eventType);
+ return et && et->flags & DETF_MSGWINDOW;
+}
+
+// could be displayed in a history window
+bool DB::EventInfo::isHistory() const
+{
+ auto *et = DbEvent_GetType(szModule, eventType);
+ return et && et->flags & DETF_HISTORY;
+}
+
wchar_t* DB::EventInfo::getString(const char *str) const
{
if (flags & DBEF_UTF)
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 021694711d..6086dfd503 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -851,3 +851,5 @@ Chat_IsMuted @941 NONAME
?getString@EventInfo@DB@@QBEPA_WPBD@Z @967 NONAME
?InsertFileLink@CRtfLogWindow@@IAEXAAV?$CMStringT@DV?$ChTraitsCRT@D@@@@IABVFILE_BLOB@DB@@@Z @968 NONAME
?GetDialog@CSrmmLogWindow@@QBEAAVCMsgDialog@@XZ @969 NONAME
+?isHistory@EventInfo@DB@@QBE_NXZ @970 NONAME
+?isSrmm@EventInfo@DB@@QBE_NXZ @971 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index b888eb1a3b..678dd85842 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -851,3 +851,5 @@ Chat_IsMuted @941 NONAME
?getString@EventInfo@DB@@QEBAPEA_WPEBD@Z @967 NONAME
?InsertFileLink@CRtfLogWindow@@IEAAXAEAV?$CMStringT@DV?$ChTraitsCRT@D@@@@IAEBVFILE_BLOB@DB@@@Z @968 NONAME
?GetDialog@CSrmmLogWindow@@QEBAAEAVCMsgDialog@@XZ @969 NONAME
+?isHistory@EventInfo@DB@@QEBA_NXZ @970 NONAME
+?isSrmm@EventInfo@DB@@QEBA_NXZ @971 NONAME