branch: elpa/mastodon
commit 77db7fdb3d58fd0a0912bfe405ee4b86bf753a04
Author: marty hiatt <[email protected]>
Commit: marty hiatt <[email protected]>

    remove dulpicate check-for-updates var, rename alerts-interval.
    
    re-write mastodon-notifications--update-with-timer
    
    enable mastodon-notifications-alerts by default, now that we fallback to
    messaging if no alert.el present.
---
 lisp/mastodon-notifications.el | 80 +++++++++++++++++++++---------------------
 lisp/mastodon.el               | 15 ++++----
 2 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index 2683ec528c..5ca14ad1e2 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -96,8 +96,7 @@
 (defvar mastodon-notifications-grouped-names-count)
 (defvar mastodon-tl--link-keymap)
 (defvar mastodon-tl--update-point)
-(defvar mastodon-notifications-updates-interval)
-(defvar mastodon-notifications-check-for-updates)
+(defvar mastodon-notifications-alerts-interval)
 (defvar mastodon-notifications-alert-style)
 (defvar mastodon-notifications-alerts)
 ;;; VARIABLES
@@ -1057,43 +1056,44 @@ When FORCE, skip all checks and show an alert (for 
debugging)."
 
 (defun mastodon-notifications--update-with-timer ()
   "Run a timer to update notifications. Added to `mastodon-mode-hook'."
-  ;; if no buffers: cancel our timer and do nothing else:
-  (if (and (not (mastodon-live-buffers))
-           ;; if we are loading a first mastodon buffer, the previous
-           ;; check fails, as `mastodon-mode-hook' necessariliy runs
-           ;; before we have buf-spec, which
-           ;; `mastodon-tl--get-buffer-type' depends on, and if we set
-           ;; buf-spec before enabling the mode, buf-spec is lost. so
-           ;; let's also check if the current buffer prefix is *mastodon-,
-           ;; which it will be when first calling `mastodon' at least
-           ;; (though not necessarily when loading other first mastodon.el
-           ;; buffers, such as new toot):
-           (not (string-prefix-p "*mastodon-" (buffer-name))))
-      ;; if not masto buffers: cancel everything:
-      (mastodon-notifications-cancel-timer)
-    (when mastodon-notifications-check-for-updates
-      ;; if a timer has already run but somehow the variable has not been
-      ;; nilled, assume it is a leftover and cancel it, otherwise our
-      ;; unless check below will always fail and no new timer will be
-      ;; created.
-      ;; NB: this gets called:
-      ;; - on creating a new mastodon.el buffer,
-      ;; - if an existing timer is run.
-      ;; in both cases, `timerp' should fail, but sometimes we have a
-      ;; zombie one somehow:
-      (when (and (timerp mastodon-notifications-timer)
-                 (timer--triggered mastodon-notifications-timer))
-        (mastodon-notifications-cancel-timer))
-      ;; maybe we can remove this unless check, and just always cancel and
-      ;; restart? that would have the effect of making the timer always
-      ;; run mastodon-notifications-updates-interval seconds after opening
-      ;; a new mastodon.el buffer, or effectively only showing an alert if
-      ;; the user stops opening buffers:
-      (unless mastodon-notifications-timer
-        ;; set new timer if we don't have one:
-        (setq mastodon-notifications-timer
-              (run-at-time mastodon-notifications-updates-interval
-                           nil #'mastodon-notifications--update-check))))))
+  (cond
+   ;; if no buffers: cancel our timer and do nothing else:
+   ((and (not (mastodon-live-buffers))
+         ;; if we are loading a first mastodon.el buffer, the previous
+         ;; check fails, as `mastodon-mode-hook' necessariliy runs
+         ;; before we have buf-spec, which
+         ;; `mastodon-tl--get-buffer-type' relies on, and if we set
+         ;; buf-spec earlier, enabling the mode wipes it. So
+         ;; let's also check if the current buffer prefix is *mastodon-,
+         ;; which it will be when first calling `mastodon' at least
+         ;; (though not necessarily when loading other first mastodon.el
+         ;; buffers, such as new toot):
+         (not (string-prefix-p "*mastodon-" (buffer-name))))
+    ;; if not masto buffers: cancel everything:
+    (mastodon-notifications-cancel-timer))
+   ;; if a timer has already run but somehow
+   ;; `mastodon-notifications-timer' has not been nilled, assume it is a
+   ;; leftover and cancel it, otherwise our unless check below will always
+   ;; fail and no new timer will be created.
+   ;; NB: this gets called:
+   ;; - on creating a new mastodon.el buffer,
+   ;; - if an existing timer is run.
+   ;; in both cases, `timerp' should fail, but sometimes we have a
+   ;; zombie one somehow:
+   ((and (timerp mastodon-notifications-timer)
+         (timer--triggered mastodon-notifications-timer))
+    (mastodon-notifications-cancel-timer))
+   ;; maybe we can remove this unless check, and just always cancel and
+   ;; restart? that would have the effect of making the timer always
+   ;; run `mastodon-notifications-alerts-interval' seconds after opening
+   ;; a new mastodon.el buffer, or effectively only showing an alert if
+   ;; the user stops opening buffers:
+   (t
+    (unless mastodon-notifications-timer
+      ;; set new timer if we don't have one:
+      (setq mastodon-notifications-timer
+            (run-at-time mastodon-notifications-alerts-interval
+                         nil #'mastodon-notifications--update-check))))))
 
 (defun mastodon-notifications--update-check ()
   "Get unread notifications count from the server, asynchronously.
@@ -1114,7 +1114,7 @@ Callback is `mastodon-notifications--update-check-cb'."
       ;; FIXME: unsure how to check if notifications buffer is active
       ;; here, as (current-buffer) returns different things if this is
       ;; triggered with notifs buffer active! so let's skip it for now,
-      ;; and only ever notify, not update.
+      ;; and only ever notify, not update the notifs buffer.
 
       ;; (if ;;(not (mastodon-tl--buffer-type-eq 'notifications))
       ;; (not mastodon-notifications-update-when-unread)
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index 397a121a0f..af3d541a95 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -200,16 +200,17 @@ A count of 2 for example means to display like so: \"Bob, 
Jenny
 and X others...\"."
   :type '(integer))
 
-(defcustom mastodon-notifications-check-for-updates t
-  "Whether to regularly check for new notifications."
-  :type '(boolean))
-
-(defcustom mastodon-notifications-updates-interval 60
+(defcustom mastodon-notifications-alerts-interval 60
   "How often to check for new notifications, in seconds."
   :type '(integer))
 
-(defcustom mastodon-notifications-alerts nil
-  "Whether to enable alert.el alerts."
+(defcustom mastodon-notifications-alerts t
+  "Whether to enable alert.el unread-notification alerts.
+If this is enabled and alert.el is installed, an alert.el notification
+will be shown using `mastodon-notifications-alert-style' as its alert
+style. If this is enabled but alert.el is not installed, alerts will be
+shown using `message'.
+Alerts are only checked for when at least 1 mastodon.el buffer is open."
   :type '(boolean))
 
 (defcustom mastodon-notifications-alert-style alert-default-style

Reply via email to