Include the message sender in desktop notification
[riece] / lisp / riece-desktop-notify.el
index ef4b771..a696cae 100644 (file)
@@ -1,4 +1,4 @@
-;;; riece-desktop-notify.el --- Display notification to desktop
+;;; riece-desktop-notify.el --- Display notification to desktop -*- lexical-binding: t -*-
 ;; Copyright (C) 2009 OHASHI Akira
 
 ;; Author: OHASHI Akira <bg66@koka-in.org>
   :group 'riece)
 
 (defcustom riece-desktop-notify-title-function
-  '(lambda (message)
-     (riece-identity-prefix (riece-message-target message)))
+  #'(lambda (message)
+      (format "%s said in %s..."
+             (riece-identity-prefix (riece-message-speaker message))
+             (riece-identity-prefix (riece-message-target message))))
   "*The function which make title.
 This function must have only one message object as argument."
   :type 'function
@@ -145,31 +147,38 @@ This function must have only one message object as argument."
                  (symbol-name riece-desktop-notify-type)
                  (symbol-name symbol))))
 
-(defun riece-desktop-notify-keyword-notify-function (keyword message)
-  (let ((program-symbol (riece-desktop-notify-make-symbol 'program))
-       (args-symbol (riece-desktop-notify-make-symbol 'args)))
-    (when (and (boundp program-symbol) (boundp args-symbol))
-      (let ((program (eval program-symbol))
-           (args (eval args-symbol)))
-       (when (fboundp 'executable-find)
-         (setq program (executable-find program)))
-       (when (stringp program)
-         (let ((title (funcall riece-desktop-notify-title-function message))
-               (message (funcall riece-desktop-notify-message-function
-                                 message)))
-           (condition-case nil
-               (apply #'call-process program nil nil nil
-                      (riece-desktop-notify-substitute-variables
-                       args
-                       (list (cons 'title
-                                   (encode-coding-string
-                                    title
-                                    riece-desktop-notify-coding-system))
-                             (cons 'message
-                                   (encode-coding-string
-                                    message
-                                    riece-desktop-notify-coding-system)))))
-             (file-error nil))))))))
+(defvar riece-desktop-notify-last-message nil
+  "The previous message we have seen in
+`riece-desktop-notify-keyword-notify-function'.")
+
+(defun riece-desktop-notify-keyword-notify-function (_keyword message)
+  ;; Don't send notification multiple times for a single message.
+  (unless (eq riece-desktop-notify-last-message message)
+    (let ((program-symbol (riece-desktop-notify-make-symbol 'program))
+         (args-symbol (riece-desktop-notify-make-symbol 'args)))
+      (when (and (boundp program-symbol) (boundp args-symbol))
+       (let ((program (eval program-symbol))
+             (args (eval args-symbol)))
+         (when (fboundp 'executable-find)
+           (setq program (executable-find program)))
+         (when (stringp program)
+           (let ((title (funcall riece-desktop-notify-title-function message))
+                 (message (funcall riece-desktop-notify-message-function
+                                   message)))
+             (condition-case nil
+                 (apply #'call-process program nil 0 nil
+                        (riece-desktop-notify-substitute-variables
+                         args
+                         (list (cons 'title
+                                     (encode-coding-string
+                                      title
+                                      riece-desktop-notify-coding-system))
+                               (cons 'message
+                                     (encode-coding-string
+                                      message
+                                      riece-desktop-notify-coding-system)))))
+               (file-error nil))))))))
+  (setq riece-desktop-notify-last-message message))
 
 (defun riece-desktop-notify-requires ()
   '(riece-keyword))