Better notification handling.
authorSteve Youngs <steve@emchat.org>
Mon, 25 Feb 2013 10:38:57 +0000 (20:38 +1000)
committerSteve Youngs <steve@emchat.org>
Mon, 25 Feb 2013 10:38:57 +0000 (20:38 +1000)
With this changeset you can now control which messages get notifications.
See `emchat-notify-events-type'.  Notifications still only happen if the
emchat-frame is not the current selected frame. No point in getting
notifications when it's right there in front of you.

* emchat-log.el (emchat-notify): Rewrite using finer grained
tuning of which events to send notifications for.

* emchat-log.el (emchat-notify-events-type): New.

* emchat-log.el (emchat-log): Maybe send notification after log
has been written.  Test off of emchat-notify-flag.

Signed-off-by: Steve Youngs <steve@emchat.org>
emchat-log.el

index e6aacc1..208848a 100644 (file)
@@ -193,6 +193,21 @@ Currently this simply uses `notify-send' shell command."
   :group 'emchat-log
   :type 'boolean)
 
+(defcustom emchat-notify-events-type 'msg
+  "*What event types to send notifications for.
+
+Possible values are:
+    all      -- all events \(anything and everything that is logged\).
+    incoming -- only incoming messages plus system and debug events.
+                This would include friends status changes.
+    msg      -- incoming user messages only \(default\).
+    nil      -- no events."
+  :group 'emchat-log
+  :type '(choice (item :tag "All Events" all)
+                (item :tag "Incoming msg + sys + debug events" incoming)
+                (item :tag "Incoming user messages" msg)
+                (item :tag "Nothing" nil)))
+
 (defcustom emchat-notify-command (executable-find "notify-send")
   "*The shell command used to send notifications."
   :group 'emchat-log
@@ -413,24 +428,42 @@ ID is the entity that sent MESSAGE."
        (set-extent-property exp 'balloon-help bhelp)))))
 
 (defun emchat-notify (id message)
-  "Send a notification about incoming MESSAGE from ID."
+  "Send a notification about MESSAGE from ID."
   (let ((notify emchat-notify-command)
        (icon (expand-file-name "emchat-icon.png" emchat-glyph-dir))
-       (urgency "normal")
-       (skip-id (member id '("!debug" "!info" "!system"))))
-    (when (and notify (not skip-id))
-      (call-process notify nil nil nil
-                   "-i" icon
-                   "-u" urgency
-                   (format "New Message From: %s" id)
-                   message))))
+       (urgency "normal"))
+    (when notify
+      (unless (eq (selected-frame) emchat-frame)
+       (ecase emchat-notify-events-type
+         (all (call-process notify nil nil nil
+                            "-i" icon
+                            "-u" urgency
+                            (format "New Message From: %s" id)
+                            message))
+         (incoming
+          (and (not (search ">>>" message))
+               (not (search "***|" message))
+               (call-process notify nil nil nil
+                             "-i" icon
+                             "-u" urgency
+                             (format "New Message From: %s" id)
+                             message)))
+         (msg
+          (and (not (equal id "!debug"))
+               (not (equal id "!error"))
+               (not (equal id "!system"))
+               (not (search ">>>" message))
+               (not (search "***|" message))
+               (call-process notify nil nil nil
+                             "-i" icon
+                             "-u" urgency
+                             (format "New Message From: %s" id)
+                             message))))))))
 
 (defun emchat-log (id message option mark-unread)
   "Log message under ID.
 Put MESSAGE at the end of log buffer if OPTION is non-nil.
 Mark MESSAGE unread if MARK-UNREAD is non-nil"
-  (unless (eq (selected-frame) emchat-frame)
-    (emchat-notify id message))
   (if (and option (buffer-live-p emchat-log-buffer))
       (with-current-buffer emchat-log-buffer
        (save-excursion
@@ -446,6 +479,8 @@ Mark MESSAGE unread if MARK-UNREAD is non-nil"
             ;; use concat instead of format for extent
             (concat "[" id "] " message "\n"))
            (fill-region start-point (point))
+           (when emchat-notify-flag
+             (emchat-notify id message))
            (when emchat-history-enabled-flag
              (emchat-log-update-history id message weekday))
            (when emchat-track-enable