1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Add option to color MUC history like regular messages

`/logging group color` has:
* `unanimous` which will color it with one unanimous color. Like it was
done always.
* `regular` which colors it like regular incoming messages.

Regards https://github.com/profanity-im/profanity/issues/1261
This commit is contained in:
Michael Vetter 2020-02-20 08:11:58 +01:00
parent 6aa793fca6
commit 80dd3fdbb2
7 changed files with 72 additions and 17 deletions

View File

@ -238,6 +238,8 @@ static Autocomplete invite_ac;
static Autocomplete status_ac;
static Autocomplete status_state_ac;
static Autocomplete logging_ac;
static Autocomplete logging_group_ac;
static Autocomplete logging_group_color_ac;
static Autocomplete color_ac;
static Autocomplete correction_ac;
@ -944,6 +946,15 @@ cmd_ac_init(void)
autocomplete_add(logging_ac, "chat");
autocomplete_add(logging_ac, "group");
logging_group_ac = autocomplete_new();
autocomplete_add(logging_group_ac, "on");
autocomplete_add(logging_group_ac, "off");
autocomplete_add(logging_group_ac, "color");
logging_group_color_ac = autocomplete_new();
autocomplete_add(logging_group_color_ac, "unanimous");
autocomplete_add(logging_group_color_ac, "regular");
color_ac = autocomplete_new();
autocomplete_add(color_ac, "on");
autocomplete_add(color_ac, "off");
@ -1261,6 +1272,8 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(status_ac);
autocomplete_reset(status_state_ac);
autocomplete_reset(logging_ac);
autocomplete_reset(logging_group_ac);
autocomplete_reset(logging_group_color_ac);
autocomplete_reset(color_ac);
autocomplete_reset(correction_ac);
@ -1412,6 +1425,8 @@ cmd_ac_uninit(void)
autocomplete_free(status_ac);
autocomplete_free(status_state_ac);
autocomplete_free(logging_ac);
autocomplete_free(logging_group_ac);
autocomplete_free(logging_group_color_ac);
autocomplete_free(color_ac);
autocomplete_free(correction_ac);
}
@ -3727,7 +3742,12 @@ _logging_autocomplete(ProfWin *window, const char *const input, gboolean previou
return result;
}
result = autocomplete_param_with_func(input, "/logging group", prefs_autocomplete_boolean_choice, previous, NULL);
result = autocomplete_param_with_ac(input, "/logging group", logging_group_ac, TRUE, previous);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/logging group color", logging_group_color_ac, TRUE, previous);
if (result) {
return result;
}

View File

@ -1607,24 +1607,28 @@ static struct cmd_t command_defs[] =
},
{ "/logging",
parse_args, 2, 2, &cons_logging_setting,
parse_args, 2, 3, &cons_logging_setting,
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_logging)
CMD_TAGS(
CMD_TAG_CHAT)
CMD_SYN(
"/logging chat|group on|off")
"/logging chat|group on|off",
"/logging group color unanimous|regular")
CMD_DESC(
"Configure chat logging. "
"Switch logging on or off. "
"Chat logging will be enabled if /history is set to on. "
"When disabling this option, /history will also be disabled. ")
"When disabling this option, /history will also be disabled. "
"Color MUC history unanimously or like regular MUC messages.")
CMD_ARGS(
{ "chat", "Regular chat logging" },
{ "group", "Groupchat (room) logging" },
{ "on|off", "Enable or disable logging." })
{ "chat on|off", "Enable/Disable regular chat logging" },
{ "group on|off", "Enable/Disable groupchat (room) logging" },
{ "group color unanimous|regular", "Color MUC history unanimous or like regular MUC messages." })
CMD_EXAMPLES(
"/logging chat on",
"/logging group off" )
"/logging group off",
"/logging group color regular" )
},
{ "/states",

View File

@ -6721,12 +6721,22 @@ cmd_logging(ProfWin *window, const char *const command, gchar **args)
if (strcmp(args[1], "off") == 0) {
prefs_set_boolean(PREF_HISTORY, FALSE);
}
} else if (strcmp(args[0], "group") == 0) {
_cmd_set_boolean_preference(args[1], command, "Groupchat logging", PREF_GRLOG);
} else {
cons_bad_cmd_usage(command);
return TRUE;
} else if (g_strcmp0(args[0], "group") == 0) {
if (g_strcmp0(args[1], "on") == 0 || g_strcmp0(args[1], "off") == 0) {
_cmd_set_boolean_preference(args[1], command, "Groupchat logging", PREF_GRLOG);
return TRUE;
} else if (strcmp(args[1], "color") == 0 && args[2] != NULL) {
if (g_strcmp0(args[2], "unanimous") == 0 || g_strcmp0(args[2], "regular") == 0) {
prefs_set_string(PREF_HISTORY_COLOR_MUC, args[2]);
cons_show("Groupchat logging color set to: %s", args[2]);
return TRUE;
}
}
}
cons_bad_cmd_usage(command);
return TRUE;
}

