diff options
author | Jonathan Leech-Pepin <jonathan.leechpepin@gmail.com> | 2014-11-18 11:21:51 -0500 |
---|---|---|
committer | Jonathan Leech-Pepin <jonathan.leechpepin@gmail.com> | 2014-11-18 11:57:45 -0500 |
commit | 6a1d561e3af81aaa67dd834192697e39e3e4bc5d (patch) | |
tree | 24efae0f03c7339b89db1d6c654501b7b8e1cddb /sx-networks.el | |
parent | c0a4f017ca56f8d8ba174231d9f1f3f64fa0a9a4 (diff) |
Fix logic for updating cache and setting variables.
Turned (sx-network--ensure-user) into (sx-network--initialize) and added
as hook for initialization.
Diffstat (limited to 'sx-networks.el')
-rw-r--r-- | sx-networks.el | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/sx-networks.el b/sx-networks.el index 315daba..fbb2d78 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 () + "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 user-cache is available. -This should be called during initialization." +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. |