diff options
author | Sean Allred <code@seanallred.com> | 2014-11-18 15:34:10 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-11-18 15:34:10 -0500 |
commit | 821bf636028a38562e18d0da0818cd5d09748f97 (patch) | |
tree | dc0514c652c49f11619fec77021ab19268e7dbbb /sx-question.el | |
parent | 85268ef6fa01b407e712df8199816f9639a5e539 (diff) | |
parent | 93ba268e78dd4967343f479403719a2e20ebc5bd (diff) |
Merge pull request #71 from vermiculus/hidden-questions
Hidden questions
Diffstat (limited to 'sx-question.el')
-rw-r--r-- | sx-question.el | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/sx-question.el b/sx-question.el index 6ef9484..972e9d9 100644 --- a/sx-question.el +++ b/sx-question.el @@ -68,6 +68,7 @@ ;;; Question Properties +;;;; Read/unread (defvar sx-question--user-read-list nil "Alist of questions read by the user. Each element has the form (SITE . QUESTION-LIST). @@ -78,7 +79,7 @@ And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE). If no cache exists for it, initialize one with SITE." (unless sx-question--user-read-list (setq sx-question--user-read-list - (sx-cache-get 'read-questions `(list ,site))))) + (sx-cache-get 'read-questions `'((,site)))))) (defun sx-question--read-p (question) "Non-nil if QUESTION has been read since last updated." @@ -104,13 +105,58 @@ If no cache exists for it, initialize one with SITE." ((setq cell (assoc .question_id site-cell)) (setcdr cell .last_activity_date)) ;; Question wasn't present. - (t - (setcdr site-cell (cons q-cell (cdr site-cell))))))) + (t + (sx-sorted-insert-skip-first + q-cell site-cell (lambda (x y) (> (car x) (car y)))))))) ;; This causes a small lag on `j' and `k' as the list gets large. ;; Should we do this on a timer? ;; Save the results. (sx-cache-set 'read-questions sx-question--user-read-list)) + +;;;; Hidden +(defvar sx-question--user-hidden-list nil + "Alist of questions hidden by the user. +Each element has the form (SITE . QUESTION-LIST). +And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE).") + +(defun sx-question--ensure-hidden-list (site) + "Ensure the `sx-question--user-hidden-list' has been read from cache. +If no cache exists for it, initialize one with SITE." + (unless sx-question--user-hidden-list + (setq sx-question--user-hidden-list + (sx-cache-get 'hidden-questions `'((,site)))))) + +(defun sx-question--hidden-p (question) + "Non-nil if QUESTION has been hidden." + (sx-assoc-let question + (sx-question--ensure-hidden-list .site) + (let ((ql (cdr (assoc .site sx-question--user-hidden-list)))) + (and ql (memq .question_id ql))))) + +(defun sx-question--mark-hidden (question) + "Mark QUESTION as being hidden." + (sx-assoc-let question + (sx-question--ensure-hidden-list .site) + (let ((site-cell (assoc .site sx-question--user-hidden-list)) + cell) + ;; If question already hidden, do nothing. + (unless (memq .question_id site-cell) + ;; First question from this site. + (if (null site-cell) + (push (list .site .question_id) sx-question--user-hidden-list) + ;; Question wasn't present. + ;; Add it in, but make sure it's sorted (just in case we need + ;; it later). + (sx-sorted-insert-skip-first .question_id site-cell >)) + ;; This causes a small lag on `j' and `k' as the list gets large. + ;; Should we do this on a timer? + ;; Save the results. + (sx-cache-set 'hidden-questions sx-question--user-hidden-list))))) + + +;;;; Other data + (defun sx-question--accepted-answer-id (question) "Return accepted answer in QUESTION, or nil if none." (sx-assoc-let question |