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

Display special char for encrypted messages

This commit is contained in:
James Booth 2015-08-26 00:42:56 +01:00
parent 4b0ee89fa3
commit f998ab8f3b
7 changed files with 55 additions and 31 deletions

View File

@ -97,13 +97,13 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
if (!handled) { if (!handled) {
char *id = message_send_chat(chatwin->barejid, msg); char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id); ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_NONE);
free(id); free(id);
} }
} else { // enc_mode = PROF_ENC_PGP } else { // enc_mode = PROF_ENC_PGP
char *id = message_send_chat_pgp(chatwin->barejid, msg); char *id = message_send_chat_pgp(chatwin->barejid, msg);
chat_log_pgp_msg_out(chatwin->barejid, msg); chat_log_pgp_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id); ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_PGP);
free(id); free(id);
} }
return; return;
@ -117,7 +117,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
if (!handled) { if (!handled) {
char *id = message_send_chat(chatwin->barejid, msg); char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id); ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_NONE);
free(id); free(id);
} }
return; return;
@ -131,12 +131,12 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
if (enc_mode == PROF_ENC_NONE) { if (enc_mode == PROF_ENC_NONE) {
char *id = message_send_chat(chatwin->barejid, msg); char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id); ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_NONE);
free(id); free(id);
} else if (enc_mode == PROF_ENC_PGP) { } else if (enc_mode == PROF_ENC_PGP) {
char *id = message_send_chat_pgp(chatwin->barejid, msg); char *id = message_send_chat_pgp(chatwin->barejid, msg);
chat_log_pgp_msg_out(chatwin->barejid, msg); chat_log_pgp_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id); ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_PGP);
free(id); free(id);
} }
return; return;
@ -148,7 +148,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
#ifndef HAVE_LIBGPGME #ifndef HAVE_LIBGPGME
char *id = message_send_chat(chatwin->barejid, msg); char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id); ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_NONE;
free(id); free(id);
return; return;
#endif #endif

View File

