1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Show encryption for historical messages

Refactor getting char, introduce get_show_char() to follow DRY principle.

In theory, performance might be negatively affected after this change.

Ideally get_show_char should be optimized in the future.
This commit is contained in:
John Hernandez 2023-11-03 11:27:30 +01:00
parent 0b957d6207
commit 7af0e9b1e1
4 changed files with 35 additions and 38 deletions

View File

@ -433,16 +433,8 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, char* id,
auto_char char* enc_char;
if (chatwin->outgoing_char) {
enc_char = chatwin->outgoing_char;
} else if (enc_mode == PROF_MSG_ENC_OTR) {
enc_char = prefs_get_otr_char();
} else if (enc_mode == PROF_MSG_ENC_PGP) {
enc_char = prefs_get_pgp_char();
} else if (enc_mode == PROF_MSG_ENC_OMEMO) {
enc_char = prefs_get_omemo_char();
} else if (enc_mode == PROF_MSG_ENC_OX) {
enc_char = prefs_get_ox_char();
} else {
enc_char = strdup("-");
enc_char = get_show_char(enc_mode);
}
if (request_receipt && id) {

View File

@ -518,16 +518,8 @@ mucwin_outgoing_msg(ProfMucWin* mucwin, const char* const message, const char* c
auto_char char* ch;
if (mucwin->message_char) {
ch = strdup(mucwin->message_char);
} else if (enc_mode == PROF_MSG_ENC_OTR) {
ch = prefs_get_otr_char();
} else if (enc_mode == PROF_MSG_ENC_PGP) {
ch = prefs_get_pgp_char();
} else if (enc_mode == PROF_MSG_ENC_OMEMO) {
ch = prefs_get_omemo_char();
} else if (enc_mode == PROF_MSG_ENC_OX) {
ch = prefs_get_omemo_char();
} else {
ch = strdup("-");
ch = get_show_char(enc_mode);
}
win_print_outgoing_muc_msg(window, ch, mynick, id, replace_id, message);
@ -566,14 +558,8 @@ mucwin_incoming_msg(ProfMucWin* mucwin, const ProfMessage* const message, GSList
auto_char char* ch;
if (mucwin->message_char) {
ch = strdup(mucwin->message_char);
} else if (message->enc == PROF_MSG_ENC_OTR) {
ch = prefs_get_otr_char();
} else if (message->enc == PROF_MSG_ENC_PGP) {
ch = prefs_get_pgp_char();
} else if (message->enc == PROF_MSG_ENC_OMEMO) {
ch = prefs_get_omemo_char();
} else {
ch = strdup("-");
ch = get_show_char(message->enc);
}
win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);

View File

@ -1394,16 +1394,8 @@ win_print_incoming(ProfWin* window, const char* const display_name_from, ProfMes
if (chatwin->incoming_char) {
enc_char = strdup(chatwin->incoming_char);
} else if (message->enc == PROF_MSG_ENC_OTR) {
enc_char = prefs_get_otr_char();
} else if (message->enc == PROF_MSG_ENC_PGP) {
enc_char = prefs_get_pgp_char();
} else if (message->enc == PROF_MSG_ENC_OX) { // XEP-0373: OpenPGP for XMPP
enc_char = prefs_get_ox_char();
} else if (message->enc == PROF_MSG_ENC_OMEMO) {
enc_char = prefs_get_omemo_char();
} else {
enc_char = strdup("-");
enc_char = get_show_char(message->enc);
}
if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) {
@ -1492,10 +1484,12 @@ win_print_history(ProfWin* window, const ProfMessage* const message)
flags = NO_ME;
}
buffer_append(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
auto_char char* ch = get_show_char(message->enc);
buffer_append(window->layout->buffer, ch, 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
wins_add_urls_ac(window, message, FALSE);
wins_add_quotes_ac(window, message->plain, FALSE);
_win_print_internal(window, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
_win_print_internal(window, ch, 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(message->timestamp);
@ -1518,10 +1512,12 @@ win_print_old_history(ProfWin* window, const ProfMessage* const message)
flags = NO_ME;
}
buffer_prepend(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
auto_char char* ch = get_show_char(message->enc);
buffer_prepend(window->layout->buffer, ch, 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
wins_add_urls_ac(window, message, TRUE);
wins_add_quotes_ac(window, message->plain, TRUE);
_win_print_internal(window, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
_win_print_internal(window, ch, 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(message->timestamp);
@ -2239,3 +2235,24 @@ win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previo
return g_strdup_printf("> %s\n", quoted_result);
}
// Derive encryption char from encryption mode. Output needs to be freed by caller.
char*
get_show_char(prof_enc_t encryption_mode)
{
char* enc_char;
if (encryption_mode == PROF_MSG_ENC_OTR) {
enc_char = prefs_get_otr_char();
} else if (encryption_mode == PROF_MSG_ENC_PGP) {
enc_char = prefs_get_pgp_char();
} else if (encryption_mode == PROF_MSG_ENC_OMEMO) {
enc_char = prefs_get_omemo_char();
} else if (encryption_mode == PROF_MSG_ENC_OX) {
enc_char = prefs_get_ox_char();
} else {
enc_char = strdup("-");
}
return enc_char;
}

View File

@ -98,4 +98,6 @@ void win_remove_entry_message(ProfWin* window, const char* const id);
char* win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previous);
char* get_show_char(prof_enc_t encryption_mode);
#endif