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

Pass delay timestamp to all incoming chat events

This commit is contained in:
James Booth 2015-09-08 20:18:31 +01:00
parent 3883e04d24
commit b266e4d035
6 changed files with 40 additions and 73 deletions

View File

@ -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
@ -301,21 +301,6 @@ sv_ev_delayed_private_message(const char * const fulljid, char *message, GDateTi
ui_incoming_private_msg(fulljid, message, timestamp);
}
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)
{

View File

@ -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);

View File

@ -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();

View File

@ -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,

View File

@ -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);

View File

@ -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,