diff options
-rw-r--r-- | src/event/server_events.c | 55 | ||||
-rw-r--r-- | src/event/server_events.h | 3 | ||||
-rw-r--r-- | src/log.c | 25 | ||||
-rw-r--r-- | src/log.h | 7 | ||||
-rw-r--r-- | src/xmpp/message.c | 16 | ||||
-rw-r--r-- | tests/unittests/log/stub_log.c | 7 |
6 files changed, 40 insertions, 73 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c index 74aa4d74..160d4472 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -188,22 +188,22 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message) } ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN); - chat_log_msg_in(barejid, message); + chat_log_msg_in(barejid, message, NULL); } #ifdef HAVE_LIBGPGME static void -_sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, char *pgp_message) +_sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, char *pgp_message, GDateTime *timestamp) { char *decrypted = p_gpg_decrypt(pgp_message); if (decrypted) { - ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win, PROF_MSG_PGP); - chat_log_pgp_msg_in(barejid, decrypted); + ui_incoming_msg(chatwin, resource, decrypted, timestamp, new_win, PROF_MSG_PGP); + chat_log_pgp_msg_in(barejid, decrypted, timestamp); chatwin->pgp_recv = TRUE; p_gpg_free_decrypted(decrypted); } else { - ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN); - chat_log_msg_in(barejid, message); + ui_incoming_msg(chatwin, resource, message, timestamp, new_win, PROF_MSG_PLAIN); + chat_log_msg_in(barejid, message, timestamp); chatwin->pgp_recv = FALSE; } } @@ -211,18 +211,18 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char #ifdef HAVE_LIBOTR static void -_sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message) +_sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, GDateTime *timestamp) { gboolean decrypted = FALSE; char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted); if (otr_res) { if (decrypted) { - ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_MSG_OTR); + ui_incoming_msg(chatwin, resource, otr_res, timestamp, new_win, PROF_MSG_OTR); chatwin->pgp_send = FALSE; } else { - ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_MSG_PLAIN); + ui_incoming_msg(chatwin, resource, otr_res, timestamp, new_win, PROF_MSG_PLAIN); } - chat_log_otr_msg_in(barejid, otr_res, decrypted); + chat_log_otr_msg_in(barejid, otr_res, decrypted, timestamp); otr_free_message(otr_res); chatwin->pgp_recv = FALSE; } @@ -231,16 +231,16 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char #ifndef HAVE_LIBOTR static void -_sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message) +_sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, GDateTime *timestamp) { - ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN); - chat_log_msg_in(barejid, message); + ui_incoming_msg(chatwin, resource, message, timestamp, new_win, PROF_MSG_PLAIN); + chat_log_msg_in(barejid, message, timestamp); chatwin->pgp_recv = FALSE; } #endif void -sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message) +sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message, GDateTime *timestamp) { gboolean new_win = FALSE; ProfChatWin *chatwin = wins_get_chat(barejid); @@ -257,10 +257,10 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m if (chatwin->is_otr) { win_println((ProfWin*)chatwin, 0, "PGP encrypted message received whilst in OTR session."); } else { // PROF_ENC_NONE, PROF_ENC_PGP - _sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message); + _sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message, timestamp); } } else { - _sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message); + _sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message, timestamp); } return; #endif @@ -269,7 +269,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m // OTR supported, PGP unsupported #ifdef HAVE_LIBOTR #ifndef HAVE_LIBGPGME - _sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message); + _sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message, timestamp); return; #endif #endif @@ -278,9 +278,9 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m #ifndef HAVE_LIBOTR #ifdef HAVE_LIBGPGME if (pgp_message) { - _sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message); + _sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message, timestamp); } else { - _sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message); + _sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, timestamp); } return; #endif @@ -289,7 +289,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m // OTR unsupported, PGP unsupported #ifndef HAVE_LIBOTR #ifndef HAVE_LIBGPGME - _sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message); + _sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, timestamp); return; #endif #endif @@ -302,21 +302,6 @@ sv_ev_delayed_private_message(const char * const fulljid, char *message, GDateTi } void -sv_ev_delayed_message(char *barejid, char *message, GDateTime *timestamp) -{ - gboolean new_win = FALSE; - ProfChatWin *chatwin = wins_get_chat(barejid); - if (!chatwin) { - ProfWin *window = wins_new_chat(barejid); - chatwin = (ProfChatWin*)window; - new_win = TRUE; - } - - ui_incoming_msg(chatwin, NULL, message, timestamp, new_win, PROF_MSG_PLAIN); - chat_log_msg_in_delayed(barejid, message, timestamp); -} - -void sv_ev_message_receipt(char *barejid, char *id) { ui_message_receipt(barejid, id); diff --git a/src/event/server_events.h b/src/event/server_events.h index 12d7ffa5..3ef8eae4 100644 --- a/src/event/server_events.h +++ b/src/event/server_events.h @@ -50,9 +50,8 @@ void sv_ev_room_history(const char * const room_jid, const char * const nick, GDateTime *timestamp, const char * const message); void sv_ev_room_message(const char * const room_jid, const char * const nick, const char * const message); -void sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message); +void sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message, GDateTime *timestamp); void sv_ev_incoming_private_message(const char * const fulljid, char *message); -void sv_ev_delayed_message(char *fulljid, char *message, GDateTime *timestamp); void sv_ev_delayed_private_message(const char * const fulljid, char *message, GDateTime *timestamp); void sv_ev_typing(char *barejid, char *resource); void sv_ev_paused(char *barejid, char *resource); diff --git a/src/log.c b/src/log.c index e4e6e809..5537c612 100644 --- a/src/log.c +++ b/src/log.c @@ -308,16 +308,16 @@ chat_log_pgp_msg_out(const char * const barejid, const char * const msg) } void -chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted) +chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted, GDateTime *timestamp) { if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); if (!was_decrypted || (strcmp(pref_otr_log, "on") == 0)) { - _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, NULL); + _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, timestamp); } else if (strcmp(pref_otr_log, "redact") == 0) { - _chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_IN_LOG, NULL); + _chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_IN_LOG, timestamp); } prefs_free_string(pref_otr_log); jid_destroy(jidp); @@ -325,16 +325,16 @@ chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean } void -chat_log_pgp_msg_in(const char * const barejid, const char * const msg) +chat_log_pgp_msg_in(const char * const barejid, const char * const msg, GDateTime *timestamp) { if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG); if (strcmp(pref_pgp_log, "on") == 0) { - _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, NULL); + _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, timestamp); } else if (strcmp(pref_pgp_log, "redact") == 0) { - _chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_IN_LOG, NULL); + _chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_IN_LOG, timestamp); } prefs_free_string(pref_pgp_log); jid_destroy(jidp); @@ -342,18 +342,7 @@ chat_log_pgp_msg_in(const char * const barejid, const char * const msg) } void -chat_log_msg_in(const char * const barejid, const char * const msg) -{ - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, NULL); - jid_destroy(jidp); - } -} - -void -chat_log_msg_in_delayed(const char * const barejid, const char * msg, GDateTime *timestamp) +chat_log_msg_in(const char * const barejid, const char * const msg, GDateTime *timestamp) { if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); diff --git a/src/log.h b/src/log.h index 99975670..87c96df9 100644 --- a/src/log.h +++ b/src/log.h @@ -73,10 +73,9 @@ void chat_log_msg_out(const char * const barejid, const char * const msg); void chat_log_otr_msg_out(const char * const barejid, const char * const msg); void chat_log_pgp_msg_out(const char * const barejid, const char * const msg); -void chat_log_msg_in(const char * const barejid, const char * const msg); -void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GDateTime *timestamp); -void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted); -void chat_log_pgp_msg_in(const char * const barejid, const char * const msg); +void chat_log_msg_in(const char * const barejid, const char * const msg, GDateTime *timestamp); +void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted, GDateTime *timestamp); +void chat_log_pgp_msg_in(const char * const barejid, const char * const msg, GDateTime *timestamp); void chat_log_close(void); GSList * chat_log_get_previous(const gchar * const login, diff --git a/src/xmpp/message.c b/src/xmpp/message.c index a46ead5c..5581521c 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -778,17 +778,13 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con if (body) { char *message = xmpp_stanza_get_text(body); if (message) { - if (timestamp) { - sv_ev_delayed_message(jid->barejid, message, timestamp); - } else { - char *enc_message = NULL; - xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED); - if (x) { - enc_message = xmpp_stanza_get_text(x); - } - sv_ev_incoming_message(jid->barejid, jid->resourcepart, message, enc_message); - xmpp_free(ctx, enc_message); + char *enc_message = NULL; + xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED); + if (x) { + enc_message = xmpp_stanza_get_text(x); } + sv_ev_incoming_message(jid->barejid, jid->resourcepart, message, enc_message, timestamp); + xmpp_free(ctx, enc_message); _receipt_request_handler(stanza); diff --git a/tests/unittests/log/stub_log.c b/tests/unittests/log/stub_log.c index 3baddb69..51e23ab6 100644 --- a/tests/unittests/log/stub_log.c +++ b/tests/unittests/log/stub_log.c @@ -59,10 +59,9 @@ void chat_log_msg_out(const char * const barejid, const char * const msg) {} void chat_log_otr_msg_out(const char * const barejid, const char * const msg) {} void chat_log_pgp_msg_out(const char * const barejid, const char * const msg) {} -void chat_log_msg_in(const char * const barejid, const char * const msg) {} -void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GDateTime *timestamp) {} -void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted) {} -void chat_log_pgp_msg_in(const char * const barejid, const char * const msg) {} +void chat_log_msg_in(const char * const barejid, const char * const msg, GDateTime *timestamp) {} +void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted, GDateTime *timestamp) {} +void chat_log_pgp_msg_in(const char * const barejid, const char * const msg, GDateTime *timestamp) {} void chat_log_close(void) {} GSList * chat_log_get_previous(const gchar * const login, |