1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05: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_ac;
static Autocomplete status_state_ac; static Autocomplete status_state_ac;
static Autocomplete logging_ac; static Autocomplete logging_ac;
static Autocomplete logging_group_ac;
static Autocomplete logging_group_color_ac;
static Autocomplete color_ac; static Autocomplete color_ac;
static Autocomplete correction_ac; static Autocomplete correction_ac;
@ -944,6 +946,15 @@ cmd_ac_init(void)
autocomplete_add(logging_ac, "chat"); autocomplete_add(logging_ac, "chat");
autocomplete_add(logging_ac, "group"); 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(); color_ac = autocomplete_new();
autocomplete_add(color_ac, "on"); autocomplete_add(color_ac, "on");
autocomplete_add(color_ac, "off"); autocomplete_add(color_ac, "off");
@ -1261,6 +1272,8 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(status_ac); autocomplete_reset(status_ac);
autocomplete_reset(status_state_ac); autocomplete_reset(status_state_ac);
autocomplete_reset(logging_ac); autocomplete_reset(logging_ac);
autocomplete_reset(logging_group_ac);
autocomplete_reset(logging_group_color_ac);
autocomplete_reset(color_ac); autocomplete_reset(color_ac);
autocomplete_reset(correction_ac); autocomplete_reset(correction_ac);
@ -1412,6 +1425,8 @@ cmd_ac_uninit(void)
autocomplete_free(status_ac); autocomplete_free(status_ac);
autocomplete_free(status_state_ac); autocomplete_free(status_state_ac);
autocomplete_free(logging_ac); autocomplete_free(logging_ac);
autocomplete_free(logging_group_ac);
autocomplete_free(logging_group_color_ac);
autocomplete_free(color_ac); autocomplete_free(color_ac);
autocomplete_free(correction_ac); autocomplete_free(correction_ac);
} }
@ -3727,7 +3742,12 @@ _logging_autocomplete(ProfWin *window, const char *const input, gboolean previou
return result; 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) { if (result) {
return result; return result;
} }

View File

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

View File

@ -6721,12 +6721,22 @@ cmd_logging(ProfWin *window, const char *const command, gchar **args)
if (strcmp(args[1], "off") == 0) { if (strcmp(args[1], "off") == 0) {
prefs_set_boolean(PREF_HISTORY, FALSE); prefs_set_boolean(PREF_HISTORY, FALSE);
} }
} else if (strcmp(args[0], "group") == 0) {
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); _cmd_set_boolean_preference(args[1], command, "Groupchat logging", PREF_GRLOG);
} else { return TRUE;
cons_bad_cmd_usage(command); } 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; return TRUE;
} }

View File

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

View File

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

View File

@ -1862,6 +1862,10 @@ cons_logging_setting(void)
cons_show("Groupchat logging (/logging group) : ON"); cons_show("Groupchat logging (/logging group) : ON");
else 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 void

View File

@ -380,7 +380,18 @@ mucwin_history(ProfMucWin *mucwin, const ProfMessage *const message)
g_string_append(line, message->plain); g_string_append(line, message->plain);
} }
// '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); 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); g_string_free(line, TRUE);
plugins_on_room_history_message(mucwin->roomjid, nick, message->plain, message->timestamp); plugins_on_room_history_message(mucwin->roomjid, nick, message->plain, message->timestamp);