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) {
char *id = message_send_chat(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);
}
} else { // enc_mode = PROF_ENC_PGP
char *id = message_send_chat_pgp(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);
}
return;
@ -117,7 +117,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
if (!handled) {
char *id = message_send_chat(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);
}
return;
@ -131,12 +131,12 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
if (enc_mode == PROF_ENC_NONE) {
char *id = message_send_chat(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);
} else if (enc_mode == PROF_ENC_PGP) {
char *id = message_send_chat_pgp(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);
}
return;
@ -148,7 +148,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
#ifndef HAVE_LIBGPGME
char *id = message_send_chat(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);
return;
#endif

View File

@ -187,7 +187,7 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message)
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);
}
@ -215,12 +215,12 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
if (enc_mode == PROF_ENC_NONE) {
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);
chatwin->enc_mode = PROF_ENC_PGP;
p_gpg_free_decrypted(decrypted);
} 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);
chatwin->enc_mode = PROF_ENC_NONE;
}
@ -228,14 +228,18 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
} else {
if (enc_mode == PROF_ENC_PGP) {
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);
chatwin->enc_mode = PROF_ENC_NONE;
} else {
gboolean decrypted = FALSE;
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
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);
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;
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
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);
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) {
char *decrypted = p_gpg_decrypt(enc_message);
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);
chatwin->enc_mode = PROF_ENC_PGP;
p_gpg_free_decrypted(decrypted);
} 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);
chatwin->enc_mode = PROF_ENC_NONE;
}
} 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);
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
#ifndef HAVE_LIBOTR
#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);
chatwin->enc_mode = PROF_ENC_NONE;
return;
@ -311,7 +319,7 @@ sv_ev_delayed_message(char *barejid, char *message, GDateTime *timestamp)
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);
}

View File

@ -325,7 +325,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char * const message)
if (encrypted) {
id = message_send_chat_otr(chatwin->barejid, encrypted);
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);
free(id);
return TRUE;
@ -345,7 +345,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char * const message)
if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
char *otr_tagged_msg = otr_tag_message(message);
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);
free(otr_tagged_msg);
free(id);

View File

@ -412,7 +412,7 @@ ui_message_receipt(const char * const barejid, const char * const id)
}
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;
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
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);
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)) {
@ -478,7 +478,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
// currently viewing chat window with sender
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);
status_bar_active(num);
@ -487,7 +487,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
privatewin->unread++;
status_bar_new(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)) {
flash();
@ -1287,12 +1287,19 @@ ui_new_chat_win(const char * const barejid)
}
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) {
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 {
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
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_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_message_receipt(const char * const barejid, const char * const id);
void ui_disconnected(void);
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_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
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)
{
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:
win_print(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message);
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,
const char * const default_show);
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,
theme_item_t theme_item, const char * const from, const char * const message, char *id);
void win_newline(ProfWin *window);