From 084c5cab6f62a9886bbf07893f85eff901a9f361 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 25 Nov 2014 01:42:09 +0000 Subject: Implement voting --- sx.el | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sx.el b/sx.el index 837d43b..7935ee0 100644 --- a/sx.el +++ b/sx.el @@ -184,6 +184,39 @@ If DATA is a question, also mark it as read." (when ((derived-mode-p 'sx-question-list-mode)) (sx-question-list-refresh 'redisplay 'no-update))))) +(defun sx-toggle-upvote (data) + "Apply or remove upvote from DATA. +DATA can be a question, answer, or comment. Interactively, it is +guessed from context at point." + (interactive (list (sx--data-here))) + (sx-assoc-let data + (sx-set-vote data "upvote" (null .upvoted)))) + +(defun sx-toggle-downvote (data) + "Apply or remove downvote from DATA. +DATA can be a question or an answer. Interactively, it is guessed +from context at point." + (interactive (list (sx--data-here))) + (sx-assoc-let data + (sx-set-vote data "downvote" (null .downvoted)))) + +(defun sx-set-vote (data type status) + "Set the DATA's vote TYPE to STATUS. +DATA can be a question, answer, or comment. +TYPE can be \"upvote\" or \"downvote\". +Status is a boolean." + (sx-assoc-let data + (sx-method-call + (cond + (.comment_id "comments") + (.answer_id "answers") + (.question_id "questions")) + :id (or .comment_id .answer_id .question_id) + :submethod type + :auth 'warn + :url-method "POST" + :site .site))) + ;;; Assoc-let (defun sx--site (data) -- cgit v1.2.3