gnus-notifications: add actions support
[gnus] / lisp / gnus-sync.el
index 612e586..7e13b88 100644 (file)
@@ -1,6 +1,6 @@
 ;;; gnus-sync.el --- synchronization facility for Gnus
 
-;; Copyright (C) 2010-2011  Free Software Foundation, Inc.
+;; Copyright (C) 2010-2012  Free Software Foundation, Inc.
 
 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
 ;; Keywords: news synchronization nntp nnrss
 (require 'gnus-start)
 (require 'gnus-util)
 
+(defvar gnus-topic-alist) ;; gnus-group.el
+(eval-when-compile
+  (autoload 'gnus-group-topic "gnus-topic")
+  (autoload 'gnus-topic-create-topic "gnus-topic" nil t)
+  (autoload 'gnus-topic-enter-dribble "gnus-topic"))
+
 (defgroup gnus-sync nil
   "The Gnus synchronization facility."
   :version "24.1"
   :group 'gnus)
 
-(defcustom gnus-sync-newsrc-groups `("nntp" "nnrss")
+(defcustom gnus-sync-newsrc-groups '("nntp" "nnrss")
   "List of groups to be synchronized in the gnus-newsrc-alist.
 The group names are matched, they don't have to be fully
 qualified.  Typically you would choose all of these.  That's the
@@ -172,14 +178,11 @@ and `gnus-topic-alist'.  Also see `gnus-variable-list'."
 (defun gnus-sync-lesync-call (url method headers &optional kvdata)
   "Make an access request to URL using KVDATA and METHOD.
 KVDATA must be an alist."
-  ;;(debug (json-encode kvdata))
-  ;; (when (string-match-p "gmane.emacs.devel" url) (debug kvdata))
   (flet ((json-alist-p (list) (gnus-sync-json-alist-p list))) ; temp patch
     (let ((url-request-method method)
           (url-request-extra-headers headers)
           (url-request-data (if kvdata (json-encode kvdata) nil)))
       (with-current-buffer (url-retrieve-synchronously url)
-        ;;(debug (buffer-string))
         (let ((data (gnus-sync-lesync-parse)))
           (gnus-message 12 "gnus-sync-lesync-call: %s URL %s sent %S got %S"
                         method url `((headers . ,headers) (data ,kvdata)) data)
@@ -488,10 +491,22 @@ Updates `gnus-sync-lesync-props-hash'."
       ;; the read marks
       ,(cons 'read (gnus-sync-range2invlist (nth 2 nentry)))
       ;; the other marks
-      ,@(mapcar (lambda (mark-entry)
-                  (cons (car mark-entry)
-                        (gnus-sync-range2invlist (cdr mark-entry))))
-                (nth 3 nentry)))))
+      ,@(delq nil (mapcar (lambda (mark-entry)
+                            (gnus-message 12 "%s: prep param %s in %s"
+                                          loc
+                                          (car mark-entry)
+                                          (nth 3 nentry))
+                            (if (listp (cdr mark-entry))
+                                (cons (car mark-entry)
+                                      (gnus-sync-range2invlist
+                                       (cdr mark-entry)))
+                              (progn    ; else this is not a list
+                                (gnus-message 9 "%s: non-list param %s in %s"
+                                              loc
+                                              (car mark-entry)
+                                              (nth 3 nentry))
+                                nil)))
+                          (nth 3 nentry))))))
 
 (defun gnus-sync-lesync-post-save-group-entry (url entry)
   (let* ((loc "gnus-sync-lesync-post-save-group-entry")
@@ -666,8 +681,8 @@ unwanted groups via the LeSync URL."
         (cond
          ((eq k 'read)
           (push (cons k (gnus-sync-invlist2range val)) ret))
-         ;; we already know the name
-         ((eq k '_id)
+         ;; we ignore these parameters
+         ((member k '(_id subscribe-all _deleted_conflicts))
           nil)
          ((eq k '_rev)
           (push (cons 'rev val) ret))
@@ -801,24 +816,24 @@ With a prefix, SUBSCRIBE-ALL is set and unknown groups will be subscribed."
            (stringp (nth 1 gnus-sync-backend)))
       (let ((errored nil)
             name ftime)
-        (mapcar (lambda (entry)
-                  (setq name (cdr (assq 'id entry)))
-                  ;; set ftime the FIRST time through this loop, that
-                  ;; way it reflects the time we FINISHED reading
-                  (unless ftime (setq ftime (float-time)))
-
-                  (unless errored
-                    (setq errored
-                          (when (equal name
-                                       (gnus-sync-lesync-read-group-entry
-                                        (nth 1 gnus-sync-backend)
-                                        name
-                                        (cdr (assq 'value entry))
-                                        `(read-time ,ftime)
-                                        `(subscribe-all ,subscribe-all)))
-                            (gnus-sync-lesync-install-group-entry
-                             (cdr (assq 'id entry)))))))
-                (gnus-sync-lesync-groups-builder (nth 1 gnus-sync-backend)))))
+        (mapc (lambda (entry)
+               (setq name (cdr (assq 'id entry)))
+               ;; set ftime the FIRST time through this loop, that
+               ;; way it reflects the time we FINISHED reading
+               (unless ftime (setq ftime (float-time)))
+
+               (unless errored
+                 (setq errored
+                       (when (equal name
+                                    (gnus-sync-lesync-read-group-entry
+                                     (nth 1 gnus-sync-backend)
+                                     name
+                                     (cdr (assq 'value entry))
+                                     `(read-time ,ftime)
+                                     `(subscribe-all ,subscribe-all)))
+                         (gnus-sync-lesync-install-group-entry
+                          (cdr (assq 'id entry)))))))
+             (gnus-sync-lesync-groups-builder (nth 1 gnus-sync-backend)))))
 
      ((stringp gnus-sync-backend)
       ;; read data here...