aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-25 01:42:09 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-25 01:42:09 +0000
commit084c5cab6f62a9886bbf07893f85eff901a9f361 (patch)
treeb09513c24ad5e19bd1e3ff023b91954025861b6e
parent5dbe39b002418f5a663984f341dd7a240bca90c2 (diff)
Implement voting
-rw-r--r--sx.el33
1 files changed, 33 insertions, 0 deletions
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)