diff options
author | George Hazan <ghazan@miranda.im> | 2023-03-15 12:17:54 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-03-15 12:17:54 +0300 |
commit | e4f25e2f1f5ecad84a8900b056be90d0c2ccf559 (patch) | |
tree | a4c1fc22a868a45c5b89be3acc2948c7d9ab124a /src | |
parent | 26a36b043f00d780fc9e8d27c7cad75082f0e960 (diff) |
HM_DBEVENTADDED message replaced with CMsgDialog::EventAdded method
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdmsg/src/globals.cpp | 17 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgdialog.cpp | 76 | ||||
-rw-r--r-- | src/core/stdmsg/src/msglog.cpp | 7 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgs.cpp | 7 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgs.h | 6 | ||||
-rw-r--r-- | src/mir_app/src/chat_svc.cpp | 17 |
6 files changed, 64 insertions, 66 deletions
diff --git a/src/core/stdmsg/src/globals.cpp b/src/core/stdmsg/src/globals.cpp index 5d2b95cc46..38ea6641d2 100644 --- a/src/core/stdmsg/src/globals.cpp +++ b/src/core/stdmsg/src/globals.cpp @@ -60,21 +60,6 @@ static int OnMetaChanged(WPARAM hMeta, LPARAM) return 0;
}
-static int dbaddedevent(WPARAM hContact, LPARAM hDbEvent)
-{
- if (hContact) {
- HWND h = Srmm_FindWindow(hContact);
- if (h)
- ::SendMessage(h, HM_DBEVENTADDED, hContact, hDbEvent);
-
- MCONTACT hEventContact = db_event_getContact(hDbEvent);
- if (hEventContact != hContact)
- if ((h = Srmm_FindWindow(hEventContact)) != nullptr)
- ::SendMessage(h, HM_DBEVENTADDED, hEventContact, hDbEvent);
- }
- return 0;
-}
-
static int ackevent(WPARAM, LPARAM lParam)
{
ACKDATA *pAck = (ACKDATA *)lParam;
@@ -105,8 +90,6 @@ void InitGlobals() g_plugin.delSetting("HideNames");
}
- HookEvent(ME_DB_EVENT_ADDED, dbaddedevent);
- HookEvent(ME_DB_EVENT_EDITED, dbaddedevent);
HookEvent(ME_PROTO_ACK, ackevent);
HookEvent(ME_SKIN_ICONSCHANGED, IconsChanged);
HookEvent(ME_AV_AVATARCHANGED, AvatarChanged);
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index aebdb9ee81..5e42c9f18a 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -587,46 +587,6 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) }
return TRUE;
- case HM_DBEVENTADDED:
- if (wParam == m_hContact && !isChat()) {
- MEVENT hDbEvent = lParam;
- if (m_hDbEventFirst == 0)
- m_hDbEventFirst = hDbEvent;
-
- DBEVENTINFO dbei = {};
- db_event_get(hDbEvent, &dbei);
- bool isMessage = (dbei.eventType == EVENTTYPE_MESSAGE), isSent = ((dbei.flags & DBEF_SENT) != 0);
- bool isActive = IsActive();
- if (DbEventIsShown(&dbei)) {
- // Sounds *only* for sent messages, not for custom events
- if (isMessage && !isSent) {
- if (isActive)
- Skin_PlaySound("RecvMsgActive");
- else
- Skin_PlaySound("RecvMsgInactive");
- }
- if (isMessage && !isSent) {
- m_lastMessage = dbei.timestamp;
- UpdateLastMessage();
- }
-
- if (hDbEvent != m_hDbEventFirst && db_event_next(m_hContact, hDbEvent) == 0)
- m_pLog->LogEvents(hDbEvent, 1, 1);
- else
- RemakeLog();
-
- // Flash window *only* for messages, not for custom events
- if (isMessage && !isSent) {
- if (isActive) {
- if (m_pLog->AtBottom())
- StartFlash();
- }
- else StartFlash();
- }
- }
- }
- break;
-
case WM_TIMECHANGE:
PostMessage(m_hwnd, DM_NEWTIMEZONE, 0, 0);
RemakeLog();
@@ -1295,6 +1255,42 @@ void CMsgDialog::CloseTab() else SendMessage(m_hwndParent, WM_CLOSE, 0, 0);
}
+void CMsgDialog::EventAdded(MEVENT hDbEvent, const DBEVENTINFO &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)) {
+ // Sounds *only* for sent messages, not for custom events
+ if (isMessage && !isSent) {
+ if (isActive)
+ Skin_PlaySound("RecvMsgActive");
+ else
+ Skin_PlaySound("RecvMsgInactive");
+ }
+ if (isMessage && !isSent) {
+ m_lastMessage = dbei.timestamp;
+ UpdateLastMessage();
+ }
+
+ if (hDbEvent != m_hDbEventFirst && db_event_next(m_hContact, hDbEvent) == 0)
+ m_pLog->LogEvents(hDbEvent, 1, 1);
+ else
+ RemakeLog();
+
+ // Flash window *only* for messages, not for custom events
+ if (isMessage && !isSent) {
+ if (isActive) {
+ if (m_pLog->AtBottom())
+ StartFlash();
+ }
+ else StartFlash();
+ }
+ }
+}
+
bool CMsgDialog::GetFirstEvent()
{
// This finds the first message to display, it works like shit
diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 7dddbcd10f..f97f361bb6 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -187,18 +187,17 @@ 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);
}
-int DbEventIsForMsgWindow(DBEVENTINFO *dbei)
+bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei)
{
DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType);
return et && (et->flags & DETF_MSGWINDOW);
}
-int DbEventIsShown(DBEVENTINFO *dbei)
+bool DbEventIsShown(const DBEVENTINFO *dbei)
{
- return (dbei->eventType==EVENTTYPE_MESSAGE) || DbEventIsForMsgWindow(dbei);
+ return (dbei->eventType == EVENTTYPE_MESSAGE) || DbEventIsForMsgWindow(dbei);
}
-//mir_free() the return value
static bool CreateRTFFromDbEvent(LogStreamData *dat)
{
DB::EventInfo dbei;
diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index 066875a243..121856ce37 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -67,13 +67,16 @@ static int SRMMStatusToPf2(int status) static int MessageEventAdded(WPARAM hContact, LPARAM lParam)
{
+ if (hContact == 0 || Contact::IsGroupChat(hContact))
+ return 0;
+
DBEVENTINFO dbei = {};
- db_event_get(lParam, &dbei);
+ if (db_event_get(lParam, &dbei))
+ return 0;
if (dbei.flags & (DBEF_SENT | DBEF_READ) || !(dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei)))
return 0;
- g_clistApi.pfnRemoveEvent(hContact, 1);
/* does a window for the contact exist? */
HWND hwnd = Srmm_FindWindow(hContact);
if (hwnd) {
diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index 8234296277..2087c094ba 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SRMM_MSGS_H
#define SRMM_MSGS_H
-#define HM_DBEVENTADDED (WM_USER+12)
#define DM_OPTIONSAPPLIED (WM_USER+14)
#define DM_UPDATETITLE (WM_USER+16)
#define DM_NEWTIMEZONE (WM_USER+18)
@@ -153,6 +152,7 @@ public: }
void CloseTab() override;
+ void EventAdded(MEVENT, const DBEVENTINFO &dbei) override;
bool GetFirstEvent() override;
bool IsActive() const override;
void LoadSettings() override;
@@ -171,8 +171,8 @@ extern LIST<CMsgDialog> g_arDialogs; /////////////////////////////////////////////////////////////////////////////////////////
-int DbEventIsForMsgWindow(DBEVENTINFO *dbei);
-int DbEventIsShown(DBEVENTINFO *dbei);
+bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei);
+bool DbEventIsShown(const DBEVENTINFO *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 d893a2c754..9e6a89ea3f 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -802,6 +802,9 @@ static INT_PTR LeaveChat(WPARAM hContact, LPARAM) static int OnEventAdded(WPARAM hContact, LPARAM hDbEvent)
{
+ if (hContact == 0)
+ return 0;
+
if (Contact::IsGroupChat(hContact)) {
if (auto *si = SM_FindSessionByContact(hContact)) {
DB::EventInfo dbei;
@@ -822,6 +825,20 @@ static int OnEventAdded(WPARAM hContact, LPARAM hDbEvent) }
}
}
+ else {
+ g_clistApi.pfnRemoveEvent(hContact, 1);
+
+ DBEVENTINFO dbei = {};
+ if (!db_event_get(hDbEvent, &dbei)) {
+ if (auto *pDlg = Srmm_FindDialog(hContact))
+ pDlg->EventAdded(hDbEvent, dbei);
+
+ MCONTACT hRealContact = db_event_getContact(hDbEvent);
+ if (hRealContact != hContact)
+ if (auto *pDlg = Srmm_FindDialog(hRealContact))
+ pDlg->EventAdded(hDbEvent, dbei);
+ }
+ }
return 0;
}
|