aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/mastodon-tl.el79
-rw-r--r--test/mastodon-tl-tests.el122
2 files changed, 120 insertions, 81 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 3ebcec1..0355a27 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -2102,46 +2102,53 @@ Prefix is sent to `mastodon-tl--show-tag-timeline', which see."
(let ((url (mastodon-http--api "instance/rules")))
(mastodon-http--get-json url nil :silent)))
+(defun mastodon-tl--report-params ()
+ "Query user and return report params alist."
+ (let* ((url (mastodon-http--api "reports"))
+ (toot (mastodon-tl--toot-or-base
+ (mastodon-tl--property 'toot-json :no-move)))
+ (account (alist-get 'account toot))
+ (handle (alist-get 'acct account))
+ (account-id (mastodon-profile--account-field account 'id))
+ (comment (read-string "Add comment [optional]: "))
+ (toot-id (when (y-or-n-p "Also report status at point? ")
+ (mastodon-tl--toot-id toot))) ; base toot if poss
+ (forward-p (when (y-or-n-p "Forward to remote admin? ") "true"))
+ (rules (when (y-or-n-p "Cite a rule broken? ")
+ (mastodon-tl--read-rules-ids)))
+ (cat (unless rules (if (y-or-n-p "Spam? ") "spam" "other")))
+ (params `(("account_id" . ,account-id)
+ ,(when comment
+ `("comment" . ,comment))
+ ,(when toot-id
+ `("status_ids[]" . ,toot-id))
+ ,(when forward-p
+ `("forward" . ,forward-p))
+ ,(when cat
+ `("category" . ,cat)))))
+ (when rules
+ (let ((alist
+ (mastodon-http--build-array-params-alist "rule_ids[]" rules)))
+ (mapc (lambda (x)
+ (push x params))
+ alist)))
+ ;; FIXME: the above approach adds nils to your params.
+ (setq params (delete nil params))
+ params))
+
(defun mastodon-tl--report-to-mods ()
"Report the author of the toot at point to your instance moderators.
-Optionally report the toot at point, optionally add a comment, optionally cite rules that have been broken, optionally forward the report to the remove admin, optionally report the account for spam."
+Optionally report the toot at point, add a comment, cite rules
+that have been broken, forward the report to the remove admin,
+report the account for spam."
(interactive)
- (when (y-or-n-p (format "report author of toot at point?"))
+ (when (y-or-n-p "Report author of toot at point?")
(let* ((url (mastodon-http--api "reports"))
- (toot (mastodon-tl--toot-or-base
- (mastodon-tl--property 'toot-json)))
- (account (alist-get 'account toot))
- (handle (alist-get 'acct account))
- (account-id (mastodon-profile--account-field account 'id))
- (comment (read-string "Add comment [optional]: "))
- (toot-id (when (y-or-n-p "Also report status at point?")
- (mastodon-tl--toot-id toot))) ; base toot if poss
- (forward-p (when (y-or-n-p "Forward to remote admin?") "true"))
- (rules (when (y-or-n-p "Cite a rule broken? ")
- (mastodon-tl--read-rules-ids)))
- (cat (unless rules (if (y-or-n-p "Spam? ") "spam" "other")))
- (params `(("account_id" . ,account-id)
- ,(when comment
- `("comment" . ,comment))
- ,(when toot-id
- `("status_ids[]" . ,toot-id))
- ,(when forward-p
- `("forward" . ,forward-p))
- ,(when cat
- `("category" . ,cat)))))
- (when rules
- (let ((alist
- (mastodon-http--build-array-params-alist "rule_ids[]" rules)))
- (mapc (lambda (x)
- (push x params))
- alist)))
- ;; FIXME: the above approach adds nils to your params.
- (setq params (delete nil params))
- ;; (message "%s" (prin1-to-string params))
- (let ((response (mastodon-http--post-async url params)))
- (mastodon-http--triage response
- (lambda (response)
- (message "User %s reported!" handle)))))))
+ (params (mastodon-tl--report-params))
+ (response (mastodon-http--post-async url params)))
+ (mastodon-http--triage response
+ (lambda (response)
+ (message "User %s reported!" handle))))))
(defun mastodon-tl--read-rules-ids ()
"Prompt for a list of instance rules and return a list of selected ids."
diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el
index a3ac330..f1b4735 100644
--- a/test/mastodon-tl-tests.el
+++ b/test/mastodon-tl-tests.el
@@ -1073,53 +1073,85 @@ correct value for following, as well as notifications enabled or disabled."
(let ((response-buffer-true (current-buffer)))
(insert mastodon-tl--follow-notify-true-response)
(with-mock
- (mock (mastodon-http--post url-follow-only nil)
- => response-buffer-true)
- (should
- (equal
- (mastodon-tl--do-user-action-function url-follow-only
- user-name
- user-handle
- "follow")
- "User some-user (@some-user@instance.url) followed!"))
- (mock (mastodon-http--post url-mute nil)
- => response-buffer-true)
- (should
- (equal
- (mastodon-tl--do-user-action-function url-mute
- user-name
- user-handle
- "mute")
- "User some-user (@some-user@instance.url) muted!"))
- (mock (mastodon-http--post url-block nil)
- => response-buffer-true)
- (should
- (equal
- (mastodon-tl--do-user-action-function url-block
- user-name
- user-handle
- "block")
- "User some-user (@some-user@instance.url) blocked!")))
+ (mock (mastodon-http--post url-follow-only nil)
+ => response-buffer-true)
+ (should
+ (equal
+ (mastodon-tl--do-user-action-function url-follow-only
+ user-name
+ user-handle
+ "follow")
+ "User some-user (@some-user@instance.url) followed!"))
+ (mock (mastodon-http--post url-mute nil)
+ => response-buffer-true)
+ (should
+ (equal
+ (mastodon-tl--do-user-action-function url-mute
+ user-name
+ user-handle
+ "mute")
+ "User some-user (@some-user@instance.url) muted!"))
+ (mock (mastodon-http--post url-block nil)
+ => response-buffer-true)
+ (should
+ (equal
+ (mastodon-tl--do-user-action-function url-block
+ user-name
+ user-handle
+ "block")
+ "User some-user (@some-user@instance.url) blocked!")))
(with-mock
- (mock (mastodon-http--post url-true nil) => response-buffer-true)
- (should
- (equal
- (mastodon-tl--do-user-action-function url-true
- user-name
- user-handle
- "follow"
- "true")
- "Receiving notifications for user some-user (@some-user@instance.url)!")))))
+ (mock (mastodon-http--post url-true nil) => response-buffer-true)
+ (should
+ (equal
+ (mastodon-tl--do-user-action-function url-true
+ user-name
+ user-handle
+ "follow"
+ "true")
+ "Receiving notifications for user some-user (@some-user@instance.url)!")))))
(with-temp-buffer
(let ((response-buffer-false (current-buffer)))
(insert mastodon-tl--follow-notify-false-response)
(with-mock
- (mock (mastodon-http--post url-false nil) => response-buffer-false)
- (should
- (equal
- (mastodon-tl--do-user-action-function url-false
- user-name
- user-handle
- "follow"
- "false")
- "Not receiving notifications for user some-user (@some-user@instance.url)!")))))))
+ (mock (mastodon-http--post url-false nil) => response-buffer-false)
+ (should
+ (equal
+ (mastodon-tl--do-user-action-function url-false
+ user-name
+ user-handle
+ "follow"
+ "false")
+ "Not receiving notifications for user some-user (@some-user@instance.url)!")))))))
+
+(ert-deftest mastodon-tl--report-to-mods-params-alist ()
+ ""
+ (with-temp-buffer
+ (let ((toot mastodon-tl-test-base-toot))
+ (with-mock
+ (mock (mastodon-http--api "reports") => "https://instance.url/api/v1/reports")
+ (mock (mastodon-tl--toot-or-base
+ (mastodon-tl--property 'toot-json :no-move))
+ => mastodon-tl-test-base-toot)
+ (mock (read-string "Add comment [optional]: ") => "Dummy complaint")
+
+ (stub y-or-n-p => nil) ; no to all
+ (should (equal (mastodon-tl--report-params)
+ '(("account_id" . 42)
+ ("comment" . "Dummy complaint")
+ ("category" . "other"))))
+ (with-mock
+ (stub y-or-n-p => t) ; yes to all
+ (mock (mastodon-tl--read-rules-ids) => '(1 2 3))
+ ;; (mock (y-or-n-p "Also report status at point? ") => t)
+ ;; (mock (y-or-n-p "Forward to remote admin? ") => nil)
+ ;; (mock (y-or-n-p "Cite a rule broken? ") => nil)
+ ;; (mock (y-or-n-p "Spam? ") => nil)
+ (should (equal (mastodon-tl--report-params)
+ '(("rule_ids[]" . 3)
+ ("rule_ids[]" . 2)
+ ("rule_ids[]" . 1)
+ ("account_id" . 42)
+ ("comment" . "Dummy complaint")
+ ("status_ids[]" . 61208)
+ ("forward" . "true")))))))))