From aec9ec8b670b3bb9a719377b75a53ff009b07c3d Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 17 Oct 2007 01:15:54 +0000 Subject: changed to use 'event added' instead of 'filter add' git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@371 4f64403b-2f21-0410-a795-97e2b3489a10 --- message_notify/messagenotify.cpp | 66 ++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'message_notify/messagenotify.cpp') 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); -- cgit v1.2.3