View File

@ -1746,6 +1746,7 @@ _get_group(preference_t pref)
case PREF_STATUSBAR_CHAT:
case PREF_STATUSBAR_ROOM:
case PREF_TITLEBAR_MUC_TITLE:
case PREF_HISTORY_COLOR_MUC:
return PREF_GROUP_UI;
case PREF_STATES:
case PREF_OUTTYPE:
@ -2048,6 +2049,8 @@ _get_key(preference_t pref)
return "sendfile";
case PREF_CORRECTION_ALLOW:
return "correction.allow";
case PREF_HISTORY_COLOR_MUC:
return "history.muc.color";
default:
return NULL;
}
@ -2177,6 +2180,8 @@ _get_default_string(preference_t pref)
return "automatic";
case PREF_COLOR_NICK:
return "false";
case PREF_HISTORY_COLOR_MUC:
return "unanimous";
default:
return NULL;
}

View File

@ -165,6 +165,7 @@ typedef enum {
PREF_OMEMO_SENDFILE,
PREF_OCCUPANTS_WRAP,
PREF_CORRECTION_ALLOW,
PREF_HISTORY_COLOR_MUC,
} preference_t;
typedef struct prof_alias_t {

View File

@ -1854,14 +1854,18 @@ void
cons_logging_setting(void)
{
if (prefs_get_boolean(PREF_CHLOG))
cons_show("Chat logging (/logging chat) : ON");
cons_show("Chat logging (/logging chat) : ON");
else
cons_show("Chat logging (/logging chat) : OFF");
cons_show("Chat logging (/logging chat) : OFF");
if (prefs_get_boolean(PREF_GRLOG))
cons_show("Groupchat logging (/logging group) : ON");
cons_show("Groupchat logging (/logging group) : ON");
else
cons_show("Groupchat logging (/logging group) : OFF");
cons_show("Groupchat logging (/logging group) : OFF");
char *pref = prefs_get_string(PREF_HISTORY_COLOR_MUC);
cons_show("MUC history color (/logging group color) : %s", pref);
prefs_free_string(pref);
}
void

View File

@ -380,7 +380,18 @@ mucwin_history(ProfMucWin *mucwin, const ProfMessage *const message)
g_string_append(line, message->plain);
}
win_print_history(window, message->timestamp, line->str);
// 'unanimous' all in one color (like always was)
// 'regular' colored like new messages too
char *muc_history_color = prefs_get_string(PREF_HISTORY_COLOR_MUC);
if (g_strcmp0(muc_history_color, "unanimous") == 0) {
win_print_history(window, message->timestamp, line->str);
} else {
// TODO: actually should call mucwin_incoming_msg() so that mentions and triggers are highlighted too.
// so should put code from sv_ev_room_message() in own function. so that we get the triggers etc.
win_println_incoming_muc_msg(window, '-', 0, message->jid->resourcepart, message->id, message->replace_id, message->plain);
}
g_free(muc_history_color);
g_string_free(line, TRUE);
plugins_on_room_history_message(mucwin->roomjid, nick, message->plain, message->timestamp);