1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added /room <affiliation> command

This commit is contained in:
James Booth 2014-10-01 00:46:58 +01:00
parent 5879f497ad
commit c90f4a37a3
7 changed files with 107 additions and 6 deletions

View File

@ -1231,6 +1231,10 @@ cmd_init(void)
autocomplete_add(room_ac, "moderators");
autocomplete_add(room_ac, "participants");
autocomplete_add(room_ac, "visitors");
autocomplete_add(room_ac, "owners");
autocomplete_add(room_ac, "admins");
autocomplete_add(room_ac, "members");
autocomplete_add(room_ac, "outcasts");
form_ac = autocomplete_new();
autocomplete_add(form_ac, "submit");

View File

@ -2066,6 +2066,10 @@ cmd_room(gchar **args, struct cmd_help_t help)
(g_strcmp0(args[0], "moderators") != 0) &&
(g_strcmp0(args[0], "participants") != 0) &&
(g_strcmp0(args[0], "visitors") != 0) &&
(g_strcmp0(args[0], "owners") != 0) &&
(g_strcmp0(args[0], "admins") != 0) &&
(g_strcmp0(args[0], "members") != 0) &&
(g_strcmp0(args[0], "outcasts") != 0) &&
(g_strcmp0(args[0], "info") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
@ -2089,17 +2093,33 @@ cmd_room(gchar **args, struct cmd_help_t help)
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) {
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;
}
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) {
gboolean requires_config = muc_requires_config(room);
if (!requires_config) {

View File

@ -542,6 +542,29 @@ muc_occupants_by_role(const char * const room, muc_role_t role)
}
}
GSList *
muc_occupants_by_affiliation(const char * const room, muc_affiliation_t affiliation)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room) {
GSList *result = NULL;
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, chat_room->roster);
while (g_hash_table_iter_next(&iter, &key, &value)) {
Occupant *occupant = (Occupant *)value;
if (occupant->affiliation == affiliation) {
result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_occupants);
}
}
return result;
} else {
return NULL;
}
}
/*
* Remove the old_nick from the roster, and flag that a pending nickname change
* is in progress

View File

@ -98,6 +98,7 @@ gboolean muc_occupant_available(Occupant *occupant);
const char * muc_occupant_affiliation_str(Occupant *occupant);
const char * muc_occupant_role_str(Occupant *occupant);
GSList * muc_occupants_by_role(const char * const room, muc_role_t role);
GSList * muc_occupants_by_affiliation(const char * const room, muc_affiliation_t affiliation);
void muc_roster_nick_change_start(const char * const room, const char * const new_nick, const char * const old_nick);
char* muc_roster_nick_change_complete(const char * const room, const char * const nick);

View File

@ -1892,7 +1892,6 @@ _ui_show_room_info(ProfWin *window, const char * const room)
char *role = muc_role_str(room);
char *affiliation = muc_affiliation_str(room);
win_save_print(window, '-', NULL, 0, 0, "", "");
win_save_vprint(window, '!', NULL, 0, 0, "", "Room: %s", room);
win_save_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", affiliation);
win_save_vprint(window, '!', NULL, 0, 0, "", " Role: %s", role);
@ -1905,7 +1904,6 @@ _ui_show_room_role_list(ProfWin *window, const char * const room, muc_role_t rol
GSList *occupants = muc_occupants_by_role(room, role);
if (!occupants) {
win_save_print(window, '-', NULL, 0, 0, "", "");
switch (role) {
case MUC_ROLE_MODERATOR:
win_save_print(window, '!', NULL, 0, 0, "", "No moderators found.");
@ -1921,7 +1919,6 @@ _ui_show_room_role_list(ProfWin *window, const char * const room, muc_role_t rol
}
win_save_print(window, '-', NULL, 0, 0, "", "");
} else {
win_save_print(window, '-', NULL, 0, 0, "", "");
switch (role) {
case MUC_ROLE_MODERATOR:
win_save_print(window, '!', NULL, 0, 0, "", "Moderators:");
@ -1950,6 +1947,61 @@ _ui_show_room_role_list(ProfWin *window, const char * const room, muc_role_t rol
}
}
static void
_ui_show_room_affiliation_list(ProfWin *window, const char * const room, muc_affiliation_t affiliation)
{
GSList *occupants = muc_occupants_by_affiliation(room, affiliation);
if (!occupants) {
switch (affiliation) {
case MUC_AFFILIATION_OWNER:
win_save_print(window, '!', NULL, 0, 0, "", "No owners found.");
break;
case MUC_AFFILIATION_ADMIN:
win_save_print(window, '!', NULL, 0, 0, "", "No admins found.");
break;
case MUC_AFFILIATION_MEMBER:
win_save_print(window, '!', NULL, 0, 0, "", "No members found.");
break;
case MUC_AFFILIATION_OUTCAST:
win_save_print(window, '!', NULL, 0, 0, "", "No outcasts found.");
break;
default:
break;
}
win_save_print(window, '-', NULL, 0, 0, "", "");
} else {
switch (affiliation) {
case MUC_AFFILIATION_OWNER:
win_save_print(window, '!', NULL, 0, 0, "", "Owners:");
break;
case MUC_AFFILIATION_ADMIN:
win_save_print(window, '!', NULL, 0, 0, "", "Admins:");
break;
case MUC_AFFILIATION_MEMBER:
win_save_print(window, '!', NULL, 0, 0, "", "Members:");
break;
case MUC_AFFILIATION_OUTCAST:
win_save_print(window, '!', NULL, 0, 0, "", "Outcasts:");
break;
default:
break;
}
GSList *curr_occupant = occupants;
while(curr_occupant) {
Occupant *occupant = curr_occupant->data;
if (occupant->affiliation == affiliation) {
win_save_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick);
}
curr_occupant = g_slist_next(curr_occupant);
}
win_save_print(window, '-', NULL, 0, 0, "", "");
}
}
static void
_ui_handle_form_field(ProfWin *window, char *tag, FormField *field)
{
@ -2579,4 +2631,5 @@ ui_init_module(void)
ui_handle_room_configuration_form_error = _ui_handle_room_configuration_form_error;
ui_show_room_info = _ui_show_room_info;
ui_show_room_role_list = _ui_show_room_role_list;
ui_show_room_affiliation_list = _ui_show_room_affiliation_list;
}

View File

@ -139,6 +139,7 @@ void (*ui_room_requires_config)(const char * const room_jid);
void (*ui_room_destroyed)(const char * const room_jid);
void (*ui_show_room_info)(ProfWin *window, const char * const room);
void (*ui_show_room_role_list)(ProfWin *window, const char * const room, muc_role_t role);
void (*ui_show_room_affiliation_list)(ProfWin *window, const char * const room, muc_affiliation_t affiliation);
void (*ui_room_broadcast)(const char * const room_jid,
const char * const message);

View File

@ -195,7 +195,6 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
int presence_colour = win_presence_colour(presence_str);
win_save_print(window, '-', NULL, 0, 0, "", "");
win_save_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick);
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);