X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Fgnus-notifications.el;h=f73aac1f5b37ce4c3f7295b07bf99ccfff25868a;hb=4fe932c9ab0714252bb9a6de65b139026c41b3ac;hp=811a90895ae4ab103330149b191d8128d3bc76bc;hpb=873ba7b51ddfb07246cd874b7de72662308236c9;p=gnus diff --git a/lisp/gnus-notifications.el b/lisp/gnus-notifications.el index 811a90895..f73aac1f5 100644 --- a/lisp/gnus-notifications.el +++ b/lisp/gnus-notifications.el @@ -1,6 +1,6 @@ ;; gnus-notifications.el -- Send notification on new message in Gnus -;; Copyright (C) 2012 Free Software Foundation, Inc. +;; Copyright (C) 2012-2015 Free Software Foundation, Inc. ;; Author: Julien Danjou ;; Keywords: news @@ -29,16 +29,20 @@ ;;; Code: -(require 'notifications nil t) +(ignore-errors + (require 'notifications)) (require 'gnus-sum) (require 'gnus-group) (require 'gnus-int) (require 'gnus-art) (require 'gnus-util) -(require 'google-contacts nil t) ; Optional +(ignore-errors + (require 'google-contacts)) ; Optional +(require 'gnus-fun) (defgroup gnus-notifications nil "Send notifications on new message in Gnus." + :version "24.3" :group 'gnus) (defcustom gnus-notifications-use-google-contacts t @@ -60,7 +64,8 @@ not get notifications." (defcustom gnus-notifications-timeout nil "Timeout used for notifications sent via `notifications-notify'." - :type 'integer + :type '(choice (const :tag "Server default" nil) + (integer :tag "Milliseconds")) :group 'gnus-notifications) (defvar gnus-notifications-sent nil @@ -70,37 +75,50 @@ not get notifications." "Map notifications ids to messages.") (defun gnus-notifications-action (id key) - (when (string= key "read") - (let ((group-article (assoc id gnus-notifications-id-to-msg))) - (when group-article - (let ((group (cadr group-article)) - (article (caddr group-article))) - (gnus-fetch-group group (list article))))))) + (let ((group-article (assoc id gnus-notifications-id-to-msg))) + (when group-article + (let ((group (cadr group-article)) + (article (nth 2 group-article))) + (cond ((string= key "read") + (gnus-fetch-group group (list article)) + (gnus-select-frame-set-input-focus (selected-frame))) + ((string= key "mark-read") + (gnus-update-read-articles + group + (delq article (gnus-list-of-unread-articles group))) + ;; gnus-group-refresh-group + (gnus-group-update-group group))))))) (defun gnus-notifications-notify (from subject photo-file) "Send a notification about a new mail. Return a notification id if any, or t on success." (if (fboundp 'notifications-notify) - (notifications-notify + (gnus-funcall-no-warning + 'notifications-notify :title from :body subject - :actions '("read" "Read") + :actions '("read" "Read" "mark-read" "Mark As Read") :on-action 'gnus-notifications-action - :app-icon (image-search-load-path "gnus/gnus.png") + :app-icon (gnus-funcall-no-warning + 'image-search-load-path "gnus/gnus.png") + :image-path photo-file :app-name "Gnus" :category "email.arrived" - :timeout gnus-notifications-timeout - :image-path photo-file) + :timeout gnus-notifications-timeout) (message "New message from %s: %s" from subject) ;; Don't return an id t)) +(declare-function gravatar-retrieve-synchronously "gravatar.el" + (mail-address)) + (defun gnus-notifications-get-photo (mail-address) "Get photo for mail address." (let ((google-photo (when (and gnus-notifications-use-google-contacts (fboundp 'google-contacts-get-photo)) (ignore-errors - (google-contacts-get-photo mail-address))))) + (gnus-funcall-no-warning + 'google-contacts-get-photo mail-address))))) (if google-photo google-photo (when gnus-notifications-use-gravatar @@ -160,8 +178,10 @@ This is typically a function to add in (or (mail-fetch-field "From") ""))) (address (cadr address-components))) ;; Ignore mails from ourselves - (unless (gnus-string-match-p gnus-ignored-from-addresses - address) + (unless (and gnus-ignored-from-addresses + address + (gnus-string-match-p gnus-ignored-from-addresses + address)) (let* ((photo-file (gnus-notifications-get-photo-file address)) (notification-id (gnus-notifications-notify (or (car address-components) address)