mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Add nickname support for /roster remove
Add support of name/nickname instead of only JID for `/roster remove` command. Add tests for it as well.
This commit is contained in:
parent
766dc76e33
commit
5b8b9074a2
@ -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;
|
||||
}
|
||||
|
@ -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>",
|
||||
|
@ -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);
|
||||
|
@ -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),
|
||||
|
@ -92,6 +92,35 @@ sends_remove_item(void **state)
|
||||
assert_true(prof_output_exact("Roster item removed: buddy1@localhost"));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user