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 | |
parent | 26a36b043f00d780fc9e8d27c7cad75082f0e960 (diff) |
HM_DBEVENTADDED message replaced with CMsgDialog::EventAdded method
-rw-r--r-- | include/m_srmm_int.h | 1 | ||||
-rw-r--r-- | plugins/Scriver/src/msgdialog.cpp | 42 | ||||
-rw-r--r-- | plugins/Scriver/src/msglog.cpp | 6 | ||||
-rw-r--r-- | plugins/Scriver/src/msgs.cpp | 20 | ||||
-rw-r--r-- | plugins/Scriver/src/msgs.h | 8 | ||||
-rw-r--r-- | plugins/Scriver/src/msgutils.cpp | 39 | ||||
-rw-r--r-- | plugins/TabSRMM/src/functions.h | 5 | ||||
-rw-r--r-- | plugins/TabSRMM/src/generic_msghandlers.cpp | 109 | ||||
-rw-r--r-- | plugins/TabSRMM/src/globals.cpp | 3 | ||||
-rw-r--r-- | plugins/TabSRMM/src/mim.cpp | 27 | ||||
-rw-r--r-- | plugins/TabSRMM/src/mim.h | 1 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgdialog.cpp | 7 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgdlgother.cpp | 108 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msglog.cpp | 4 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.h | 5 | ||||
-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 |
21 files changed, 235 insertions, 280 deletions
diff --git a/include/m_srmm_int.h b/include/m_srmm_int.h index 876c31dbaf..2ba5f5cc00 100644 --- a/include/m_srmm_int.h +++ b/include/m_srmm_int.h @@ -248,6 +248,7 @@ public: virtual void AddLog();
virtual void CloseTab() {}
+ virtual void EventAdded(MEVENT, const DBEVENTINFO &dbei) PURE;
virtual bool GetFirstEvent() PURE;
virtual bool IsActive() const PURE;
virtual void LoadSettings() PURE;
diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 8f7a405723..78ab1229ee 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -1165,48 +1165,6 @@ INT_PTR CMsgDialog::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) InvalidateRect(m_pLog->GetHwnd(), nullptr, FALSE);
break;
- case HM_DBEVENTADDED:
- if (wParam == m_hContact && !isChat()) {
- MEVENT hDbEvent = lParam;
- DBEVENTINFO dbei = {};
- db_event_get(hDbEvent, &dbei);
- if (m_hDbEventFirst == 0)
- m_hDbEventFirst = hDbEvent;
- if (DbEventIsShown(dbei)) {
- bool bIsActive = IsActive();
- if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) {
- /* store the event when the container is hidden so that clist notifications can be removed */
- if (!IsWindowVisible(m_hwndParent) && m_hDbUnreadEventFirst == 0)
- m_hDbUnreadEventFirst = hDbEvent;
- m_lastMessage = dbei.timestamp;
- UpdateStatusBar();
- if (bIsActive)
- Skin_PlaySound("RecvMsgActive");
- else
- Skin_PlaySound("RecvMsgInactive");
- if (g_dat.flags2.bSwitchToActive && (IsIconic(m_hwndParent) || GetActiveWindow() != m_hwndParent) && IsWindowVisible(m_hwndParent))
- m_pParent->ActivateChild(this);
- if (IsAutoPopup(m_hContact))
- PopupWindow(true);
- }
-
- if (hDbEvent != m_hDbEventFirst && db_event_next(m_hContact, hDbEvent) == 0)
- m_pLog->LogEvents(hDbEvent, 1, 1);
- else
- SendMessage(m_hwnd, DM_REMAKELOG, 0, 0);
-
- if (!(dbei.flags & DBEF_SENT) && !DbEventIsCustomForMsgWindow(&dbei)) {
- if (!bIsActive) {
- m_iShowUnread = 1;
- UpdateIcon();
- SetTimer(m_hwnd, TIMERID_UNREAD, TIMEOUT_UNREAD, nullptr);
- }
- StartFlashing();
- }
- }
- }
- break;
-
case WM_TIMER:
if (wParam == TIMERID_MSGSEND)
ReportSendQueueTimeouts(this);
diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index 95c7269cd7..139fd3eef0 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -50,18 +50,18 @@ struct LogStreamData EventData *events;
};
-int DbEventIsCustomForMsgWindow(DBEVENTINFO *dbei)
+bool DbEventIsCustomForMsgWindow(const DBEVENTINFO *dbei)
{
DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType);
return et && (et->flags & DETF_MSGWINDOW);
}
-int DbEventIsMessageOrCustom(DBEVENTINFO* dbei)
+bool DbEventIsMessageOrCustom(const DBEVENTINFO* dbei)
{
return dbei->eventType == EVENTTYPE_MESSAGE || DbEventIsCustomForMsgWindow(dbei);
}
-int DbEventIsShown(DBEVENTINFO &dbei)
+bool DbEventIsShown(const DBEVENTINFO &dbei)
{
switch (dbei.eventType) {
case EVENTTYPE_MESSAGE:
diff --git a/plugins/Scriver/src/msgs.cpp b/plugins/Scriver/src/msgs.cpp index 01ffec8586..e939a1c69e 100644 --- a/plugins/Scriver/src/msgs.cpp +++ b/plugins/Scriver/src/msgs.cpp @@ -79,19 +79,14 @@ static INT_PTR ReadMessageCommand(WPARAM, LPARAM lParam) return 0;
}
-static int MessageEventAdded(WPARAM hContact, LPARAM lParam)
+static int MessageEventAdded(WPARAM hContact, LPARAM hDbEvent)
{
- MCONTACT hContactWnd;
- MEVENT hDbEvent = (MEVENT)lParam;
-
- HWND hwnd = Srmm_FindWindow(hContactWnd = hContact);
- if (hwnd == nullptr)
- hwnd = Srmm_FindWindow(hContactWnd = db_event_getContact(hDbEvent));
- if (hwnd)
- ::PostMessage(hwnd, HM_DBEVENTADDED, hContactWnd, lParam);
+ if (hContact == 0 || Contact::IsGroupChat(hContact))
+ return 0;
DBEVENTINFO dbei = {};
- db_event_get(hDbEvent, &dbei);
+ if (db_event_get(hDbEvent, &dbei))
+ return 0;
if (dbei.eventType == EVENTTYPE_MESSAGE && (dbei.flags & DBEF_READ))
return 0;
@@ -99,8 +94,11 @@ static int MessageEventAdded(WPARAM hContact, LPARAM lParam) if (dbei.flags & DBEF_SENT || !DbEventIsMessageOrCustom(&dbei))
return 0;
- g_clistApi.pfnRemoveEvent(hContact, 1);
/* does a window for the contact exist? */
+ HWND hwnd = Srmm_FindWindow(hContact);
+ if (hwnd == nullptr)
+ hwnd = Srmm_FindWindow(db_event_getContact(hDbEvent));
+
if (hwnd == nullptr) {
/* new message */
Skin_PlaySound("AlertMsg");
diff --git a/plugins/Scriver/src/msgs.h b/plugins/Scriver/src/msgs.h index 7b92e8ce24..30c228f101 100644 --- a/plugins/Scriver/src/msgs.h +++ b/plugins/Scriver/src/msgs.h @@ -172,6 +172,7 @@ public: void onType(CTimer *);
void CloseTab() override;
+ void EventAdded(MEVENT, const DBEVENTINFO &dbei) override;
bool GetFirstEvent() override;
void LoadSettings() override;
void SetStatusText(const wchar_t *, HICON) override;
@@ -217,7 +218,6 @@ public: void Reattach(HWND hwndContainer);
};
-#define HM_DBEVENTADDED (WM_USER+10)
#define HM_ACKEVENT (WM_USER+11)
#define DM_REMAKELOG (WM_USER+12)
@@ -235,9 +235,9 @@ public: #define EVENTTYPE_JABBER_CHATSTATES 2000
#define EVENTTYPE_JABBER_PRESENCE 2001
-int DbEventIsShown(DBEVENTINFO &dbei);
-int DbEventIsCustomForMsgWindow(DBEVENTINFO *dbei);
-int DbEventIsMessageOrCustom(DBEVENTINFO *dbei);
+bool DbEventIsShown(const DBEVENTINFO &dbei);
+bool DbEventIsCustomForMsgWindow(const DBEVENTINFO *dbei);
+bool DbEventIsMessageOrCustom(const DBEVENTINFO *dbei);
void LoadMsgLogIcons(void);
void FreeMsgLogIcons(void);
int IsAutoPopup(MCONTACT hContact);
diff --git a/plugins/Scriver/src/msgutils.cpp b/plugins/Scriver/src/msgutils.cpp index 01210cdcbd..4df469e568 100644 --- a/plugins/Scriver/src/msgutils.cpp +++ b/plugins/Scriver/src/msgutils.cpp @@ -36,6 +36,45 @@ void CMsgDialog::CloseTab() Close(); } +void CMsgDialog::EventAdded(MEVENT hDbEvent, const DBEVENTINFO &dbei) +{ + if (m_hDbEventFirst == 0) + m_hDbEventFirst = hDbEvent; + + if (DbEventIsShown(dbei)) { + bool bIsActive = IsActive(); + if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) { + /* store the event when the container is hidden so that clist notifications can be removed */ + if (!IsWindowVisible(m_hwndParent) && m_hDbUnreadEventFirst == 0) + m_hDbUnreadEventFirst = hDbEvent; + m_lastMessage = dbei.timestamp; + UpdateStatusBar(); + if (bIsActive) + Skin_PlaySound("RecvMsgActive"); + else + Skin_PlaySound("RecvMsgInactive"); + if (g_dat.flags2.bSwitchToActive && (IsIconic(m_hwndParent) || GetActiveWindow() != m_hwndParent) && IsWindowVisible(m_hwndParent)) + m_pParent->ActivateChild(this); + if (IsAutoPopup(m_hContact)) + PopupWindow(true); + } + + if (hDbEvent != m_hDbEventFirst && db_event_next(m_hContact, hDbEvent) == 0) + m_pLog->LogEvents(hDbEvent, 1, 1); + else + SendMessage(m_hwnd, DM_REMAKELOG, 0, 0); + + if (!(dbei.flags & DBEF_SENT) && !DbEventIsCustomForMsgWindow(&dbei)) { + if (!bIsActive) { + m_iShowUnread = 1; + UpdateIcon(); + SetTimer(m_hwnd, TIMERID_UNREAD, TIMEOUT_UNREAD, nullptr); + } + StartFlashing(); + } + } +} + bool CMsgDialog::GetFirstEvent() { bool notifyUnread = false; diff --git a/plugins/TabSRMM/src/functions.h b/plugins/TabSRMM/src/functions.h index dc0bb47c5f..e7311632d2 100644 --- a/plugins/TabSRMM/src/functions.h +++ b/plugins/TabSRMM/src/functions.h @@ -84,9 +84,8 @@ void TSAPI CacheMsgLogIcons(); void TSAPI CacheLogFonts();
void TSAPI LoadIconTheme();
-int DbEventIsForMsgWindow(DBEVENTINFO *dbei);
-
-int TSAPI DbEventIsShown(DBEVENTINFO *dbei);
+bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei);
+bool DbEventIsShown(const DBEVENTINFO *dbei);
// custom tab control
diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp index 91a8906c30..f69e6de35d 100644 --- a/plugins/TabSRMM/src/generic_msghandlers.cpp +++ b/plugins/TabSRMM/src/generic_msghandlers.cpp @@ -1034,115 +1034,6 @@ void CMsgDialog::DM_AddDivider() }
/////////////////////////////////////////////////////////////////////////////////////////
-// incoming event handler
-
-void CMsgDialog::DM_EventAdded(WPARAM, LPARAM lParam)
-{
- MEVENT hDbEvent = (MEVENT)lParam;
-
- DBEVENTINFO dbei = {};
- db_event_get(hDbEvent, &dbei);
- if (m_hDbEventFirst == 0)
- m_hDbEventFirst = hDbEvent;
-
- bool bIsStatusChangeEvent = IsStatusEvent(dbei.eventType);
- bool bDisableNotify = (dbei.eventType == EVENTTYPE_MESSAGE && (dbei.flags & DBEF_READ));
-
- if (!DbEventIsShown(&dbei))
- return;
-
- if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) {
- m_lastMessage = dbei.timestamp;
- m_wszStatusBar[0] = 0;
- if (m_bShowTyping) {
- m_nTypeSecs = 0;
- DM_Typing(true);
- m_bShowTyping = 0;
- }
- HandleIconFeedback(this, (HICON)-1);
- if (m_pContainer->m_hwndStatus)
- PostMessage(m_hwnd, DM_UPDATELASTMESSAGE, 0, 0);
- }
-
- // set the message log divider to mark new (maybe unseen) messages, if the container has
- // been minimized or in the background.
- if (!(dbei.flags & DBEF_SENT) && !bIsStatusChangeEvent) {
- if (g_plugin.bDividersUsePopupConfig && g_plugin.bUseDividers) {
- if (!MessageWindowOpened(m_hContact, nullptr))
- DM_AddDivider();
- }
- else if (g_plugin.bUseDividers) {
- if (!m_pContainer->IsActive())
- DM_AddDivider();
- else if (m_pContainer->m_hwndActive != m_hwnd)
- DM_AddDivider();
- }
-
- if (IsWindowVisible(m_pContainer->m_hwnd))
- m_pContainer->m_bHidden = false;
- }
- m_cache->updateStats(TSessionStats::UPDATE_WITH_LAST_RCV, 0);
-
- if (hDbEvent != m_hDbEventFirst)
- StreamEvents(hDbEvent, 1, 1);
- else
- RemakeLog();
-
- // handle tab flashing
- if (!bDisableNotify && !bIsStatusChangeEvent)
- if ((TabCtrl_GetCurSel(m_hwndParent) != m_iTabID) && !(dbei.flags & DBEF_SENT)) {
- switch (dbei.eventType) {
- case EVENTTYPE_MESSAGE:
- m_iFlashIcon = PluginConfig.g_IconMsgEvent;
- break;
- case EVENTTYPE_FILE:
- m_iFlashIcon = PluginConfig.g_IconFileEvent;
- break;
- default:
- m_iFlashIcon = PluginConfig.g_IconMsgEvent;
- break;
- }
- timerFlash.Start(TIMEOUT_FLASHWND);
- m_bCanFlashTab = true;
- }
-
- // try to flash the contact list...
- if (!bDisableNotify)
- FlashOnClist(hDbEvent, &dbei);
-
- // autoswitch tab if option is set AND container is minimized (otherwise, we never autoswitch)
- // never switch for status changes...
- if (!(dbei.flags & DBEF_SENT) && !bIsStatusChangeEvent) {
- if (g_plugin.bAutoSwitchTabs && m_pContainer->m_hwndActive != m_hwnd) {
- if ((IsIconic(m_pContainer->m_hwnd) && !IsZoomed(m_pContainer->m_hwnd)) || (g_plugin.bHideOnClose && !IsWindowVisible(m_pContainer->m_hwnd))) {
- int iItem = GetTabIndexFromHWND(GetParent(m_hwnd), m_hwnd);
- if (iItem >= 0) {
- TabCtrl_SetCurSel(m_hwndParent, iItem);
- ShowWindow(m_pContainer->m_hwndActive, SW_HIDE);
- m_pContainer->m_hwndActive = m_hwnd;
- m_pContainer->UpdateTitle(m_hContact);
- m_pContainer->cfg.flags.m_bDeferredTabSelect = true;
- }
- }
- }
- }
-
- // flash window if it is not focused
- if (!bDisableNotify && !bIsStatusChangeEvent)
- if (!IsActive() && !(dbei.flags & DBEF_SENT)) {
- if (!m_pContainer->cfg.flags.m_bNoFlash && !m_pContainer->IsActive())
- m_pContainer->FlashContainer(1, 0);
- m_pContainer->SetIcon(this, Skin_LoadIcon(SKINICON_EVENT_MESSAGE));
- m_pContainer->cfg.flags.m_bNeedsUpdateTitle = true;
- }
-
- // play a sound
- if (!bDisableNotify && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT)))
- PlayIncomingSound();
-
- if (m_pWnd)
- m_pWnd->Invalidate();
-}
void CMsgDialog::DM_HandleAutoSizeRequest(REQRESIZE* rr)
{
diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp index a80ff3f2b2..397e829dc1 100644 --- a/plugins/TabSRMM/src/globals.cpp +++ b/plugins/TabSRMM/src/globals.cpp @@ -265,10 +265,7 @@ int CGlobals::ModulesLoaded(WPARAM, LPARAM) HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged);
HookEvent(ME_DB_CONTACT_DELETED, DBContactDeleted);
- HookEvent(ME_DB_EVENT_ADDED, CMimAPI::DispatchNewEvent);
HookEvent(ME_DB_EVENT_ADDED, CMimAPI::MessageEventAdded);
-
- HookEvent(ME_DB_EVENT_EDITED, CMimAPI::DispatchNewEvent);
HookEvent(ME_DB_EVENT_EDITED, CMimAPI::MessageEventAdded);
HookEvent(ME_FONT_RELOAD, ::FontServiceFontsChanged);
diff --git a/plugins/TabSRMM/src/mim.cpp b/plugins/TabSRMM/src/mim.cpp index 9b776b88ab..7412bd0474 100644 --- a/plugins/TabSRMM/src/mim.cpp +++ b/plugins/TabSRMM/src/mim.cpp @@ -361,27 +361,6 @@ int CMimAPI::PrebuildContactMenu(WPARAM hContact, LPARAM) }
/////////////////////////////////////////////////////////////////////////////////////////
-// this handler is called first in the message window chain - it will handle events for which a message window
-// is already open. if not, it will do nothing and the 2nd handler(MessageEventAdded) will perform all
-// the needed actions.
-//
-// this handler POSTs the event to the message window procedure - so it is fast and can exit quickly which will
-// improve the overall responsiveness when receiving messages.
-
-int CMimAPI::DispatchNewEvent(WPARAM hContact, LPARAM hDbEvent)
-{
- if (hContact) {
- Utils::sendContactMessage(hContact, HM_DBEVENTADDED, hContact, hDbEvent);
-
- // we're in meta and an event belongs to a sub
- MCONTACT hReal = db_event_getContact(hDbEvent);
- if (hReal != hContact)
- Utils::sendContactMessage(hReal, HM_DBEVENTADDED, hContact, hDbEvent);
- }
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// Message event added is called when a new message is added to the database
// if no session is open for the contact, this function will determine if and how a new message
// session(tab) must be created.
@@ -390,7 +369,7 @@ int CMimAPI::DispatchNewEvent(WPARAM hContact, LPARAM hDbEvent) int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM hDbEvent)
{
- if (hContact == 0)
+ if (hContact == 0 || Contact::IsGroupChat(hContact))
return 0;
DBEVENTINFO dbei = {};
@@ -401,12 +380,10 @@ int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) pDlg = Srmm_FindDialog(db_event_getContact(hDbEvent));
BOOL isCustomEvent = IsCustomEvent(dbei.eventType);
- BOOL isShownCustomEvent = DbEventIsForMsgWindow(&dbei);
+ bool isShownCustomEvent = DbEventIsForMsgWindow(&dbei);
if (dbei.markedRead() || (isCustomEvent && !isShownCustomEvent))
return 0;
- g_clistApi.pfnRemoveEvent(hContact, 1);
-
bool bAutoPopup = g_plugin.bAutoPopup;
bool bAutoCreate = g_plugin.bAutoTabs;
bool bAutoContainer = g_plugin.bAutoContainer;
diff --git a/plugins/TabSRMM/src/mim.h b/plugins/TabSRMM/src/mim.h index b9d094868a..4245d0a957 100644 --- a/plugins/TabSRMM/src/mim.h +++ b/plugins/TabSRMM/src/mim.h @@ -173,7 +173,6 @@ public: static int TypingMessage(WPARAM wParam, LPARAM lParam);
static int ProtoAck(WPARAM wParam, LPARAM lParam);
static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam);
- static int DispatchNewEvent(WPARAM wParam, LPARAM lParam);
static int MessageEventAdded(WPARAM wParam, LPARAM lParam);
public:
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index d6a30b3153..acc2e1bd44 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -2489,13 +2489,6 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) StreamEvents(lParam, 1, 1);
return 0;
- case HM_DBEVENTADDED:
- // this is called whenever a new event has been added to the database.
- // this CAN be posted (some sanity checks required).
- if (this && !isChat())
- DM_EventAdded(m_hContact, lParam);
- return 0;
-
case WM_TIMER:
// timer id for message timeouts is composed like:
// for single message sends: basevalue (TIMERID_MSGSEND) + send queue index
diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp index fb80588a80..ff9dac657e 100644 --- a/plugins/TabSRMM/src/msgdlgother.cpp +++ b/plugins/TabSRMM/src/msgdlgother.cpp @@ -452,6 +452,112 @@ void CMsgDialog::EnableSending(bool bMode) const /////////////////////////////////////////////////////////////////////////////////////////
+void CMsgDialog::EventAdded(MEVENT hDbEvent, const DBEVENTINFO &dbei)
+{
+ if (m_hDbEventFirst == 0)
+ m_hDbEventFirst = hDbEvent;
+
+ bool bIsStatusChangeEvent = IsStatusEvent(dbei.eventType);
+ bool bDisableNotify = (dbei.eventType == EVENTTYPE_MESSAGE && (dbei.flags & DBEF_READ));
+
+ if (!DbEventIsShown(&dbei))
+ return;
+
+ if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) {
+ m_lastMessage = dbei.timestamp;
+ m_wszStatusBar[0] = 0;
+ if (m_bShowTyping) {
+ m_nTypeSecs = 0;
+ DM_Typing(true);
+ m_bShowTyping = 0;
+ }
+ HandleIconFeedback(this, (HICON)-1);
+ if (m_pContainer->m_hwndStatus)
+ PostMessage(m_hwnd, DM_UPDATELASTMESSAGE, 0, 0);
+ }
+
+ // set the message log divider to mark new (maybe unseen) messages, if the container has
+ // been minimized or in the background.
+ if (!(dbei.flags & DBEF_SENT) && !bIsStatusChangeEvent) {
+ if (g_plugin.bDividersUsePopupConfig && g_plugin.bUseDividers) {
+ if (!MessageWindowOpened(m_hContact, nullptr))
+ DM_AddDivider();
+ }
+ else if (g_plugin.bUseDividers) {
+ if (!m_pContainer->IsActive())
+ DM_AddDivider();
+ else if (m_pContainer->m_hwndActive != m_hwnd)
+ DM_AddDivider();
+ }
+
+ if (IsWindowVisible(m_pContainer->m_hwnd))
+ m_pContainer->m_bHidden = false;
+ }
+ m_cache->updateStats(TSessionStats::UPDATE_WITH_LAST_RCV, 0);
+
+ if (hDbEvent != m_hDbEventFirst)
+ StreamEvents(hDbEvent, 1, 1);
+ else
+ RemakeLog();
+
+ // handle tab flashing
+ if (!bDisableNotify && !bIsStatusChangeEvent)
+ if ((TabCtrl_GetCurSel(m_hwndParent) != m_iTabID) && !(dbei.flags & DBEF_SENT)) {
+ switch (dbei.eventType) {
+ case EVENTTYPE_MESSAGE:
+ m_iFlashIcon = PluginConfig.g_IconMsgEvent;
+ break;
+ case EVENTTYPE_FILE:
+ m_iFlashIcon = PluginConfig.g_IconFileEvent;
+ break;
+ default:
+ m_iFlashIcon = PluginConfig.g_IconMsgEvent;
+ break;
+ }
+ timerFlash.Start(TIMEOUT_FLASHWND);
+ m_bCanFlashTab = true;
+ }
+
+ // try to flash the contact list...
+ if (!bDisableNotify)
+ FlashOnClist(hDbEvent, &dbei);
+
+ // autoswitch tab if option is set AND container is minimized (otherwise, we never autoswitch)
+ // never switch for status changes...
+ if (!(dbei.flags & DBEF_SENT) && !bIsStatusChangeEvent) {
+ if (g_plugin.bAutoSwitchTabs && m_pContainer->m_hwndActive != m_hwnd) {
+ if ((IsIconic(m_pContainer->m_hwnd) && !IsZoomed(m_pContainer->m_hwnd)) || (g_plugin.bHideOnClose && !IsWindowVisible(m_pContainer->m_hwnd))) {
+ int iItem = GetTabIndexFromHWND(GetParent(m_hwnd), m_hwnd);
+ if (iItem >= 0) {
+ TabCtrl_SetCurSel(m_hwndParent, iItem);
+ ShowWindow(m_pContainer->m_hwndActive, SW_HIDE);
+ m_pContainer->m_hwndActive = m_hwnd;
+ m_pContainer->UpdateTitle(m_hContact);
+ m_pContainer->cfg.flags.m_bDeferredTabSelect = true;
+ }
+ }
+ }
+ }
+
+ // flash window if it is not focused
+ if (!bDisableNotify && !bIsStatusChangeEvent)
+ if (!IsActive() && !(dbei.flags & DBEF_SENT)) {
+ if (!m_pContainer->cfg.flags.m_bNoFlash && !m_pContainer->IsActive())
+ m_pContainer->FlashContainer(1, 0);
+ m_pContainer->SetIcon(this, Skin_LoadIcon(SKINICON_EVENT_MESSAGE));
+ m_pContainer->cfg.flags.m_bNeedsUpdateTitle = true;
+ }
+
+ // play a sound
+ if (!bDisableNotify && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT)))
+ PlayIncomingSound();
+
+ if (m_pWnd)
+ m_pWnd->Invalidate();
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
bool CMsgDialog::GetFirstEvent()
{
int historyMode = g_plugin.getByte(m_hContact, SRMSGSET_LOADHISTORY, -1);
@@ -537,7 +643,7 @@ int CMsgDialog::FindRTLLocale() /////////////////////////////////////////////////////////////////////////////////////////
-void CMsgDialog::FlashOnClist(MEVENT hEvent, DBEVENTINFO *dbei)
+void CMsgDialog::FlashOnClist(MEVENT hEvent, const DBEVENTINFO *dbei)
{
m_dwTickLastEvent = GetTickCount();
diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index e12507d8e0..2fb0e7fe9e 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -411,7 +411,7 @@ static char *CreateRTFTail() return mir_strdup("}");
}
-int TSAPI DbEventIsShown(DBEVENTINFO *dbei)
+bool DbEventIsShown(const DBEVENTINFO *dbei)
{
if (!IsCustomEvent(dbei->eventType) || DbEventIsForMsgWindow(dbei))
return 1;
@@ -419,7 +419,7 @@ int TSAPI DbEventIsShown(DBEVENTINFO *dbei) return IsStatusEvent(dbei->eventType);
}
-int DbEventIsForMsgWindow(DBEVENTINFO *dbei)
+bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei)
{
DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType);
return et && (et->flags & DETF_MSGWINDOW);
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index d0c23f3522..8f0082470a 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -70,7 +70,6 @@ #define EM_REFRESHWITHOUTCLIP (TM_USER+0x106)
#define HM_EVENTSENT (TM_USER+10)
-#define HM_DBEVENTADDED (TM_USER+12)
#define DM_SETINFOPANEL (TM_USER+13)
#define DM_OPTIONSAPPLIED (TM_USER+14)
#define DM_SPLITSENDACK (TM_USER+19)
@@ -437,7 +436,6 @@ class CMsgDialog : public CSrmmBaseDialog HWND DM_CreateClist(void);
void DM_DismissTip(const POINT& pt);
void DM_ErrorDetected(int type, int flag);
- void DM_EventAdded(WPARAM wParam, LPARAM lParam);
void DM_FreeTheme(void);
bool DM_GenericHotkeysCheck(MSG *message);
void DM_HandleAutoSizeRequest(REQRESIZE *rr);
@@ -457,7 +455,7 @@ class CMsgDialog : public CSrmmBaseDialog void DetermineMinHeight(void);
BOOL DoRtfToTags(CMStringW &pszText) const;
int FindRTLLocale(void);
- void FlashOnClist(MEVENT hEvent, DBEVENTINFO *dbei);
+ void FlashOnClist(MEVENT hEvent, const DBEVENTINFO *dbei);
void FlashTab(bool bInvertMode);
LRESULT GetSendButtonState();
void GetSendFormat(void);
@@ -633,6 +631,7 @@ public: void AddLog() override;
void CloseTab() override;
+ void EventAdded(MEVENT, const DBEVENTINFO &dbei) override;
bool GetFirstEvent() override;
bool IsActive() const override;
void LoadSettings() override;
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;
}
|