1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-09 21:30:42 +00:00

Merge pull request #1826 from H3rnand3zzz/feature/roster-nickname-remove

Add nickname support for `/roster remove`
This commit is contained in:
Michael Vetter 2023-04-14 13:13:18 +02:00 committed by GitHub
commit ebec68821f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 7 deletions

View File

@ -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;
}

View File

@ -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>",

View File

@ -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);

View File

@ -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),

View File

@ -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)
{

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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),