about summary refs log tree commit diff stats
path: root/src/command/cmd_funcs.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-06-30 23:42:32 +0200
committerMichael Vetter <jubalh@iodoru.org>2021-07-01 00:14:32 +0200
commit31ebd6ab1cb464c66b1555e5d78896a46d092cc9 (patch)
tree674b49364a0e962c2b836f0fc36c5e38500f4511 /src/command/cmd_funcs.c
parentdc79c514be403cff93a1165b47d456182a03fd05 (diff)
downloadprofani-tty-31ebd6ab1cb464c66b1555e5d78896a46d092cc9.tar.gz
Add XEP-0377: Spam Reporting
Report and block:
`/blocked add someone@domain.org report-abuse This is not nice`
`/blocked add someone@domain.org report-spam This is not nice`

Regular block:
`/blocked add someone@domain.org`

Implement https://github.com/profanity-im/profanity/issues/1434
Diffstat (limited to 'src/command/cmd_funcs.c')
-rw-r--r--src/command/cmd_funcs.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index e1108982..094e6527 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -3014,17 +3014,41 @@ cmd_blocked(ProfWin* window, const char* const command, gchar** args)
 
     if (g_strcmp0(args[0], "add") == 0) {
         char* jid = args[1];
-        if (jid == NULL && (window->type == WIN_CHAT)) {
-            ProfChatWin* chatwin = (ProfChatWin*)window;
-            jid = chatwin->barejid;
-        }
+        char* msg = NULL;
+        blocked_report br = BLOCKED_NO_REPORT;
 
-        if (jid == NULL) {
-            cons_bad_cmd_usage(command);
-            return TRUE;
+        // /blocked add jid or /blocked add (in window)
+        if (g_strv_length(args) < 3) {
+            if (jid == NULL && (window->type == WIN_CHAT)) {
+                ProfChatWin* chatwin = (ProfChatWin*)window;
+                jid = chatwin->barejid;
+            }
+
+            if (jid == NULL) {
+                cons_bad_cmd_usage(command);
+                return TRUE;
+            }
+
+        } else {
+            if (args[2] && g_strcmp0(args[2], "report-abuse") == 0) {
+                br = BLOCKED_REPORT_ABUSE;
+            } else if (args[2] && g_strcmp0(args[2], "report-abuse") == 0) {
+                br = BLOCKED_REPORT_SPAM;
+            } else {
+                cons_bad_cmd_usage(command);
+                return TRUE;
+            }
+
+            if (!connection_supports(XMPP_FEATURE_SPAM_REPORTING)) {
+                cons_show("Spam reporting not supported by server.");
+                return TRUE;
+            }
+
+            msg = args[3];
         }
 
-        gboolean res = blocked_add(jid);
+        // args[3] is optional message
+        gboolean res = blocked_add(jid, br, msg);
         if (!res) {
             cons_show("User %s already blocked.", jid);
         }