xuchunyang / github-notifier.el

Displays your GitHub notifications unread count in Emacs mode-line
32 stars 6 forks source link

Hook for new notification #4

Closed Andre0991 closed 8 years ago

Andre0991 commented 8 years ago

Hi.

I think it'd be great if github-notifier had a hook that is activated after getting a new notification. That would make it more extensible, which is what Emacs is all about.

Of course, I myself could define a function to check github-notifier-unread-count value or something like that, but I think it'd be nice for github-notifier to have it.

Thanks.

xuchunyang commented 8 years ago

Oops, sorry for the delay.

It is not very clear about the meaning of "new notification", for example, for the first time, all notifications looks like new to github-notifier.el (or not). Instead I will add a hook which runs whenever github-notifier.el updates, the rest is up to you.

xuchunyang commented 8 years ago

Here is a working example for the new hook, it messages the count of new notification after github-notifier.el updates.

(defun github-notifier--message-new (last-json)
  (let ((last-notification-ids
         (loop for item in (append last-json nil)
               collect (assoc-default 'id item)))
        (current-notification-ids
         (loop for item in (append github-notifier-unread-json nil)
               collect (assoc-default 'id item))))
    (message "You have %d new notifications."
             (length (-difference
                      current-notification-ids
                      last-notification-ids)))))

(add-hook 'github-notifier-update-hook #'github-notifier--message-new)
Andre0991 commented 8 years ago

Cool. Thanks!