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:
parent
5879f497ad
commit
c90f4a37a3
@ -1231,6 +1231,10 @@ cmd_init(void)
|
|||||||
autocomplete_add(room_ac, "moderators");
|
autocomplete_add(room_ac, "moderators");
|
||||||
autocomplete_add(room_ac, "participants");
|
autocomplete_add(room_ac, "participants");
|
||||||
autocomplete_add(room_ac, "visitors");
|
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();
|
form_ac = autocomplete_new();
|
||||||
autocomplete_add(form_ac, "submit");
|
autocomplete_add(form_ac, "submit");
|
||||||
|
@ -2066,6 +2066,10 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
(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) &&
|
||||||
|
(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)) {
|
(g_strcmp0(args[0], "info") != 0)) {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return TRUE;
|
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);
|
ui_show_room_role_list(window, room, MUC_ROLE_MODERATOR);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "participants") == 0) {
|
if (g_strcmp0(args[0], "participants") == 0) {
|
||||||
ui_show_room_role_list(window, room, MUC_ROLE_PARTICIPANT);
|
ui_show_room_role_list(window, room, MUC_ROLE_PARTICIPANT);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "visitors") == 0) {
|
if (g_strcmp0(args[0], "visitors") == 0) {
|
||||||
ui_show_room_role_list(window, room, MUC_ROLE_VISITOR);
|
ui_show_room_role_list(window, room, MUC_ROLE_VISITOR);
|
||||||
return TRUE;
|
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) {
|
if (g_strcmp0(args[0], "accept") == 0) {
|
||||||
gboolean requires_config = muc_requires_config(room);
|
gboolean requires_config = muc_requires_config(room);
|
||||||
if (!requires_config) {
|
if (!requires_config) {
|
||||||
|
23
src/muc.c
23
src/muc.c
@ -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
|
* Remove the old_nick from the roster, and flag that a pending nickname change
|
||||||
* is in progress
|
* is in progress
|
||||||
|
@ -98,6 +98,7 @@ gboolean muc_occupant_available(Occupant *occupant);
|
|||||||
const char * muc_occupant_affiliation_str(Occupant *occupant);
|
const char * muc_occupant_affiliation_str(Occupant *occupant);
|
||||||
const char * muc_occupant_role_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_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);
|
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);
|
char* muc_roster_nick_change_complete(const char * const room, const char * const nick);
|
||||||
|
@ -1892,7 +1892,6 @@ _ui_show_room_info(ProfWin *window, const char * const room)
|
|||||||
char *role = muc_role_str(room);
|
char *role = muc_role_str(room);
|
||||||
char *affiliation = muc_affiliation_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, "", "Room: %s", room);
|
||||||
win_save_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", affiliation);
|
win_save_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", affiliation);
|
||||||
win_save_vprint(window, '!', NULL, 0, 0, "", " Role: %s", role);
|
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);
|
GSList *occupants = muc_occupants_by_role(room, role);
|
||||||
|
|
||||||
if (!occupants) {
|
if (!occupants) {
|
||||||
win_save_print(window, '-', NULL, 0, 0, "", "");
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case MUC_ROLE_MODERATOR:
|
case MUC_ROLE_MODERATOR:
|
||||||
win_save_print(window, '!', NULL, 0, 0, "", "No moderators found.");
|
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, "", "");
|
win_save_print(window, '-', NULL, 0, 0, "", "");
|
||||||
} else {
|
} else {
|
||||||
win_save_print(window, '-', NULL, 0, 0, "", "");
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case MUC_ROLE_MODERATOR:
|
case MUC_ROLE_MODERATOR:
|
||||||
win_save_print(window, '!', NULL, 0, 0, "", "Moderators:");
|
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
|
static void
|
||||||
_ui_handle_form_field(ProfWin *window, char *tag, FormField *field)
|
_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_handle_room_configuration_form_error = _ui_handle_room_configuration_form_error;
|
||||||
ui_show_room_info = _ui_show_room_info;
|
ui_show_room_info = _ui_show_room_info;
|
||||||
ui_show_room_role_list = _ui_show_room_role_list;
|
ui_show_room_role_list = _ui_show_room_role_list;
|
||||||
|
ui_show_room_affiliation_list = _ui_show_room_affiliation_list;
|
||||||
}
|
}
|
||||||
|
@ -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_room_destroyed)(const char * const room_jid);
|
||||||
void (*ui_show_room_info)(ProfWin *window, const char * const room);
|
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_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,
|
void (*ui_room_broadcast)(const char * const room_jid,
|
||||||
const char * const message);
|
const char * const message);
|
||||||
|
@ -195,7 +195,6 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
|
|||||||
|
|
||||||
int presence_colour = win_presence_colour(presence_str);
|
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_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick);
|
||||||
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
|
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user