branch: elpa/mastodon
commit 59c9b90b8e975fe8d4d1c2e9ca1c63e64591eff7
Author: marty hiatt <martianhia...@disroot.org>
Commit: marty hiatt <martianhia...@disroot.org>

    notifs: fix updates for grouped notifs. FIX #673
    
    - also respect mastodon-tl--position-after-update
---
 lisp/mastodon-notifications.el |  2 ++
 lisp/mastodon-tl.el            | 24 ++++++++++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index 2f177b4072..fe85d105dd 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -634,6 +634,8 @@ UPDATE means we are updating, so skip some things."
        (substitute-command-keys
         "You have filtered notifications. \
 \\[mastodon-notifications-requests] to view requests.\n\n")))
+    ;; set update point:
+    (setq mastodon-tl--update-point (point))
     ;; render:
     (mastodon-notifications--render json
                                     (not mastodon-group-notifications))
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index ed7a94f7de..18115bbcc9 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -3171,13 +3171,13 @@ Then run CALLBACK with arguments CBARGS."
     (setf (alist-get "offset" params nil nil #'string=) offset)
     (apply #'mastodon-http--get-json-async url params callback cbargs)))
 
-(defun mastodon-tl--updated-json (endpoint id &optional params)
+(defun mastodon-tl--updated-json (endpoint id &optional params version)
   "Return JSON for timeline ENDPOINT since ID.
 PARAMS is used to send any parameters needed to correctly update
 the current view."
   (let* ((args `(("since_id" . ,(mastodon-tl--as-string id))))
          (args (append args params))
-         (url (mastodon-http--api endpoint)))
+         (url (mastodon-http--api endpoint version)))
     (mastodon-http--get-json url args)))
 
 ;; TODO: add this to new posts in some cases, e.g. in thread view.
@@ -3511,7 +3511,7 @@ This location is defined by a non-nil value of
       (user-error "Update not available in this view")
     ;; FIXME: handle update for search and trending buffers
     (let* ((endpoint (mastodon-tl--endpoint))
-           (update-function (mastodon-tl--update-function))
+           (update-fun (mastodon-tl--update-function))
            (id (mastodon-tl--newest-id)))
       ;; update a thread, without calling `mastodon-tl--updated-json':
       (if (mastodon-tl--buffer-type-eq 'thread)
@@ -3522,15 +3522,23 @@ This location is defined by a non-nil value of
             (user-error "No last id")
           ;; update other timelines:
           (let* ((params (mastodon-tl--update-params))
-                 (json (mastodon-tl--updated-json endpoint id params)))
-            (if (not json)
+                 (notifs-p
+                  (eq update-fun 'mastodon-notifications--timeline))
+                 (json (mastodon-tl--updated-json
+                        endpoint id params
+                        (when (and notifs-p mastodon-group-notifications)
+                          "v2"))))
+            (if (not
+                 (if (and notifs-p mastodon-group-notifications)
+                     (alist-get 'statuses json)
+                   json))
                 (user-error "Nothing to update")
               (let ((inhibit-read-only t))
                 (mastodon-tl--set-after-update-marker)
                 (goto-char (or mastodon-tl--update-point (point-min)))
-                (if (eq update-function 'mastodon-notifications--timeline)
-                    (funcall update-function json nil :update)
-                  (funcall update-function json))
+                (if notifs-p
+                    (funcall update-fun json nil :update)
+                  (funcall update-fun json))
                 (if mastodon-tl--after-update-marker
                     (goto-char mastodon-tl--after-update-marker)
                   (mastodon-tl-goto-next-item))))))))))

Reply via email to