Skip to content

Commit

Permalink
Merge pull request #1910 from H3rnand3zzz/fix/show-char-dry-and-db
Browse files Browse the repository at this point in the history
Show encryption for historical messages
  • Loading branch information
jubalh authored Nov 6, 2023
2 parents 0b957d6 + 7af0e9b commit 83fdd9b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 38 deletions.
10 changes: 1 addition & 9 deletions src/ui/chatwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 2 additions & 16 deletions src/ui/mucwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
43 changes: 30 additions & 13 deletions src/ui/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/ui/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 83fdd9b

Please sign in to comment.