1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge /group command into /roster

Fix https://github.com/profanity-im/profanity/issues/1229
Regards https://github.com/profanity-im/profanity/issues/1116
This commit is contained in:
Michael Vetter 2019-11-25 10:40:25 +01:00
parent 548b64f6c5
commit f0a719d1e1
3 changed files with 118 additions and 146 deletions

View File

@ -71,7 +71,6 @@ static char* _autoconnect_autocomplete(ProfWin *window, const char *const input,
static char* _account_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _account_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _who_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _who_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _roster_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _roster_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _group_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _bookmark_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _bookmark_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _otr_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _otr_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _pgp_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _pgp_autocomplete(ProfWin *window, const char *const input, gboolean previous);
@ -441,6 +440,7 @@ cmd_ac_init(void)
autocomplete_add(roster_ac, "resource"); autocomplete_add(roster_ac, "resource");
autocomplete_add(roster_ac, "presence"); autocomplete_add(roster_ac, "presence");
autocomplete_add(roster_ac, "private"); autocomplete_add(roster_ac, "private");
autocomplete_add(roster_ac, "group");
roster_private_ac = autocomplete_new(); roster_private_ac = autocomplete_new();
autocomplete_add(roster_private_ac, "room"); autocomplete_add(roster_private_ac, "room");
@ -1559,7 +1559,6 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
g_hash_table_insert(ac_funcs, "/log", _log_autocomplete); g_hash_table_insert(ac_funcs, "/log", _log_autocomplete);
g_hash_table_insert(ac_funcs, "/account", _account_autocomplete); g_hash_table_insert(ac_funcs, "/account", _account_autocomplete);
g_hash_table_insert(ac_funcs, "/roster", _roster_autocomplete); g_hash_table_insert(ac_funcs, "/roster", _roster_autocomplete);
g_hash_table_insert(ac_funcs, "/group", _group_autocomplete);
g_hash_table_insert(ac_funcs, "/bookmark", _bookmark_autocomplete); g_hash_table_insert(ac_funcs, "/bookmark", _bookmark_autocomplete);
g_hash_table_insert(ac_funcs, "/autoconnect", _autoconnect_autocomplete); g_hash_table_insert(ac_funcs, "/autoconnect", _autoconnect_autocomplete);
g_hash_table_insert(ac_funcs, "/otr", _otr_autocomplete); g_hash_table_insert(ac_funcs, "/otr", _otr_autocomplete);
@ -1788,6 +1787,27 @@ _roster_autocomplete(ProfWin *window, const char *const input, gboolean previous
if (result) { if (result) {
return result; return result;
} }
result = autocomplete_param_with_func(input, "/roster group show", roster_group_autocomplete, previous);
if (result) {
return result;
}
result = autocomplete_param_no_with_func(input, "/roster group add", 5, roster_contact_autocomplete, previous);
if (result) {
return result;
}
result = autocomplete_param_no_with_func(input, "/roster group remove", 5, roster_contact_autocomplete, previous);
if (result) {
return result;
}
result = autocomplete_param_with_func(input, "/roster group add", roster_group_autocomplete, previous);
if (result) {
return result;
}
result = autocomplete_param_with_func(input, "/roster group remove", roster_group_autocomplete, previous);
if (result) {
return result;
}
} }
result = autocomplete_param_with_ac(input, "/roster remove_all", roster_remove_all_ac, TRUE, previous); result = autocomplete_param_with_ac(input, "/roster remove_all", roster_remove_all_ac, TRUE, previous);
@ -1846,45 +1866,11 @@ _roster_autocomplete(ProfWin *window, const char *const input, gboolean previous
if (result) { if (result) {
return result; return result;
} }
result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE, previous); result = autocomplete_param_with_ac(input, "/roster group", group_ac, TRUE, previous);
if (result) { if (result) {
return result; return result;
} }
result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE, previous);
return NULL;
}
static char*
_group_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
char *result = NULL;
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status == JABBER_CONNECTED) {
result = autocomplete_param_with_func(input, "/group show", roster_group_autocomplete, previous);
if (result) {
return result;
}
result = autocomplete_param_no_with_func(input, "/group add", 4, roster_contact_autocomplete, previous);
if (result) {
return result;
}
result = autocomplete_param_no_with_func(input, "/group remove", 4, roster_contact_autocomplete, previous);
if (result) {
return result;
}
result = autocomplete_param_with_func(input, "/group add", roster_group_autocomplete, previous);
if (result) {
return result;
}
result = autocomplete_param_with_func(input, "/group remove", roster_group_autocomplete, previous);
if (result) {
return result;
}
}
result = autocomplete_param_with_ac(input, "/group", group_ac, TRUE, previous);
if (result) { if (result) {
return result; return result;
} }

