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

Added /privileges command to set UI option for showing roles/affiliations in rooms

This commit is contained in:
James Booth 2014-10-18 20:22:34 +01:00
parent 0cc25e1b76
commit fc049c9eef
10 changed files with 160 additions and 75 deletions

View File

@ -1,5 +1,3 @@
Dont show success message for affiliation/role changes for user changing them
Add config option to not show role/affilation messages and changes
Check all commands from private conversations
Test all freetext args
Make form editing commands less verbose

View File

@ -547,6 +547,17 @@ static struct cmd_t command_defs[] =
"Logout of any current session, and quit Profanity.",
NULL } } },
{ "/privileges",
cmd_privileges, parse_args, 1, 1, &cons_privileges_setting,
{ "/privileges on|off", "Show occupant privileges in chat rooms.",
{ "/privileges on|off",
"---------------------------",
"If enabled:",
"The room roster will be broken down my role.",
"An occupants role and affiliation will be shown when they join a room.",
"Changes to occupant privileges will be shown in the chat room.",
NULL } } },
{ "/beep",
cmd_beep, parse_args, 1, 1, &cons_beep_setting,
{ "/beep on|off", "Terminal beep on new messages.",
@ -1697,7 +1708,7 @@ _cmd_complete_parameters(char *input, int *size)
// autocomplete boolean settings
gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype",
"/flash", "/splash", "/chlog", "/grlog", "/mouse", "/history", "/titlebar",
"/vercheck" };
"/vercheck", "/privileges" };
for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
result = autocomplete_param_with_func(input, size, boolean_choices[i],

View File

@ -590,7 +590,7 @@ cmd_help(gchar **args, struct cmd_help_t help)
} else if (strcmp(args[0], "groupchat") == 0) {
gchar *filter[] = { "/close", "/clear", "/decline", "/grlog",
"/invite", "/invites", "/join", "/leave", "/notify", "/msg",
"/rooms", "/tiny", "/who", "/nick" };
"/rooms", "/tiny", "/who", "/nick", "/privileges" };
_cmd_show_filtered_help("Groupchat commands", filter, ARRAY_SIZE(filter));
} else if (strcmp(args[0], "presence") == 0) {
@ -612,7 +612,7 @@ cmd_help(gchar **args, struct cmd_help_t help)
"/chlog", "/flash", "/gone", "/grlog", "/history", "/intype",
"/log", "/mouse", "/notify", "/outtype", "/prefs", "/priority",
"/reconnect", "/roster", "/splash", "/states", "/statuses", "/theme",
"/titlebar", "/vercheck" };
"/titlebar", "/vercheck", "/privileges" };
_cmd_show_filtered_help("Settings commands", filter, ARRAY_SIZE(filter));
} else if (strcmp(args[0], "navigation") == 0) {
@ -2878,6 +2878,16 @@ cmd_leave(gchar **args, struct cmd_help_t help)
return TRUE;
}
gboolean
cmd_privileges(gchar **args, struct cmd_help_t help)
{
gboolean result = _cmd_set_boolean_preference(args[0], help, "MUC privileges", PREF_MUC_PRIVILEGES);
ui_redraw_all_room_rosters();
return result;
}
gboolean
cmd_beep(gchar **args, struct cmd_help_t help)
{

View File

@ -131,5 +131,6 @@ gboolean cmd_ban(gchar **args, struct cmd_help_t help);
gboolean cmd_subject(gchar **args, struct cmd_help_t help);
gboolean cmd_affiliation(gchar **args, struct cmd_help_t help);
gboolean cmd_role(gchar **args, struct cmd_help_t help);
gboolean cmd_privileges(gchar **args, struct cmd_help_t help);
#endif

View File

@ -436,6 +436,7 @@ _get_group(preference_t pref)
case PREF_STATUSES_CONSOLE:
case PREF_STATUSES_CHAT:
case PREF_STATUSES_MUC:
case PREF_MUC_PRIVILEGES:
return PREF_GROUP_UI;
case PREF_STATES:
case PREF_OUTTYPE:
@ -496,6 +497,8 @@ _get_key(preference_t pref)
return "mouse";
case PREF_OCCUPANTS:
return "occupants";
case PREF_MUC_PRIVILEGES:
return "privileges";
case PREF_STATUSES:
return "statuses";
case PREF_STATUSES_CONSOLE:
@ -570,6 +573,7 @@ _get_default_boolean(preference_t pref)
case PREF_NOTIFY_TYPING_CURRENT:
case PREF_SPLASH:
case PREF_OCCUPANTS:
case PREF_MUC_PRIVILEGES:
return TRUE;
default:
return FALSE;

View File

@ -58,6 +58,7 @@ typedef enum {
PREF_HISTORY,
PREF_MOUSE,
PREF_OCCUPANTS,
PREF_MUC_PRIVILEGES,
PREF_STATUSES,
PREF_STATUSES_CONSOLE,
PREF_STATUSES_CHAT,

View File

@ -707,6 +707,7 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea
// check for change in role/affiliation
} else {
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
// both changed
if ((g_strcmp0(role, old_role) != 0) && (g_strcmp0(affiliation, old_affiliation) != 0)) {
ui_room_role_and_affiliation_change(room, role, affiliation, actor, reason);
@ -720,6 +721,7 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea
ui_room_affiliation_change(room, affiliation, actor, reason);
}
}
}
ui_muc_roster(room);
}
@ -776,6 +778,7 @@ handle_muc_occupant_online(const char * const room, const char * const nick, con
// presence unchanged, check for role/affiliation change
} else {
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
// both changed
if ((g_strcmp0(role, old_role) != 0) && (g_strcmp0(affiliation, old_affiliation) != 0)) {
ui_room_occupant_role_and_affiliation_change(room, nick, role, affiliation, actor, reason);
@ -788,6 +791,7 @@ handle_muc_occupant_online(const char * const room, const char * const nick, con
} else if (g_strcmp0(affiliation, old_affiliation) != 0) {
ui_room_occupant_affiliation_change(room, nick, affiliation, actor, reason);
}
}
ui_muc_roster(room);
}
}