@ -187,7 +187,7 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message)
new_win = TRUE; new_win = TRUE;
} }
ui_incoming_msg(chatwin, resource, message, NULL, new_win); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
} }
@ -215,12 +215,12 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
if (enc_mode == PROF_ENC_NONE) { if (enc_mode == PROF_ENC_NONE) {
win_println((ProfWin*)chatwin, 0, "PGP encryption enabled."); win_println((ProfWin*)chatwin, 0, "PGP encryption enabled.");
} }
ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win); ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win, PROF_ENC_PGP);
chat_log_pgp_msg_in(barejid, decrypted); chat_log_pgp_msg_in(barejid, decrypted);
chatwin->enc_mode = PROF_ENC_PGP; chatwin->enc_mode = PROF_ENC_PGP;
p_gpg_free_decrypted(decrypted); p_gpg_free_decrypted(decrypted);
} else { } else {
ui_incoming_msg(chatwin, resource, message, NULL, new_win); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
chatwin->enc_mode = PROF_ENC_NONE; chatwin->enc_mode = PROF_ENC_NONE;
} }
@ -228,14 +228,18 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
} else { } else {
if (enc_mode == PROF_ENC_PGP) { if (enc_mode == PROF_ENC_PGP) {
win_println((ProfWin*)chatwin, 0, "PGP encryption disabled."); win_println((ProfWin*)chatwin, 0, "PGP encryption disabled.");
ui_incoming_msg(chatwin, resource, message, NULL, new_win); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
chatwin->enc_mode = PROF_ENC_NONE; chatwin->enc_mode = PROF_ENC_NONE;
} else { } else {
gboolean decrypted = FALSE; gboolean decrypted = FALSE;
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted); char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
if (otr_res) { if (otr_res) {
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win); if (decrypted && g_strrstr(message, otr_res) == NULL) {
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_OTR);
} else {
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_NONE);
}
chat_log_otr_msg_in(barejid, otr_res, decrypted); chat_log_otr_msg_in(barejid, otr_res, decrypted);
otr_free_message(otr_res); otr_free_message(otr_res);
} }
@ -251,7 +255,11 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
gboolean decrypted = FALSE; gboolean decrypted = FALSE;
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted); char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
if (otr_res) { if (otr_res) {
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win); if (decrypted && g_strrstr(message, otr_res) == NULL) {
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_OTR);
} else {
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_NONE);
}
chat_log_otr_msg_in(barejid, otr_res, decrypted); chat_log_otr_msg_in(barejid, otr_res, decrypted);
otr_free_message(otr_res); otr_free_message(otr_res);
} }
@ -265,17 +273,17 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
if (enc_message) { if (enc_message) {
char *decrypted = p_gpg_decrypt(enc_message); char *decrypted = p_gpg_decrypt(enc_message);
if (decrypted) { if (decrypted) {
ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win); ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win, PROF_ENC_PGP);
chat_log_pgp_msg_in(barejid, decrypted); chat_log_pgp_msg_in(barejid, decrypted);
chatwin->enc_mode = PROF_ENC_PGP; chatwin->enc_mode = PROF_ENC_PGP;
p_gpg_free_decrypted(decrypted); p_gpg_free_decrypted(decrypted);
} else { } else {
ui_incoming_msg(chatwin, resource, message, NULL, new_win); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
chatwin->enc_mode = PROF_ENC_NONE; chatwin->enc_mode = PROF_ENC_NONE;
} }
} else { } else {
ui_incoming_msg(chatwin, resource, message, NULL, new_win); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
chatwin->enc_mode = PROF_ENC_NONE; chatwin->enc_mode = PROF_ENC_NONE;
} }
@ -286,7 +294,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
// OTR unsupported, PGP unsupported // OTR unsupported, PGP unsupported
#ifndef HAVE_LIBOTR #ifndef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME #ifndef HAVE_LIBGPGME
ui_incoming_msg(chatwin, resource, message, NULL, new_win); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
chatwin->enc_mode = PROF_ENC_NONE; chatwin->enc_mode = PROF_ENC_NONE;
return; return;
@ -311,7 +319,7 @@ sv_ev_delayed_message(char *barejid, char *message, GDateTime *timestamp)
new_win = TRUE; new_win = TRUE;
} }
ui_incoming_msg(chatwin, NULL, message, timestamp, new_win); ui_incoming_msg(chatwin, NULL, message, timestamp, new_win, PROF_ENC_NONE);
chat_log_msg_in_delayed(barejid, message, timestamp); chat_log_msg_in_delayed(barejid, message, timestamp);
} }

View File

@ -325,7 +325,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char * const message)
if (encrypted) { if (encrypted) {
id = message_send_chat_otr(chatwin->barejid, encrypted); id = message_send_chat_otr(chatwin->barejid, encrypted);
chat_log_otr_msg_out(chatwin->barejid, message); chat_log_otr_msg_out(chatwin->barejid, message);
ui_outgoing_chat_msg(chatwin, message, id); ui_outgoing_chat_msg(chatwin, message, id, PROF_ENC_OTR);
otr_free_message(encrypted); otr_free_message(encrypted);
free(id); free(id);
return TRUE; return TRUE;
@ -345,7 +345,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char * const message)
if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
char *otr_tagged_msg = otr_tag_message(message); char *otr_tagged_msg = otr_tag_message(message);
id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg); id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg);
ui_outgoing_chat_msg(chatwin, message, id); ui_outgoing_chat_msg(chatwin, message, id, PROF_ENC_NONE);
chat_log_msg_out(chatwin->barejid, message); chat_log_msg_out(chatwin->barejid, message);
free(otr_tagged_msg); free(otr_tagged_msg);
free(id); free(id);

View File

