mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Split autocompleters for roster and rooms
This commit is contained in:
parent
2d05601259
commit
719dbfaacc
@ -937,7 +937,8 @@ static struct cmd_t command_defs[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
static Autocomplete commands_ac;
|
static Autocomplete commands_ac;
|
||||||
static Autocomplete who_ac;
|
static Autocomplete who_room_ac;
|
||||||
|
static Autocomplete who_roster_ac;
|
||||||
static Autocomplete help_ac;
|
static Autocomplete help_ac;
|
||||||
static Autocomplete notify_ac;
|
static Autocomplete notify_ac;
|
||||||
static Autocomplete notify_room_ac;
|
static Autocomplete notify_room_ac;
|
||||||
@ -1152,16 +1153,32 @@ cmd_init(void)
|
|||||||
|
|
||||||
theme_load_ac = NULL;
|
theme_load_ac = NULL;
|
||||||
|
|
||||||
who_ac = autocomplete_new();
|
who_roster_ac = autocomplete_new();
|
||||||
autocomplete_add(who_ac, "chat");
|
autocomplete_add(who_roster_ac, "chat");
|
||||||
autocomplete_add(who_ac, "online");
|
autocomplete_add(who_roster_ac, "online");
|
||||||
autocomplete_add(who_ac, "away");
|
autocomplete_add(who_roster_ac, "away");
|
||||||
autocomplete_add(who_ac, "xa");
|
autocomplete_add(who_roster_ac, "xa");
|
||||||
autocomplete_add(who_ac, "dnd");
|
autocomplete_add(who_roster_ac, "dnd");
|
||||||
autocomplete_add(who_ac, "offline");
|
autocomplete_add(who_roster_ac, "offline");
|
||||||
autocomplete_add(who_ac, "available");
|
autocomplete_add(who_roster_ac, "available");
|
||||||
autocomplete_add(who_ac, "unavailable");
|
autocomplete_add(who_roster_ac, "unavailable");
|
||||||
autocomplete_add(who_ac, "any");
|
autocomplete_add(who_roster_ac, "any");
|
||||||
|
|
||||||
|
who_room_ac = autocomplete_new();
|
||||||
|
autocomplete_add(who_room_ac, "chat");
|
||||||
|
autocomplete_add(who_room_ac, "online");
|
||||||
|
autocomplete_add(who_room_ac, "away");
|
||||||
|
autocomplete_add(who_room_ac, "xa");
|
||||||
|
autocomplete_add(who_room_ac, "dnd");
|
||||||
|
autocomplete_add(who_room_ac, "available");
|
||||||
|
autocomplete_add(who_room_ac, "unavailable");
|
||||||
|
autocomplete_add(who_room_ac, "moderator");
|
||||||
|
autocomplete_add(who_room_ac, "participant");
|
||||||
|
autocomplete_add(who_room_ac, "visitor");
|
||||||
|
autocomplete_add(who_room_ac, "owner");
|
||||||
|
autocomplete_add(who_room_ac, "admin");
|
||||||
|
autocomplete_add(who_room_ac, "member");
|
||||||
|
autocomplete_add(who_room_ac, "outcast");
|
||||||
|
|
||||||
bookmark_ac = autocomplete_new();
|
bookmark_ac = autocomplete_new();
|
||||||
autocomplete_add(bookmark_ac, "list");
|
autocomplete_add(bookmark_ac, "list");
|
||||||
@ -1253,7 +1270,8 @@ void
|
|||||||
cmd_uninit(void)
|
cmd_uninit(void)
|
||||||
{
|
{
|
||||||
autocomplete_free(commands_ac);
|
autocomplete_free(commands_ac);
|
||||||
autocomplete_free(who_ac);
|
autocomplete_free(who_room_ac);
|
||||||
|
autocomplete_free(who_roster_ac);
|
||||||
autocomplete_free(help_ac);
|
autocomplete_free(help_ac);
|
||||||
autocomplete_free(notify_ac);
|
autocomplete_free(notify_ac);
|
||||||
autocomplete_free(notify_message_ac);
|
autocomplete_free(notify_message_ac);
|
||||||
@ -1381,7 +1399,8 @@ cmd_reset_autocomplete()
|
|||||||
muc_autocomplete_reset(recipient);
|
muc_autocomplete_reset(recipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
autocomplete_reset(who_ac);
|
autocomplete_reset(who_room_ac);
|
||||||
|
autocomplete_reset(who_roster_ac);
|
||||||
autocomplete_reset(prefs_ac);
|
autocomplete_reset(prefs_ac);
|
||||||
autocomplete_reset(log_ac);
|
autocomplete_reset(log_ac);
|
||||||
autocomplete_reset(commands_ac);
|
autocomplete_reset(commands_ac);
|
||||||
@ -1753,22 +1772,31 @@ _sub_autocomplete(char *input, int *size)
|
|||||||
static char *
|
static char *
|
||||||
_who_autocomplete(char *input, int *size)
|
_who_autocomplete(char *input, int *size)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
gchar *group_commands[] = { "/who any", "/who online", "/who offline",
|
win_type_t win_type = ui_current_win_type();
|
||||||
"/who chat", "/who away", "/who xa", "/who dnd", "/who available",
|
|
||||||
"/who unavailable" };
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(group_commands); i++) {
|
if (win_type == WIN_MUC) {
|
||||||
result = autocomplete_param_with_func(input, size, group_commands[i], roster_find_group);
|
result = autocomplete_param_with_ac(input, size, "/who", who_room_ac, TRUE);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
int i = 0;
|
||||||
|
gchar *group_commands[] = { "/who any", "/who online", "/who offline",
|
||||||
|
"/who chat", "/who away", "/who xa", "/who dnd", "/who available",
|
||||||
|
"/who unavailable" };
|
||||||
|
|
||||||
result = autocomplete_param_with_ac(input, size, "/who", who_ac, TRUE);
|
for (i = 0; i < ARRAY_SIZE(group_commands); i++) {
|
||||||
if (result != NULL) {
|
result = autocomplete_param_with_func(input, size, group_commands[i], roster_find_group);
|
||||||
return result;
|
if (result != NULL) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = autocomplete_param_with_ac(input, size, "/who", who_roster_ac, TRUE);
|
||||||
|
if (result != NULL) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -725,75 +725,128 @@ cmd_theme(gchar **args, struct cmd_help_t help)
|
|||||||
static void
|
static void
|
||||||
_who_room(gchar **args, struct cmd_help_t help)
|
_who_room(gchar **args, struct cmd_help_t help)
|
||||||
{
|
{
|
||||||
char *presence = args[0];
|
|
||||||
if ((g_strv_length(args) == 2) && (args[1] != NULL)) {
|
if ((g_strv_length(args) == 2) && (args[1] != NULL)) {
|
||||||
cons_show("Argument group is not applicable to chat rooms.");
|
cons_show("Argument group is not applicable to chat rooms.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bad arg
|
// bad arg
|
||||||
if ((presence != NULL)
|
if (args[0] != NULL &&
|
||||||
&& (strcmp(presence, "online") != 0)
|
(g_strcmp0(args[0], "online") != 0) &&
|
||||||
&& (strcmp(presence, "available") != 0)
|
(g_strcmp0(args[0], "available") != 0) &&
|
||||||
&& (strcmp(presence, "unavailable") != 0)
|
(g_strcmp0(args[0], "unavailable") != 0) &&
|
||||||
&& (strcmp(presence, "away") != 0)
|
(g_strcmp0(args[0], "away") != 0) &&
|
||||||
&& (strcmp(presence, "chat") != 0)
|
(g_strcmp0(args[0], "chat") != 0) &&
|
||||||
&& (strcmp(presence, "xa") != 0)
|
(g_strcmp0(args[0], "xa") != 0) &&
|
||||||
&& (strcmp(presence, "dnd") != 0)
|
(g_strcmp0(args[0], "dnd") != 0) &&
|
||||||
&& (strcmp(presence, "any") != 0)) {
|
(g_strcmp0(args[0], "any") != 0) &&
|
||||||
|
(g_strcmp0(args[0], "moderator") != 0) &&
|
||||||
|
(g_strcmp0(args[0], "participant") != 0) &&
|
||||||
|
(g_strcmp0(args[0], "visitor") != 0) &&
|
||||||
|
(g_strcmp0(args[0], "owner") != 0) &&
|
||||||
|
(g_strcmp0(args[0], "admin") != 0) &&
|
||||||
|
(g_strcmp0(args[0], "member") != 0) &&
|
||||||
|
(g_strcmp0(args[0], "outcast") != 0)) {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *room = ui_current_recipient();
|
char *room = ui_current_recipient();
|
||||||
GList *list = muc_roster(room);
|
|
||||||
|
|
||||||
// no arg, show all contacts
|
// presence filter
|
||||||
if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
|
if (args[0] == NULL ||
|
||||||
ui_room_roster(room, list, NULL);
|
(g_strcmp0(args[0], "online") == 0) ||
|
||||||
|
(g_strcmp0(args[0], "available") == 0) ||
|
||||||
|
(g_strcmp0(args[0], "unavailable") == 0) ||
|
||||||
|
(g_strcmp0(args[0], "away") == 0) ||
|
||||||
|
(g_strcmp0(args[0], "chat") == 0) ||
|
||||||
|
(g_strcmp0(args[0], "xa") == 0) ||
|
||||||
|
(g_strcmp0(args[0], "dnd") == 0) ||
|
||||||
|
(g_strcmp0(args[0], "any") == 0)) {
|
||||||
|
|
||||||
// available
|
char *presence = args[0];
|
||||||
} else if (strcmp("available", presence) == 0) {
|
GList *list = muc_roster(room);
|
||||||
GList *filtered = NULL;
|
|
||||||
|
|
||||||
while (list != NULL) {
|
// no arg, show all contacts
|
||||||
Occupant *occupant = list->data;
|
if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
|
||||||
if (muc_occupant_available(occupant)) {
|
ui_room_roster(room, list, NULL);
|
||||||
filtered = g_list_append(filtered, occupant);
|
|
||||||
|
// available
|
||||||
|
} else if (strcmp("available", presence) == 0) {
|
||||||
|
GList *filtered = NULL;
|
||||||
|
|
||||||
|
while (list != NULL) {
|
||||||
|
Occupant *occupant = list->data;
|
||||||
|
if (muc_occupant_available(occupant)) {
|
||||||
|
filtered = g_list_append(filtered, occupant);
|
||||||
|
}
|
||||||
|
list = g_list_next(list);
|
||||||
}
|
}
|
||||||
list = g_list_next(list);
|
|
||||||
|
ui_room_roster(room, filtered, "available");
|
||||||
|
|
||||||
|
// unavailable
|
||||||
|
} else if (strcmp("unavailable", presence) == 0) {
|
||||||
|
GList *filtered = NULL;
|
||||||
|
|
||||||
|
while (list != NULL) {
|
||||||
|
Occupant *occupant = list->data;
|
||||||
|
if (!muc_occupant_available(occupant)) {
|
||||||
|
filtered = g_list_append(filtered, occupant);
|
||||||
|
}
|
||||||
|
list = g_list_next(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_room_roster(room, filtered, "unavailable");
|
||||||
|
|
||||||
|
// show specific status
|
||||||
|
} else {
|
||||||
|
GList *filtered = NULL;
|
||||||
|
|
||||||
|
while (list != NULL) {
|
||||||
|
Occupant *occupant = list->data;
|
||||||
|
const char *presence_str = string_from_resource_presence(occupant->presence);
|
||||||
|
if (strcmp(presence_str, presence) == 0) {
|
||||||
|
filtered = g_list_append(filtered, occupant);
|
||||||
|
}
|
||||||
|
list = g_list_next(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_room_roster(room, filtered, presence);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_room_roster(room, filtered, "available");
|
// role or affiliation filter
|
||||||
|
|
||||||
// unavailable
|
|
||||||
} else if (strcmp("unavailable", presence) == 0) {
|
|
||||||
GList *filtered = NULL;
|
|
||||||
|
|
||||||
while (list != NULL) {
|
|
||||||
Occupant *occupant = list->data;
|
|
||||||
if (!muc_occupant_available(occupant)) {
|
|
||||||
filtered = g_list_append(filtered, occupant);
|
|
||||||
}
|
|
||||||
list = g_list_next(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_room_roster(room, filtered, "unavailable");
|
|
||||||
|
|
||||||
// show specific status
|
|
||||||
} else {
|
} else {
|
||||||
GList *filtered = NULL;
|
ProfWin *window = wins_get_by_recipient(room);
|
||||||
|
if (g_strcmp0(args[0], "moderator") == 0) {
|
||||||
while (list != NULL) {
|
ui_show_room_role_list(window, room, MUC_ROLE_MODERATOR);
|
||||||
Occupant *occupant = list->data;
|
return;
|
||||||
const char *presence_str = string_from_resource_presence(occupant->presence);
|
}
|
||||||
if (strcmp(presence_str, presence) == 0) {
|
if (g_strcmp0(args[0], "participant") == 0) {
|
||||||
filtered = g_list_append(filtered, occupant);
|
ui_show_room_role_list(window, room, MUC_ROLE_PARTICIPANT);
|
||||||
}
|
return;
|
||||||
list = g_list_next(list);
|
}
|
||||||
|
if (g_strcmp0(args[0], "visitor") == 0) {
|
||||||
|
ui_show_room_role_list(window, room, MUC_ROLE_VISITOR);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_room_roster(room, filtered, presence);
|
if (g_strcmp0(args[0], "owner") == 0) {
|
||||||
|
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OWNER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (g_strcmp0(args[0], "admin") == 0) {
|
||||||
|
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_ADMIN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (g_strcmp0(args[0], "member") == 0) {
|
||||||
|
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_MEMBER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (g_strcmp0(args[0], "outcast") == 0) {
|
||||||
|
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OUTCAST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1006,12 +1059,10 @@ cmd_who(gchar **args, struct cmd_help_t help)
|
|||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
|
} else if (win_type == WIN_MUC) {
|
||||||
|
_who_room(args, help);
|
||||||
} else {
|
} else {
|
||||||
if (win_type == WIN_MUC) {
|
_who_roster(args, help);
|
||||||
_who_room(args, help);
|
|
||||||
} else {
|
|
||||||
_who_roster(args, help);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (win_type != WIN_CONSOLE && win_type != WIN_MUC) {
|
if (win_type != WIN_CONSOLE && win_type != WIN_MUC) {
|
||||||
@ -2075,13 +2126,18 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
if ((g_strcmp0(args[0], "accept") != 0) &&
|
if ((g_strcmp0(args[0], "accept") != 0) &&
|
||||||
(g_strcmp0(args[0], "destroy") != 0) &&
|
(g_strcmp0(args[0], "destroy") != 0) &&
|
||||||
(g_strcmp0(args[0], "config") != 0) &&
|
(g_strcmp0(args[0], "config") != 0) &&
|
||||||
|
|
||||||
|
// roles
|
||||||
(g_strcmp0(args[0], "moderators") != 0) &&
|
(g_strcmp0(args[0], "moderators") != 0) &&
|
||||||
(g_strcmp0(args[0], "participants") != 0) &&
|
(g_strcmp0(args[0], "participants") != 0) &&
|
||||||
(g_strcmp0(args[0], "visitors") != 0) &&
|
(g_strcmp0(args[0], "visitors") != 0) &&
|
||||||
|
|
||||||
|
// affiliations
|
||||||
(g_strcmp0(args[0], "owners") != 0) &&
|
(g_strcmp0(args[0], "owners") != 0) &&
|
||||||
(g_strcmp0(args[0], "admins") != 0) &&
|
(g_strcmp0(args[0], "admins") != 0) &&
|
||||||
(g_strcmp0(args[0], "members") != 0) &&
|
(g_strcmp0(args[0], "members") != 0) &&
|
||||||
(g_strcmp0(args[0], "outcasts") != 0) &&
|
(g_strcmp0(args[0], "outcasts") != 0) &&
|
||||||
|
|
||||||
(g_strcmp0(args[0], "info") != 0)) {
|
(g_strcmp0(args[0], "info") != 0)) {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -2102,19 +2158,6 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "moderators") == 0) {
|
|
||||||
ui_show_room_role_list(window, room, MUC_ROLE_MODERATOR);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
if (g_strcmp0(args[0], "participants") == 0) {
|
|
||||||
ui_show_room_role_list(window, room, MUC_ROLE_PARTICIPANT);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
if (g_strcmp0(args[0], "visitors") == 0) {
|
|
||||||
ui_show_room_role_list(window, room, MUC_ROLE_VISITOR);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "owners") == 0) {
|
if (g_strcmp0(args[0], "owners") == 0) {
|
||||||
if ((g_strcmp0(args[1], "add") == 0) || (g_strcmp0(args[1], "remove") == 0)) {
|
if ((g_strcmp0(args[1], "add") == 0) || (g_strcmp0(args[1], "remove") == 0)) {
|
||||||
char *nick = args[2];
|
char *nick = args[2];
|
||||||
@ -2156,24 +2199,9 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
}
|
}
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
|
||||||
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OWNER);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (g_strcmp0(args[0], "admins") == 0) {
|
|
||||||
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_ADMIN);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (g_strcmp0(args[0], "members") == 0) {
|
|
||||||
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_MEMBER);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
if (g_strcmp0(args[0], "outcasts") == 0) {
|
|
||||||
ui_show_room_affiliation_list(window, room, MUC_AFFILIATION_OUTCAST);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "accept") == 0) {
|
if (g_strcmp0(args[0], "accept") == 0) {
|
||||||
gboolean requires_config = muc_requires_config(room);
|
gboolean requires_config = muc_requires_config(room);
|
||||||
|
Loading…
Reference in New Issue
Block a user