From 34d28e79f4a6049dc4ceb44397a2ca0725cecd5f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 17 Nov 2014 11:33:53 +0000 Subject: Define -visit to use answer link if available. --- sx-question.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index fc44bd8..6ef9484 100644 --- a/sx-question.el +++ b/sx-question.el @@ -34,11 +34,13 @@ question.answers question.last_editor question.accepted_answer_id + question.link user.display_name comment.owner comment.body_markdown comment.body answer.last_editor + answer.link answer.owner answer.body_markdown answer.comments) -- cgit v1.2.3 From bee6143c8abe0bc7bb6dad3d20ba539e29c4cc3c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 18 Nov 2014 16:35:34 +0000 Subject: Implement hidden question database Also improve read question code. --- sx-question.el | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index fc44bd8..3906a28 100644 --- a/sx-question.el +++ b/sx-question.el @@ -66,6 +66,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). @@ -76,7 +77,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." @@ -102,13 +103,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 -- cgit v1.2.3