diff options
Diffstat (limited to 'sx-interaction.el')
-rw-r--r-- | sx-interaction.el | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/sx-interaction.el b/sx-interaction.el index 3d60cbe..368da09 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -230,14 +230,7 @@ Interactively, it is guessed from context at point. With the UNDO prefix argument, unfavorite the question instead." (interactive (list (sx--error-if-unread (sx--data-here 'question)) current-prefix-arg)) - (sx-assoc-let data - (sx-method-call 'questions - :id .question_id - :submethod (if undo 'favorite/undo 'favorite) - :auth 'warn - :site .site_par - :url-method 'post - :filter sx-browse-filter))) + (sx-method-post-from-data data (if undo 'favorite/undo 'favorite))) (defalias 'sx-star #'sx-favorite) @@ -268,18 +261,8 @@ DATA can be a question, answer, or comment. TYPE can be Besides posting to the api, DATA is also altered to reflect the changes." (let ((result - (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 (concat type (unless status "/undo")) - :auth 'warn - :url-method 'post - :filter sx-browse-filter - :site .site_par)))) + (sx-method-post-from-data + data (concat type (unless status "/undo"))))) ;; The api returns the new DATA. (when (> (length result) 0) (sx--copy-data (elt result 0) data) @@ -287,6 +270,26 @@ changes." (sx--maybe-update-display)))) +;;; Delete +(defun sx-delete (data &optional undo) + "Delete an object given by DATA. +DATA can be a question, answer, or comment. Interactively, it is +guessed from context at point. +With UNDO prefix argument, undelete instead." + (interactive (list (sx--error-if-unread (sx--data-here)) + current-prefix-arg)) + (when (y-or-n-p (format "DELETE this %s? " + (let-alist data + (cond (.comment_id "comment") + (.answer_id "answer") + (.question_id "question"))))) + (sx-method-post-from-data data (if undo 'delete/undo 'delete)) + ;; Indicate to ourselves this has been deleted. + (setcdr data (cons (car data) (cdr data))) + (setcar data 'deleted) + (sx--maybe-update-display))) + + ;;; Commenting (defun sx-comment (data &optional text) "Post a comment on DATA given by TEXT. |