View File

@ -821,6 +821,15 @@ _cons_theme_setting(void)
prefs_free_string(theme);
}
static void
_cons_privileges_setting(void)
{
if (prefs_get_boolean(PREF_MUC_PRIVILEGES))
cons_show("MUC privileges (/privileges) : ON");
else
cons_show("MUC privileges (/privileges) : OFF");
}
static void
_cons_beep_setting(void)
{
@ -926,6 +935,7 @@ _cons_show_ui_prefs(void)
cons_mouse_setting();
cons_statuses_setting();
cons_occupants_setting();
cons_privileges_setting();
cons_titlebar_setting();
cons_alert();
@ -1518,6 +1528,7 @@ console_init_module(void)
cons_show_account_list = _cons_show_account_list;
cons_show_account = _cons_show_account;
cons_theme_setting = _cons_theme_setting;
cons_privileges_setting = _cons_privileges_setting;
cons_beep_setting = _cons_beep_setting;
cons_flash_setting = _cons_flash_setting;
cons_splash_setting = _cons_splash_setting;

View File

@ -670,6 +670,26 @@ _ui_close_read_wins(void)
return count;
}
static void
_ui_redraw_all_room_rosters(void)
{
GList *win_nums = wins_get_nums();
GList *curr = win_nums;
while (curr != NULL) {
int num = GPOINTER_TO_INT(curr->data);
ProfWin *window = wins_get_by_num(num);
if (window->type == WIN_MUC && window->subwin) {
char *room = window->from;
ui_muc_roster(room);
}
curr = g_list_next(curr);
}
g_list_free(curr);
g_list_free(win_nums);
}
static gboolean
_ui_win_has_unsaved_form(int num)
{
@ -1305,15 +1325,17 @@ _ui_room_join(const char * const room, gboolean focus)
}
char *nick = muc_nick(room);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "-> You have joined the room as %s", nick);
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
char *role = muc_role_str(room);
char *affiliation = muc_affiliation_str(room);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "-> You have joined the room as %s", nick);
if (role) {
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", role: %s", role);
}
if (affiliation) {
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", affiliation: %s", affiliation);
}
}
win_save_print(window, '!', NULL, NO_DATE, COLOUR_ROOMINFO, "", "");
num = wins_get_num(window);
@ -1593,12 +1615,14 @@ _ui_room_member_online(const char * const room, const char * const nick, const c
log_error("Received online presence for room participant %s, but no window open for %s.", nick, room);
} else {
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ONLINE, "", "-> %s has joined the room", nick);
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
if (role) {
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", role: %s", role);
}
if (affiliation) {
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", affiliation: %s", affiliation);
}
}
win_save_print(window, '!', NULL, NO_DATE, COLOUR_ROOMINFO, "", "");
}
}
@ -2763,6 +2787,7 @@ _ui_muc_roster(const char * const room)
if (roster) {
werase(window->subwin);
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
wattron(window->subwin, COLOUR_ROOMINFO);
wprintw(window->subwin, " -Moderators\n");
wattroff(window->subwin, COLOUR_ROOMINFO);
@ -2816,6 +2841,23 @@ _ui_muc_roster(const char * const room)
}
roster_curr = g_list_next(roster_curr);
}
} else {
wattron(window->subwin, COLOUR_ROOMINFO);
wprintw(window->subwin, " -Occupants\n");
wattroff(window->subwin, COLOUR_ROOMINFO);
GList *roster_curr = roster;
while (roster_curr) {
Occupant *occupant = roster_curr->data;
wprintw(window->subwin, " ");
const char *presence_str = string_from_resource_presence(occupant->presence);
int presence_colour = win_presence_colour(presence_str);
wattron(window->subwin, presence_colour);
wprintw(window->subwin, occupant->nick);
wattroff(window->subwin, presence_colour);
wprintw(window->subwin, "\n");
roster_curr = g_list_next(roster_curr);
}
}
}
}
}
@ -3137,5 +3179,6 @@ ui_init_module(void)
ui_room_occupant_role_change = _ui_room_occupant_role_change;
ui_room_occupant_affiliation_change = _ui_room_occupant_affiliation_change;
ui_room_occupant_role_and_affiliation_change = _ui_room_occupant_role_and_affiliation_change;
ui_redraw_all_room_rosters = _ui_redraw_all_room_rosters;
}

View File

@ -209,6 +209,7 @@ void (*ui_show_form_field)(ProfWin *window, DataForm *form, char *tag);
void (*ui_show_form_help)(ProfWin *window, DataForm *form);
void (*ui_show_form_field_help)(ProfWin *window, DataForm *form, char *tag);
void (*ui_show_lines)(ProfWin *window, const gchar** lines);
void (*ui_redraw_all_room_rosters)(void);
// contact status functions
void (*ui_status_room)(const char * const contact);
@ -292,6 +293,7 @@ void (*cons_show_received_subs)(void);
void (*cons_show_sent_subs)(void);
void (*cons_alert)(void);
void (*cons_theme_setting)(void);
void (*cons_privileges_setting)(void);
void (*cons_beep_setting)(void);
void (*cons_flash_setting)(void);
void (*cons_splash_setting)(void);