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
This commit is contained in:
Michael Vetter
2021-06-30 23:42:32 +02:00
parent dc79c514be
commit 31ebd6ab1c
5 changed files with 74 additions and 13 deletions

View File

@@ -420,7 +420,7 @@ static struct cmd_t command_defs[] = {
},
{ "/blocked",
parse_args, 0, 2, NULL,
parse_args_with_freetext, 0, 4, NULL,
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_blocked)
CMD_TAGS(
@@ -428,7 +428,7 @@ static struct cmd_t command_defs[] = {
CMD_TAG_CHAT)
CMD_SYN(
"/blocked",
"/blocked add [<jid>]",
"/blocked add [<jid>] [report-abuse|report-spam [<message>]",
"/blocked remove <jid>")
CMD_DESC(
"Manage blocked users (XEP-0191), calling with no arguments shows the current list of blocked users. "
@@ -438,6 +438,7 @@ static struct cmd_t command_defs[] = {
{ "remove <jid>", "Remove the specified Jabber ID from the blocked list." })
CMD_EXAMPLES(
"/blocked add hel@helheim.edda",
"/blocked add hel@helheim.edda report-spam",
"/blocked add profanity@rooms.dismail.de/spammy-user")
},

View File

@@ -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;
// /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];
}
if (jid == NULL) {
cons_bad_cmd_usage(command);
return TRUE;
}
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);
}