aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-favorites.el32
-rw-r--r--sx-networks.el36
2 files changed, 34 insertions, 34 deletions
diff --git a/sx-favorites.el b/sx-favorites.el
index 9412b5b..3aa96dd 100644
--- a/sx-favorites.el
+++ b/sx-favorites.el
@@ -43,16 +43,15 @@
Each element has the form (SITE FAVORITE-LIST). And each element
in FAVORITE-LIST is the numerical QUESTION_ID.")
-(defun sx-favorites--ensure-favorite-list ()
- (unless sx-favorites--user-favorite-list
- (setq sx-favorites--user-favorite-list
- (sx-cache-get
- 'question-favorites
- (let ((sites
- (mapcar (lambda (site)
- `(,site))
- sx-network--user-sites)))
- `(quote ,sites))))))
+(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."
@@ -65,18 +64,17 @@ in FAVORITE-LIST is the numerical QUESTION_ID.")
"Update list of starred QUESTION_IDs for SITE.
Writes list to cache QUESTION-FAVORITES."
- (sx-favorites--ensure-favorite-list site)
- (let ((favs (sx-favorites--retrieve-favorites site))
- (site-cell (assoc site
- sx-favorites--user-favorite-list)))
+ (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 (mapcar #'cdar favs))
- (push (cons site favs) sx-favorites--user-favorite-list))
+ (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'."
- (sx-network--ensure-user)
(mapc #'sx-favorites--update-site-favorites
sx-network--user-sites))
diff --git a/sx-networks.el b/sx-networks.el
index 315daba..755d62c 100644
--- a/sx-networks.el
+++ b/sx-networks.el
@@ -56,28 +56,30 @@
"Retrieve cached information for network user.
If cache is not available, retrieve current data."
- (or (and (sx-cache-get 'network-user)
- (setq sx-network--user-sites
+ (or (and (setq sx-network--user-information (sx-cache-get 'network-user)
+ sx-network--user-sites
(sx-network--map-site-url-to-site-api)))
(sx-network--update)))
(defun sx-network--update ()
- "Update user information."
- (setq sx-network--user-information
- (sx-method-call "me/associated"
- '((types . (main_site meta_site)))
- sx-network--user-filter
- 'warn))
- (setq sx-network--user-sites (sx-network--map-site-url-to-site-api))
- (sx-cache-set 'network-user sx-network--user-information))
-
-(defun sx-network--ensure-user ()
- "Ensure user-cache is available.
-
-This should be called during initialization."
+ "Update user information.
+
+Sets cache and then uses `sx-network--get-associated' to update
+the variables."
+ (sx-cache-set 'network-user
+ (sx-method-call "me/associated"
+ '((types . (main_site meta_site)))
+ sx-network--user-filter
+ 'warn))
+ (sx-network--get-associated))
+
+(defun sx-network--initialize ()
+ "Ensure network-user cache is available.
+
+Added as hook to initialization."
;; Cache was not retrieved, retrieve it.
- (unless sx-network--user-information
- (sx-network--get-associated)))
+ (sx-network--get-associated))
+(add-hook 'sx-init--internal-hook #'sx-network--initialize)
(defun sx-network--map-site-url-to-site-api ()
"Convert `me/associations' to a set of `api_site_parameter's.