View File

@ -266,7 +266,8 @@ static struct cmd_t command_defs[] =
{ "/roster", { "/roster",
parse_args_with_freetext, 0, 4, NULL, parse_args_with_freetext, 0, 4, NULL,
CMD_NOSUBFUNCS CMD_SUBFUNCS(
{ "group", cmd_group })
CMD_MAINFUNC(cmd_roster) CMD_MAINFUNC(cmd_roster)
CMD_TAGS( CMD_TAGS(
CMD_TAG_ROSTER, CMD_TAG_ROSTER,
@ -304,80 +305,87 @@ static struct cmd_t command_defs[] =
"/roster remove <jid>", "/roster remove <jid>",
"/roster remove_all contacts", "/roster remove_all contacts",
"/roster nick <jid> <nick>", "/roster nick <jid> <nick>",
"/roster clearnick <jid>") "/roster clearnick <jid>",
"/roster group",
"/roster group show <group>",
"/roster group add <group> <contat>",
"/roster group remove <group> <contact>")
CMD_DESC( CMD_DESC(
"Manage your roster, and roster display settings. " "Manage your roster, and roster display settings. "
"Passing no arguments lists all contacts in your roster.") "Passing no arguments lists all contacts in your roster.")
CMD_ARGS( CMD_ARGS(
{ "online", "Show all online contacts in console." }, { "online", "Show all online contacts in console." },
{ "show", "Show the roster panel." }, { "show", "Show the roster panel." },
{ "show offline", "Show offline contacts in roster panel." }, { "show offline", "Show offline contacts in roster panel." },
{ "show resource", "Show contact's connected resources in roster panel." }, { "show resource", "Show contact's connected resources in roster panel." },
{ "show presence", "Show contact's presence in roster panel." }, { "show presence", "Show contact's presence in roster panel." },
{ "show status", "Show contact's status message in roster panel." }, { "show status", "Show contact's status message in roster panel." },
{ "show empty", "Show empty groups in roster panel." }, { "show empty", "Show empty groups in roster panel." },
{ "show priority", "Show resource priority in roster panel." }, { "show priority", "Show resource priority in roster panel." },
{ "show contacts", "Show contacts in roster panel." }, { "show contacts", "Show contacts in roster panel." },
{ "show rooms", "Show chat rooms in roster panel." }, { "show rooms", "Show chat rooms in roster panel." },
{ "hide", "Hide the roster panel." }, { "hide", "Hide the roster panel." },
{ "hide offline", "Hide offline contacts in roster panel." }, { "hide offline", "Hide offline contacts in roster panel." },
{ "hide resource", "Hide contact's connected resources in roster panel." }, { "hide resource", "Hide contact's connected resources in roster panel." },
{ "hide presence", "Hide contact's presence in roster panel." }, { "hide presence", "Hide contact's presence in roster panel." },
{ "hide status", "Hide contact's status message in roster panel." }, { "hide status", "Hide contact's status message in roster panel." },
{ "hide empty", "Hide empty groups in roster panel." }, { "hide empty", "Hide empty groups in roster panel." },
{ "hide priority", "Hide resource priority in roster panel." }, { "hide priority", "Hide resource priority in roster panel." },
{ "hide contacts", "Hide contacts in roster panel." }, { "hide contacts", "Hide contacts in roster panel." },
{ "hide rooms", "Hide chat rooms in roster panel." }, { "hide rooms", "Hide chat rooms in roster panel." },
{ "by group", "Group contacts in roster panel by roster group." }, { "by group", "Group contacts in roster panel by roster group." },
{ "by presence", "Group contacts in roster panel by presence." }, { "by presence", "Group contacts in roster panel by presence." },
{ "by none", "No grouping in roster panel." }, { "by none", "No grouping in roster panel." },
{ "count unread", "Show unread message count with roster headers." }, { "count unread", "Show unread message count with roster headers." },
{ "count items", "Show item count with roster headers." }, { "count items", "Show item count with roster headers." },
{ "count off", "Do not show any count with roster headers." }, { "count off", "Do not show any count with roster headers." },
{ "count zero on", "Show roster header count when 0." }, { "count zero on", "Show roster header count when 0." },
{ "count zero off", "Hide roster header count when 0." }, { "count zero off", "Hide roster header count when 0." },
{ "order name", "Order roster contacts by name only." }, { "order name", "Order roster contacts by name only." },
{ "order presence", "Order roster contacts by presence, and then by name." }, { "order presence", "Order roster contacts by presence, and then by name." },
{ "unread before", "Show unread message count before contact." }, { "unread before", "Show unread message count before contact." },
{ "unread after", "Show unread message count after contact." }, { "unread after", "Show unread message count after contact." },
{ "unread off", "Do not show unread message count for contacts." }, { "unread off", "Do not show unread message count for contacts." },
{ "room char <char>", "Prefix rooms with specified character." }, { "room char <char>", "Prefix rooms with specified character." },
{ "room char none", "Remove room character prefix." }, { "room char none", "Remove room character prefix." },
{ "room private char <char>", "Prefix private room chat with specified character when displayed with room." }, { "room private char <char>", "Prefix private room chat with specified character when displayed with room." },
{ "room private char none", "Remove private room chat character prefix when displayed with room." }, { "room private char none", "Remove private room chat character prefix when displayed with room." },
{ "room position first", "Show rooms first in roster." }, { "room position first", "Show rooms first in roster." },
{ "room position last", "Show rooms last in roster." }, { "room position last", "Show rooms last in roster." },
{ "room by service", "Group rooms by chat service." }, { "room by service", "Group rooms by chat service." },
{ "room by none", "Do not group rooms." }, { "room by none", "Do not group rooms." },
{ "room order name", "Order rooms by name." }, { "room order name", "Order rooms by name." },
{ "room order unread", "Order rooms by unread messages, and then by name." }, { "room order unread", "Order rooms by unread messages, and then by name." },
{ "room unread before", "Show unread message count before room." }, { "room unread before", "Show unread message count before room." },
{ "room unread after", "Show unread message count after room." }, { "room unread after", "Show unread message count after room." },
{ "room unread off", "Do not show unread message count for rooms." }, { "room unread off", "Do not show unread message count for rooms." },
{ "room show server", "Show the conference server with room JIDs." }, { "room show server", "Show the conference server with room JIDs." },
{ "room hide server", "Do not show the conference server with room JIDs." }, { "room hide server", "Do not show the conference server with room JIDs." },
{ "private room", "Show room private chats with the room." }, { "private room", "Show room private chats with the room." },
{ "private group", "Show room private chats as a separate roster group." }, { "private group", "Show room private chats as a separate roster group." },
{ "private off", "Do not show room private chats." }, { "private off", "Do not show room private chats." },
{ "private char <char>", "Prefix private room chats with specified character when displayed in separate group." }, { "private char <char>", "Prefix private room chats with specified character when displayed in separate group." },
{ "private char none", "Remove private room chat character prefix." }, { "private char none", "Remove private room chat character prefix." },
{ "header char <char>", "Prefix roster headers with specified character." }, { "header char <char>", "Prefix roster headers with specified character." },
{ "header char none", "Remove roster header character prefix." }, { "header char none", "Remove roster header character prefix." },
{ "contact char <char>", "Prefix roster contacts with specified character." }, { "contact char <char>", "Prefix roster contacts with specified character." },
{ "contact char none", "Remove roster contact character prefix." }, { "contact char none", "Remove roster contact character prefix." },
{ "contact indent <indent>", "Indent contact line by <indent> spaces (0 to 10)." }, { "contact indent <indent>", "Indent contact line by <indent> spaces (0 to 10)." },
{ "resource char <char>", "Prefix roster resources with specified character." }, { "resource char <char>", "Prefix roster resources with specified character." },
{ "resource char none", "Remove roster resource character prefix." }, { "resource char none", "Remove roster resource character prefix." },
{ "resource indent <indent>", "Indent resource line by <indent> spaces (0 to 10)." }, { "resource indent <indent>", "Indent resource line by <indent> spaces (0 to 10)." },
{ "resource join on|off", "Join resource with previous line when only one available resource." }, { "resource join on|off", "Join resource with previous line when only one available resource." },
{ "presence indent <indent>", "Indent presence line by <indent> spaces (-1 to 10), a value of -1 will show presence on the previous line." }, { "presence indent <indent>", "Indent presence line by <indent> spaces (-1 to 10), a value of -1 will show presence on the previous line." },
{ "size <percent>", "Percentage of the screen taken up by the roster (1-99)." }, { "size <percent>", "Percentage of the screen taken up by the roster (1-99)." },
{ "wrap on|off", "Enable or disable line wrapping in roster panel." }, { "wrap on|off", "Enable or disable line wrapping in roster panel." },
{ "add <jid> [<nick>]", "Add a new item to the roster." }, { "add <jid> [<nick>]", "Add a new item to the roster." },
{ "remove <jid>", "Removes an item from the roster." }, { "remove <jid>", "Removes an item from the roster." },
{ "remove_all contacts", "Remove all items from roster." }, { "remove_all contacts", "Remove all items from roster." },
{ "nick <jid> <nick>", "Change a contacts nickname." }, { "nick <jid> <nick>", "Change a contacts nickname." },
{ "clearnick <jid>", "Removes the current nickname." }) { "clearnick <jid>", "Removes the current nickname." },
{ "group show <group>", "List all roster items in a group." },
{ "group add <group> <contact>", "Add a contact to a group." },
{ "group remove <group> <contact>", "Remove a contact from a group." })
CMD_EXAMPLES( CMD_EXAMPLES(
"/roster", "/roster",
"/roster add someone@contacts.org", "/roster add someone@contacts.org",
@ -385,7 +393,12 @@ static struct cmd_t command_defs[] =
"/roster remove someone@contacts.org", "/roster remove someone@contacts.org",
"/roster nick myfriend@chat.org \"My Friend\"", "/roster nick myfriend@chat.org \"My Friend\"",
"/roster clearnick kai@server.com", "/roster clearnick kai@server.com",
"/roster size 15") "/roster size 15",
"/roster group",
"/roster group show friends",
"/roster group add friends newfriend@server.org",
"/roster group add family Brother",
"/roster group remove colleagues boss@work.com")
}, },
{ "/blocked", { "/blocked",
@ -410,33 +423,6 @@ static struct cmd_t command_defs[] =
"/blocked add profanity@rooms.dismail.de/spammy-user") "/blocked add profanity@rooms.dismail.de/spammy-user")
}, },
{ "/group",
parse_args_with_freetext, 0, 3, NULL,
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_group)
CMD_TAGS(
CMD_TAG_ROSTER,
CMD_TAG_UI)
CMD_SYN(
"/group",
"/group show <group>",
"/group add <group> <contat>",
"/group remove <group> <contact>")
CMD_DESC(
"View, add to, and remove from roster groups. "
"Passing no argument will list all roster groups.")
CMD_ARGS(
{ "show <group>", "List all roster items in a group." },
{ "add <group> <contact>", "Add a contact to a group." },
{ "remove <group> <contact>", "Remove a contact from a group." })
CMD_EXAMPLES(
"/group",
"/group show friends",
"/group add friends newfriend@server.org",
"/group add family Brother",
"/group remove colleagues boss@work.com")
},
{ "/info", { "/info",
parse_args, 0, 1, NULL, parse_args, 0, 1, NULL,
CMD_NOSUBFUNCS CMD_NOSUBFUNCS

View File

@ -2230,7 +2230,7 @@ cmd_group(ProfWin *window, const char *const command, gchar **args)
} }
// list all groups // list all groups
if (args[0] == NULL) { if (args[1] == NULL) {
GList *groups = roster_get_groups(); GList *groups = roster_get_groups();
GList *curr = groups; GList *curr = groups;
if (curr) { if (curr) {
@ -2248,8 +2248,8 @@ cmd_group(ProfWin *window, const char *const command, gchar **args)
} }
// show contacts in group // show contacts in group
if (strcmp(args[0], "show") == 0) { if (strcmp(args[1], "show") == 0) {
char *group = args[1]; char *group = args[2];
if (group == NULL) { if (group == NULL) {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
return TRUE; return TRUE;
@ -2261,9 +2261,9 @@ cmd_group(ProfWin *window, const char *const command, gchar **args)
} }
// add contact to group // add contact to group
if (strcmp(args[0], "add") == 0) { if (strcmp(args[1], "add") == 0) {
char *group = args[1]; char *group = args[2];
char *contact = args[2]; char *contact = args[3];
if ((group == NULL) || (contact == NULL)) { if ((group == NULL) || (contact == NULL)) {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
@ -2292,9 +2292,9 @@ cmd_group(ProfWin *window, const char *const command, gchar **args)
} }
// remove contact from group // remove contact from group
if (strcmp(args[0], "remove") == 0) { if (strcmp(args[1], "remove") == 0) {
char *group = args[1]; char *group = args[2];
char *contact = args[2]; char *contact = args[3];
if ((group == NULL) || (contact == NULL)) { if ((group == NULL) || (contact == NULL)) {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);