@ -412,7 +412,7 @@ ui_message_receipt(const char * const barejid, const char * const id)
} }
void void
ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created) ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode)
{ {
ProfWin *window = (ProfWin*)chatwin; ProfWin *window = (ProfWin*)chatwin;
int num = wins_get_num(window); int num = wins_get_num(window);
@ -421,7 +421,7 @@ ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char *
// currently viewing chat window with sender // currently viewing chat window with sender
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_print_incoming_message(window, timestamp, display_name, message); win_print_incoming_message(window, timestamp, display_name, message, enc_mode);
title_bar_set_typing(FALSE); title_bar_set_typing(FALSE);
status_bar_active(num); status_bar_active(num);
@ -447,7 +447,7 @@ ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char *
} }
} }
win_print_incoming_message(window, timestamp, display_name, message); win_print_incoming_message(window, timestamp, display_name, message, enc_mode);
} }
if (prefs_get_boolean(PREF_BEEP)) { if (prefs_get_boolean(PREF_BEEP)) {
@ -478,7 +478,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
// currently viewing chat window with sender // currently viewing chat window with sender
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_print_incoming_message(window, timestamp, display_from, message); win_print_incoming_message(window, timestamp, display_from, message, PROF_ENC_NONE);
title_bar_set_typing(FALSE); title_bar_set_typing(FALSE);
status_bar_active(num); status_bar_active(num);
@ -487,7 +487,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
privatewin->unread++; privatewin->unread++;
status_bar_new(num); status_bar_new(num);
cons_show_incoming_message(display_from, num); cons_show_incoming_message(display_from, num);
win_print_incoming_message(window, timestamp, display_from, message); win_print_incoming_message(window, timestamp, display_from, message, PROF_ENC_NONE);
if (prefs_get_boolean(PREF_FLASH)) { if (prefs_get_boolean(PREF_FLASH)) {
flash(); flash();
@ -1287,12 +1287,19 @@ ui_new_chat_win(const char * const barejid)
} }
void void
ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id) ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode)
{ {
char enc_char = '-';
if (enc_mode == PROF_ENC_OTR) {
enc_char = 'O';
} else if (enc_mode == PROF_ENC_PGP) {
enc_char = 'P';
}
if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) { if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) {
win_print_with_receipt((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message, id); win_print_with_receipt((ProfWin*)chatwin, enc_char, 0, NULL, 0, THEME_TEXT_ME, "me", message, id);
} else { } else {
win_print((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); win_print((ProfWin*)chatwin, enc_char, 0, NULL, 0, THEME_TEXT_ME, "me", message);
} }
} }

View File

@ -102,14 +102,14 @@ void ui_handle_stanza(const char * const msg);
// ui events // ui events
void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity); void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity);
void ui_contact_typing(const char * const barejid, const char * const resource); void ui_contact_typing(const char * const barejid, const char * const resource);
void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created); void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode);
void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp); void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp);
void ui_message_receipt(const char * const barejid, const char * const id); void ui_message_receipt(const char * const barejid, const char * const id);
void ui_disconnected(void); void ui_disconnected(void);
void ui_recipient_gone(const char * const barejid, const char * const resource); void ui_recipient_gone(const char * const barejid, const char * const resource);
void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id); void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode);
void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message); void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message);
void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message); void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message);

View File

@ -877,11 +877,20 @@ win_show_status_string(ProfWin *window, const char * const from,
void void
win_print_incoming_message(ProfWin *window, GDateTime *timestamp, win_print_incoming_message(ProfWin *window, GDateTime *timestamp,
const char * const from, const char * const message) const char * const from, const char * const message, prof_enc_t enc_mode)
{ {
char enc_char = '-';
switch (window->type) switch (window->type)
{ {
case WIN_CHAT: case WIN_CHAT:
if (enc_mode == PROF_ENC_OTR) {
enc_char = 'O';
} else if (enc_mode == PROF_ENC_PGP) {
enc_char = 'P';
}
win_print(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message);
break;
case WIN_PRIVATE: case WIN_PRIVATE:
win_print(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message); win_print(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message);
break; break;

View File

@ -60,7 +60,7 @@ void win_show_status_string(ProfWin *window, const char * const from,
GDateTime *last_activity, const char * const pre, GDateTime *last_activity, const char * const pre,
const char * const default_show); const char * const default_show);
void win_print_incoming_message(ProfWin *window, GDateTime *timestamp, void win_print_incoming_message(ProfWin *window, GDateTime *timestamp,
const char * const from, const char * const message); const char * const from, const char * const message, prof_enc_t enc_mode);
void win_print_with_receipt(ProfWin *window, const char show_char, int pad_indent, GTimeVal *tstamp, int flags, void win_print_with_receipt(ProfWin *window, const char show_char, int pad_indent, GTimeVal *tstamp, int flags,
theme_item_t theme_item, const char * const from, const char * const message, char *id); theme_item_t theme_item, const char * const from, const char * const message, char *id);
void win_newline(ProfWin *window); void win_newline(ProfWin *window);