I have custom notification code that runs, and like you I often do not want them if I am obviously editing in Emacs at the time the message arrives.
Often I am looking away from Emacs, away from my desk, or something else and emacs still has focus, so messages can be missed easily if only mode line notifications are used or if they are notifications are canceled based on focus. I use lasting OS specific notifications that always run if the corresponding chat buffer is not visible when the message comes in, that way even if you miss the mode line blip, you will always know when messages came through when you return to your desk etc. You have access to which buffer the message belongs to in the custom notification hook, so basically, in your notification hook do...
(unless (get-buffer-window chat-buffer) (do-notification))
Sometimes I may get important chat notifications while I am away from Emacs for a long time but am still connected, in those cases I use current-idle-time
to choose whether or not to elevate the notification to an email.
(when (> (time-to-seconds (or (current-idle-time) (seconds-to-time 0)))
(or min-number-of-idle-seconds-before-email 300))
(do-custom-email-notification))
In the above code I only perform an email when emacs has been idle for a given number of seconds or 300 seconds (5 minutes) if my custom variable is nil.
With these hooks, I ensure that I won't be bothered with excessive noise while editting, won't miss any messages if I am looking away or gone for a bit, and will also not miss any messages that come even if I am away for hours by getting them by email.
I am hesitant to link this as my jabber configuration is without a doubt, the messiest and least organized file in my .emacs.d, but here is what I use currently in total:
.emacs.d/jorbi/jorbi-jabber.el