diff options
author | Sean Allred <code@seanallred.com> | 2014-11-18 23:49:07 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-11-19 00:00:42 -0500 |
commit | 0dd95e3a3d4ee52f52a585388c3ba65e045c305b (patch) | |
tree | f8c4497519cf6f741ea7ec379c537f4b71a4de88 /sx-favorites.el | |
parent | 20dd7254da8e95bd01ce57f806733dee20005039 (diff) | |
parent | 681319aeb250a83d982d1e3e02264a7af0ae4120 (diff) |
Merge branch 'master' into documentation
Conflicts:
sx-method.el
sx-question-list.el
sx-question-mode.el
sx-question.el
sx-request.el
sx.el
Diffstat (limited to 'sx-favorites.el')
-rw-r--r-- | sx-favorites.el | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/sx-favorites.el b/sx-favorites.el new file mode 100644 index 0000000..3aa96dd --- /dev/null +++ b/sx-favorites.el @@ -0,0 +1,86 @@ +;;; sx-favorites.el --- Starred questions -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Sean Allred + +;; Author: Sean Allred <code@seanallred.com> + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; + +;;; Code: + +(require 'sx-method) +(require 'sx-cache) +(require 'sx-site) +(require 'sx-networks) + +(defvar sx-favorite-list-filter + '((.backoff + .items + .quota_max + .quota_remaining + question.question_id) + nil + none)) + +(defvar sx-favorites--user-favorite-list nil + "Alist of questions favorited by the user. + +Each element has the form (SITE FAVORITE-LIST). And each element +in FAVORITE-LIST is the numerical QUESTION_ID.") + +(defun sx-favorites--initialize () + "Ensure question-favorites cache is available. + +Added as hook to initialization." + (or (setq sx-favorites--user-favorite-list + (sx-cache-get 'question-favorites)) + (sx-favorites-update))) +;; Append to ensure `sx-network--initialize is run before it. +(add-hook 'sx-init--internal-hook #'sx-favorites--initialize 'append) + +(defun sx-favorites--retrieve-favorites (site) + "Obtain list of starred QUESTION_IDs for SITE." + (sx-method-call (format "me/favorites?site=%s" site) + nil + sx-favorite-list-filter + 'warn)) + +(defun sx-favorites--update-site-favorites (site) + "Update list of starred QUESTION_IDs for SITE. + +Writes list to cache QUESTION-FAVORITES." + (let* ((favs (sx-favorites--retrieve-favorites site)) + (site-cell (assoc site + sx-favorites--user-favorite-list)) + (fav-cell (mapcar #'cdar favs))) + (if site-cell + (setcdr site-cell fav-cell) + (push (cons site fav-cell) sx-favorites--user-favorite-list)) + (sx-cache-set 'question-favorites sx-favorites--user-favorite-list))) + +(defun sx-favorites-update () + "Update all sites retrieved from `sx-network--user-sites'." + (mapc #'sx-favorites--update-site-favorites + sx-network--user-sites)) + +(provide 'sx-favorites) +;;; sx-favorites.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: |