aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormousebot <mousebot@riseup.net>2021-10-25 11:37:08 +0200
committermousebot <mousebot@riseup.net>2021-10-25 11:37:08 +0200
commitf67558804e899306f6495c934bd25adff814d092 (patch)
treebcda5a27f9127eb322f902fe0d5cc8c7723b2353 /lisp
parent67e515edbbaa660757ecdcf87bbdfe353eb652f2 (diff)
restore original tl--init as tl--init-sync.
- use it for eg notifications - this because i suspect sync is sometimes faster. - with async init*, i often have to press a key to trigger the request - perhaps good to have both in the code, and choose which to use when - cd also poss make this a customize.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-notifications.el2
-rw-r--r--lisp/mastodon-tl.el31
2 files changed, 32 insertions, 1 deletions
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index c917124..2e9aea3 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -252,7 +252,7 @@ ID is the notification's own id, which is attached as a property."
"Display NOTIFICATIONS in buffer."
(interactive)
(message "Loading your notifications...")
- (mastodon-tl--init
+ (mastodon-tl--init-sync
"notifications"
"notifications"
'mastodon-notifications--timeline))
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 7f9538b..a7767b8 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1314,5 +1314,36 @@ JSON is the data returned from the server."
(current-buffer)
nil)))))
+(defun mastodon-tl--init-sync (buffer-name endpoint update-function)
+ "Initialize BUFFER-NAME with timeline targeted by ENDPOINT.
+
+UPDATE-FUNCTION is used to recieve more toots.
+Runs synchronously."
+ (let* ((url (mastodon-http--api endpoint))
+ (buffer (concat "*mastodon-" buffer-name "*"))
+ (json (mastodon-http--get-json url)))
+ (with-output-to-temp-buffer buffer
+ (switch-to-buffer buffer)
+ (setq
+ ;; Initialize with a minimal interval; we re-scan at least once
+ ;; every 5 minutes to catch any timestamps we may have missed
+ mastodon-tl--timestamp-next-update (time-add (current-time)
+ (seconds-to-time 300)))
+ (funcall update-function json))
+ (mastodon-mode)
+ (with-current-buffer buffer
+ (setq mastodon-tl--buffer-spec
+ `(buffer-name ,buffer-name
+ endpoint ,endpoint update-function
+ ,update-function)
+ mastodon-tl--timestamp-update-timer
+ (when mastodon-tl--enable-relative-timestamps
+ (run-at-time mastodon-tl--timestamp-next-update
+ nil ;; don't repeat
+ #'mastodon-tl--update-timestamps-callback
+ (current-buffer)
+ nil))))
+ buffer))
+
(provide 'mastodon-tl)
;;; mastodon-tl.el ends here