diff options
author | Michael Vetter <jubalh@iodoru.org> | 2023-04-14 13:13:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-14 13:13:18 +0200 |
commit | ebec68821fa816ca181892919bd878e69d35810d (patch) | |
tree | fdcf6666c4c3aef3fe63043b6bcb52e3cd6caeb8 | |
parent | 766dc76e337c96e71edc698a8ee292014293c44f (diff) | |
parent | 5b8b9074a294e32cbec5f64f61d867dbf0ca1d51 (diff) | |
download | profani-tty-ebec68821fa816ca181892919bd878e69d35810d.tar.gz |
Merge pull request #1826 from H3rnand3zzz/feature/roster-nickname-remove
Add nickname support for `/roster remove`
-rw-r--r-- | src/command/cmd_ac.c | 2 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 2 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 13 | ||||
-rw-r--r-- | tests/functionaltests/functionaltests.c | 1 | ||||
-rw-r--r-- | tests/functionaltests/test_roster.c | 29 | ||||
-rw-r--r-- | tests/functionaltests/test_roster.h | 1 | ||||
-rw-r--r-- | tests/unittests/test_cmd_roster.c | 22 | ||||
-rw-r--r-- | tests/unittests/test_cmd_roster.h | 1 | ||||
-rw-r--r-- | tests/unittests/unittests.c | 1 |
9 files changed, 65 insertions, 7 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 3561449e..5678dbff 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2292,7 +2292,7 @@ _roster_autocomplete(ProfWin* window, const char* const input, gboolean previous if (result) { return result; } - result = autocomplete_param_with_func(input, "/roster remove", roster_barejid_autocomplete, previous, NULL); + result = autocomplete_param_with_func(input, "/roster remove", roster_contact_autocomplete, previous, NULL); if (result) { return result; } diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 12ebf4a1..fe993e39 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -290,7 +290,7 @@ static const struct cmd_t command_defs[] = { "/roster size <percent>", "/roster wrap on|off", "/roster add <jid> [<nick>]", - "/roster remove <jid>", + "/roster remove <contact>", "/roster remove_all contacts", "/roster nick <jid> <nick>", "/roster clearnick <jid>", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index f6736156..7c533a45 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -2922,14 +2922,17 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) cons_show("You are not currently connected."); return TRUE; } - char* jid = args[1]; - if (jid == NULL) { + char* usr = args[1]; + if (usr == NULL) { cons_bad_cmd_usage(command); - } else { - roster_send_remove(jid); + return TRUE; } + char* barejid = roster_barejid_from_name(usr); + if (barejid == NULL) { + barejid = usr; + } + roster_send_remove(barejid); return TRUE; - } else if (strcmp(args[0], "remove_all") == 0) { if (g_strcmp0(args[1], "contacts") != 0) { cons_bad_cmd_usage(command); diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index 5e8656b7..bee95ad3 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -83,6 +83,7 @@ int main(int argc, char* argv[]) { PROF_FUNC_TEST(sends_new_item), PROF_FUNC_TEST(sends_new_item_nick), PROF_FUNC_TEST(sends_remove_item), + PROF_FUNC_TEST(sends_remove_item_nick), PROF_FUNC_TEST(sends_nick_change), PROF_FUNC_TEST(send_software_version_request), diff --git a/tests/functionaltests/test_roster.c b/tests/functionaltests/test_roster.c index aa06016e..c16764be 100644 --- a/tests/functionaltests/test_roster.c +++ b/tests/functionaltests/test_roster.c @@ -93,6 +93,35 @@ sends_remove_item(void **state) } void +sends_remove_item_nick(void **state) +{ + prof_connect_with_roster( + "<item jid='buddy1@localhost' name='Bobby' subscription='both'/>" + "<item jid='buddy2@localhost' subscription='both'/>" + ); + + stbbr_for_query("jabber:iq:roster", + "<iq id='*' type='set'>" + "<query xmlns='jabber:iq:roster'>" + "<item jid='buddy1@localhost' subscription='remove'/>" + "</query>" + "</iq>" + ); + + prof_input("/roster remove Bobby"); + + assert_true(stbbr_received( + "<iq type='set' id='*'>" + "<query xmlns='jabber:iq:roster'>" + "<item jid='buddy1@localhost' subscription='remove'/>" + "</query>" + "</iq>" + )); + + assert_true(prof_output_exact("Roster item removed: buddy1@localhost")); +} + +void sends_nick_change(void **state) { prof_connect_with_roster( diff --git a/tests/functionaltests/test_roster.h b/tests/functionaltests/test_roster.h index 9b34e82a..885dfc55 100644 --- a/tests/functionaltests/test_roster.h +++ b/tests/functionaltests/test_roster.h @@ -1,4 +1,5 @@ void sends_new_item(void **state); void sends_new_item_nick(void **state); void sends_remove_item(void **state); +void sends_remove_item_nick(void **state); void sends_nick_change(void **state); diff --git a/tests/unittests/test_cmd_roster.c b/tests/unittests/test_cmd_roster.c index 3908ba58..d848235b 100644 --- a/tests/unittests/test_cmd_roster.c +++ b/tests/unittests/test_cmd_roster.c @@ -114,12 +114,34 @@ cmd_roster_remove_sends_roster_remove_request(void** state) char* jid = "bob@server.org"; gchar* args[] = { "remove", jid, NULL }; + roster_create(); + roster_add("bob@server.org", "bob", NULL, "both", FALSE); + + will_return(connection_get_status, JABBER_CONNECTED); + + expect_string(roster_send_remove, barejid, jid); + + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); + assert_true(result); + roster_destroy(); +} + +void +cmd_roster_remove_nickname_sends_roster_remove_request(void** state) +{ + char* jid = "bob@server.org"; + gchar* args[] = { "remove", "bob", NULL }; + + roster_create(); + roster_add("bob@server.org", "bob", NULL, "both", FALSE); + will_return(connection_get_status, JABBER_CONNECTED); expect_string(roster_send_remove, barejid, jid); gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); + roster_destroy(); } void diff --git a/tests/unittests/test_cmd_roster.h b/tests/unittests/test_cmd_roster.h index 49bd8db3..bc57f267 100644 --- a/tests/unittests/test_cmd_roster.h +++ b/tests/unittests/test_cmd_roster.h @@ -7,6 +7,7 @@ void cmd_roster_add_shows_message_when_no_jid(void** state); void cmd_roster_add_sends_roster_add_request(void** state); void cmd_roster_remove_shows_message_when_no_jid(void** state); void cmd_roster_remove_sends_roster_remove_request(void** state); +void cmd_roster_remove_nickname_sends_roster_remove_request(void** state); void cmd_roster_nick_shows_message_when_no_jid(void** state); void cmd_roster_nick_shows_message_when_no_nick(void** state); void cmd_roster_nick_shows_message_when_no_contact_exists(void** state); diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index 2724aaa2..30f18c5c 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -584,6 +584,7 @@ main(int argc, char* argv[]) unit_test(cmd_roster_add_sends_roster_add_request), unit_test(cmd_roster_remove_shows_message_when_no_jid), unit_test(cmd_roster_remove_sends_roster_remove_request), + unit_test(cmd_roster_remove_nickname_sends_roster_remove_request), unit_test(cmd_roster_nick_shows_message_when_no_jid), unit_test(cmd_roster_nick_shows_message_when_no_nick), unit_test(cmd_roster_nick_shows_message_when_no_contact_exists), |