summaryrefslogtreecommitdiff
path: root/message_notify/messagenotify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'message_notify/messagenotify.cpp')
-rw-r--r--message_notify/messagenotify.cpp66
1 files changed, 40 insertions, 26 deletions
diff --git a/message_notify/messagenotify.cpp b/message_notify/messagenotify.cpp
index f21c3f3..7cde52e 100644
--- a/message_notify/messagenotify.cpp
+++ b/message_notify/messagenotify.cpp
@@ -27,7 +27,7 @@ DWORD focusTimerId = 0;
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
"Message Notify",
- PLUGIN_MAKE_VERSION(0,3,0,2),
+ PLUGIN_MAKE_VERSION(0,3,1,0),
"Show a popup when a message is received",
"Scott Ellis",
"mail@scottellis.com.au",
@@ -243,53 +243,67 @@ unsigned int __stdcall sttCheckWindowProc( VOID *dwParam ) {
return 0;
}
-int OnDatabaseEventPreAdd(WPARAM wParam, LPARAM lParam) {
- DBEVENTINFO *dbei = (DBEVENTINFO *)lParam;
-
+int OnDatabaseEventAdded(WPARAM wParam, LPARAM lParam) {
+ HANDLE hContact = (HANDLE)wParam;
+
//bool debug = (DBGetContactSettingByte(0, MODULE, "Debug", 0) != 0);
// safety checks
- if ((dbei == 0) || (wParam == 0) || (dbei->flags & DBEF_SENT) || (dbei->eventType != EVENTTYPE_MESSAGE) || (dbei->flags & DBEF_READ)) {
- //if(debug) PUShowMessage("ignoring event (read, sent, no contact, or type != message)", SM_NOTIFY);
+ // messages from this contact ignored
+ if(CallService(MS_IGNORE_ISIGNORED, (WPARAM)hContact, (LPARAM)IGNOREEVENT_MESSAGE)) {
+ //if(debug) PUShowMessage("ignoring event (contact ignored)", SM_NOTIFY);
return 0;
}
- int status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
- if(status >= ID_STATUS_ONLINE && status <= ID_STATUS_OUTTOLUNCH && options.disable_status[status - ID_STATUS_ONLINE]) {
- //if(debug) PUShowMessage("ignoring event (disabled for this status)", SM_NOTIFY);
+ // if contact 'not on list', use default ignore setting
+ if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && CallService(MS_IGNORE_ISIGNORED, 0, (LPARAM)IGNOREEVENT_MESSAGE)) {
+ //if(debug) PUShowMessage("ignoring event (contact not on list and defaulting to ignored)", SM_NOTIFY);
return 0;
}
- // messages from this contact ignored
- if(CallService(MS_IGNORE_ISIGNORED, wParam, (LPARAM)IGNOREEVENT_MESSAGE)) {
- //if(debug) PUShowMessage("ignoring event (contact ignored)", SM_NOTIFY);
+ HANDLE hDbEvent = (HANDLE)lParam;
+ DBEVENTINFO dbei = {0};
+ dbei.cbSize = sizeof(dbei);
+
+ if((dbei.cbBlob = (DWORD)CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0)) == (DWORD)-1)
+ //if(debug) PUShowMessage("invalid event", SM_NOTIFY);
+ return 0;
+
+ if(dbei.cbBlob > 0) dbei.pBlob = new BYTE[dbei.cbBlob];
+ if(CallService(MS_DB_EVENT_GET, (WPARAM)hDbEvent, (LPARAM)&dbei)) {
+ //if(debug) PUShowMessage("get event failed", SM_NOTIFY);
return 0;
}
- // if contact 'not on list', use default ignore setting
- if(DBGetContactSettingByte((HANDLE)wParam, "CList", "NotOnList", 0) && CallService(MS_IGNORE_ISIGNORED, 0, (LPARAM)IGNOREEVENT_MESSAGE)) {
- //if(debug) PUShowMessage("ignoring event (contact not on list and defaulting to ignored)", SM_NOTIFY);
+ if ((dbei.flags & DBEF_SENT) || (dbei.eventType != EVENTTYPE_MESSAGE) || (dbei.flags & DBEF_READ)) {
+ //if(debug) PUShowMessage("ignoring event (read, sent, or type != message)", SM_NOTIFY);
+ return 0;
+ }
+
+ int status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
+ if(status >= ID_STATUS_ONLINE && status <= ID_STATUS_OUTTOLUNCH && options.disable_status[status - ID_STATUS_ONLINE]) {
+ //if(debug) PUShowMessage("ignoring event (disabled for this status)", SM_NOTIFY);
return 0;
}
- if(dbei->cbBlob == 0 || dbei->pBlob == 0) {
+ if(dbei.cbBlob == 0 || dbei.pBlob == 0) {
//if(debug) PUShowMessage("ignoring event (no text)", SM_NOTIFY);
return 0; // just to be safe
}
-
CheckWindowData *cd = new CheckWindowData;
- cd->hContact = (HANDLE)wParam;
+ cd->hContact = hContact;
if(options.show_msg) {
- // copy blob data
- cd->blobsize = dbei->cbBlob;
- cd->blob = new BYTE[cd->blobsize];
- cd->flags = dbei->flags;
- memcpy(cd->blob, dbei->pBlob, cd->blobsize);
- } else
+ // send blob data
+ cd->blobsize = dbei.cbBlob;
+ cd->blob = dbei.pBlob;
+ cd->flags = dbei.flags;
+ } else {
cd->blobsize = 0;
+ delete dbei.pBlob;
+ }
- // spawn a thread to deal with the copied data
+ // spawn a thread to deal with the data
if(thread_api) {
//if(debug) PUShowMessage("spawning notify thread (thread api)", SM_NOTIFY);
FORK_THREADEX_PARAMS tparam = {0};
@@ -356,7 +370,7 @@ int OnModulesLoaded(WPARAM wParam, LPARAM lParam) {
metacontacts_installed = (ServiceExists(MS_MC_GETMETACONTACT) != 0);
- hEventDbEventAdded = HookEvent(ME_DB_EVENT_FILTER_ADD, OnDatabaseEventPreAdd);
+ hEventDbEventAdded = HookEvent(ME_DB_EVENT_ADDED, OnDatabaseEventAdded);
hIdle = HookEvent(ME_IDLE_CHANGED, OnIdleChanged);
hWindowEvent = HookEvent(ME_MSG_WINDOWEVENT, OnWindowEvent);