Add category completion to feed subscription

Change the `avandu-categories' function to return a hash table of
title/id value pairs for each category from tt-rss. This makes it easier
to use it in some other places.
This commit is contained in:
Tom Willemse 2014-04-12 22:49:31 +02:00
parent 9297b07df1
commit 0c818bfc59

View file

@ -447,9 +447,14 @@ in which case the result is returned as-is."
If UNREAD is non-nil only get categories with feeds with unread If UNREAD is non-nil only get categories with feeds with unread
articles in them." articles in them."
(let ((hash (make-hash-table :test 'equal)))
(mapc (lambda (category)
(setf (gethash (cdr (assq 'title category)) hash)
(cdr (assq 'id category))))
(avandu--send-command-sync (avandu--send-command-sync
`((op . "getCategories") `((op . "getCategories")
,@(when unread `((unread_only . ,unread)))))) ,@(when unread `((unread_only . ,unread))))))
hash))
(defun avandu-feeds (&optional category unread limit offset) (defun avandu-feeds (&optional category unread limit offset)
"Get the subscribed feeds. "Get the subscribed feeds.
@ -720,12 +725,17 @@ If BUTTON is nil, try to use a button at `point'."
version)) version))
;;;###autoload ;;;###autoload
(defun avandu-subscribe-to-feed (url) (defun avandu-subscribe-to-feed (url category)
"Subscribe to the feed at URL optionally putting it in CATEGORY." "Subscribe to the feed at URL optionally putting it in CATEGORY."
(interactive "MUrl: ") (interactive (let ((categories (avandu-categories)))
(list (read-from-minibuffer "URL: ")
(gethash (completing-read "Category: "
categories nil t)
categories))))
(let ((status (avu-prop (avu-prop (avandu--send-command-sync (let ((status (avu-prop (avu-prop (avandu--send-command-sync
`((op . "subscribeToFeed") `((op . "subscribeToFeed")
(feed_url . ,url))) (feed_url . ,url)
(category_id . ,category)))
status) status)
code))) code)))
(if (= status 1) (if (= status 1)