1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Added /room <role> command

This commit is contained in:
James Booth 2014-10-01 00:27:25 +01:00
parent 76d2b9e9b5
commit 5879f497ad
6 changed files with 100 additions and 1 deletions

View File

@ -1228,6 +1228,9 @@ cmd_init(void)
autocomplete_add(room_ac, "destroy");
autocomplete_add(room_ac, "config");
autocomplete_add(room_ac, "info");
autocomplete_add(room_ac, "moderators");
autocomplete_add(room_ac, "participants");
autocomplete_add(room_ac, "visitors");
form_ac = autocomplete_new();
autocomplete_add(form_ac, "submit");

View File

@ -2063,6 +2063,9 @@ cmd_room(gchar **args, struct cmd_help_t help)
if ((g_strcmp0(args[0], "accept") != 0) &&
(g_strcmp0(args[0], "destroy") != 0) &&
(g_strcmp0(args[0], "config") != 0) &&
(g_strcmp0(args[0], "moderators") != 0) &&
(g_strcmp0(args[0], "participants") != 0) &&
(g_strcmp0(args[0], "visitors") != 0) &&
(g_strcmp0(args[0], "info") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
@ -2082,6 +2085,21 @@ cmd_room(gchar **args, struct cmd_help_t help)
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], "accept") == 0) {
gboolean requires_config = muc_requires_config(room);
if (!requires_config) {

View File

@ -519,6 +519,29 @@ muc_occupant_role_str(Occupant *occupant)
return _role_to_string(occupant->role);
}
GSList *
muc_occupants_by_role(const char * const room, muc_role_t role)
{
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->role == role) {
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

@ -85,7 +85,7 @@ char* muc_old_nick(const char * const room, const char * const new_nick);
gboolean muc_roster_contains_nick(const char * const room, const char * const nick);
gboolean muc_roster_complete(const char * const room);
gboolean muc_roster_add(const char * const room, const char * const nick, const char * const role,
gboolean muc_roster_add(const char * const room, const char * const nick, const char * const role,
const char * const affiliation, const char * const show,
const char * const status);
void muc_roster_remove(const char * const room, const char * const nick);
@ -97,6 +97,7 @@ Occupant* muc_roster_item(const char * const room, const char * const nick);
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);
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

@ -1899,6 +1899,57 @@ _ui_show_room_info(ProfWin *window, const char * const room)
win_save_print(window, '-', NULL, 0, 0, "", "");
}
static void
_ui_show_room_role_list(ProfWin *window, const char * const room, muc_role_t role)
{
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.");
break;
case MUC_ROLE_PARTICIPANT:
win_save_print(window, '!', NULL, 0, 0, "", "No participants found.");
break;
case MUC_ROLE_VISITOR:
win_save_print(window, '!', NULL, 0, 0, "", "No visitors found.");
break;
default:
break;
}
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:");
break;
case MUC_ROLE_PARTICIPANT:
win_save_print(window, '!', NULL, 0, 0, "", "Participants:");
break;
case MUC_ROLE_VISITOR:
win_save_print(window, '!', NULL, 0, 0, "", "Visitors:");
break;
default:
break;
}
GSList *curr_occupant = occupants;
while(curr_occupant) {
Occupant *occupant = curr_occupant->data;
if (occupant->role == role) {
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)
{
@ -2527,4 +2578,5 @@ ui_init_module(void)
ui_show_lines = _ui_show_lines;
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;
}

View File

@ -138,6 +138,8 @@ void (*ui_room_subject)(const char * const room_jid,
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_room_broadcast)(const char * const room_jid,
const char * const message);
void (*ui_room_member_offline)(const char * const room, const char * const nick);