From 5dbe39b002418f5a663984f341dd7a240bca90c2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 25 Nov 2014 01:39:36 +0000 Subject: .site is now a special symbol in sx-assoc-let sx-question.el no longer manually inserts the `site` property on fetched questions. This was insufficient because we also need this property on other objects. --- sx-question.el | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index 06e8648..cca789e 100644 --- a/sx-question.el +++ b/sx-question.el @@ -56,13 +56,11 @@ properties returned by the API with an added (site SITE) property. `sx-method-call' is used with `sx-question-browse-filter'." - (mapcar - (lambda (question) (cons (cons 'site site) question)) - (sx-method-call 'questions - :keywords `((page . ,page)) - :site site - :auth t - :filter sx-question-browse-filter))) + (sx-method-call 'questions + :keywords `((page . ,page)) + :site site + :auth t + :filter sx-question-browse-filter)) (defun sx-question-get-question (site question-id) "Query SITE for a QUESTION-ID and return it. @@ -159,23 +157,20 @@ If no cache exists for it, initialize one with SITE." (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))))) + (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. + (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 -- cgit v1.2.3 From 61bef1ec5efb8f78c2b8f73638693acf912466a9 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 25 Nov 2014 02:42:21 +0000 Subject: Move browse-filter to sx --- sx-question.el | 29 +++-------------------------- sx.el | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 27 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index cca789e..de07c94 100644 --- a/sx-question.el +++ b/sx-question.el @@ -26,41 +26,18 @@ (require 'sx-filter) (require 'sx-method) -(defvar sx-question-browse-filter - '((question.body_markdown - question.comments - question.answers - question.last_editor - question.accepted_answer_id - question.link - question.upvoted - question.downvoted - user.display_name - comment.owner - comment.body_markdown - comment.body - comment.link - answer.last_editor - answer.link - answer.owner - answer.body_markdown - answer.comments) - (user.profile_image shallow_user.profile_image)) - "The filter applied when retrieving question data. -See `sx-question-get-questions' and `sx-question-get-question'.") - (defun sx-question-get-questions (site &optional page) "Get SITE questions. Return page PAGE (the first if nil). Return a list of question. Each question is an alist of properties returned by the API with an added (site SITE) property. -`sx-method-call' is used with `sx-question-browse-filter'." +`sx-method-call' is used with `sx-browse-filter'." (sx-method-call 'questions :keywords `((page . ,page)) :site site :auth t - :filter sx-question-browse-filter)) + :filter sx-browse-filter)) (defun sx-question-get-question (site question-id) "Query SITE for a QUESTION-ID and return it. @@ -69,7 +46,7 @@ If QUESTION-ID doesn't exist on SITE, raise an error." :id id :site site :auth t - :filter sx-question-browse-filter))) + :filter sx-browse-filter))) (if (vectorp res) (elt res 0) (error "Couldn't find question %S in %S" diff --git a/sx.el b/sx.el index 7935ee0..12b08a1 100644 --- a/sx.el +++ b/sx.el @@ -45,6 +45,31 @@ (interactive) (browse-url "https://github.com/vermiculus/stack-mode/issues/new")) + +;;; Browsing filter +(defvar sx-browse-filter + '((question.body_markdown + question.comments + question.answers + question.last_editor + question.accepted_answer_id + question.link + question.upvoted + question.downvoted + user.display_name + comment.owner + comment.body_markdown + comment.body + comment.link + answer.last_editor + answer.link + answer.owner + answer.body_markdown + answer.comments) + (user.profile_image shallow_user.profile_image)) + "The filter applied when retrieving question data. +See `sx-question-get-questions' and `sx-question-get-question'.") + ;;; Utility Functions @@ -212,9 +237,10 @@ Status is a boolean." (.answer_id "answers") (.question_id "questions")) :id (or .comment_id .answer_id .question_id) - :submethod type + :submethod (concat type (unless status "/undo")) :auth 'warn :url-method "POST" + :filter sx-browse-filter :site .site))) -- cgit v1.2.3