diff --git a/src/database.c b/src/database.c index 2f363baf..782d3d5b 100644 --- a/src/database.c +++ b/src/database.c @@ -107,7 +107,7 @@ log_database_init(ProfAccount *account) // to_jid is the receivers resource // message is the message text // timestamp the timestamp like "2020/03/24 11:12:14" - // type is there to distinguish: message, MUC message, muc pm + // type is there to distinguish: message (chat), MUC message (muc), muc pm (mucpm) // stanza_id is the ID from XEP-0359: Unique and Stable Stanza IDs // archive_id is the ID from XEP-0313: Message Archive Management // replace_id is the ID from XEP-0308: Last Message Correction @@ -154,7 +154,7 @@ log_database_close(void) } void -log_database_add(ProfMessage *message, gboolean is_muc) { +log_database_add(ProfMessage *message, const char *const type) { if (!g_chatlog_database) { log_debug("log_database_add() called but db is not initialized"); return; @@ -163,10 +163,20 @@ log_database_add(ProfMessage *message, gboolean is_muc) { char *err_msg; char *query; + const char *jid = connection_get_fulljid(); + Jid *myjid = jid_create(jid); + //gchar *date_fmt = g_date_time_format_iso8601(message->timestamp); gchar *date_fmt = g_date_time_format(message->timestamp, "%Y/%m/%d %H:%M:%S"); - if (asprintf(&query, "INSERT INTO `ChatLogs` (`jid`, `resource`, `message`, `timestamp`, `stanza_id`, `replace_id`) VALUES ('%s', '%s', '%s', '%d', '%s', '%s')", - message->jid->barejid, message->jid->resourcepart, message->plain, date_fmt, is_muc, message->id ? message->id : "", message->replace_id ? message->replace_id : "") == -1) { + if (asprintf(&query, "INSERT INTO `ChatLogs` (`from_jid`, `from_resource`, `to_jid`, `message`, `timestamp`, `stanza_id`, `replace_id`, `type`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", + message->jid->barejid, + message->jid->resourcepart, + myjid->barejid, + message->plain, + date_fmt, + message->id ? message->id : "", + message->replace_id ? message->replace_id : "", + type) == -1) { log_error("log_database_add(): could not allocate memory"); return; } diff --git a/src/database.h b/src/database.h index 9281e6e6..a0c252e7 100644 --- a/src/database.h +++ b/src/database.h @@ -41,7 +41,7 @@ #include "xmpp/xmpp.h" gboolean log_database_init(ProfAccount *account); -void log_database_add(ProfMessage *message, gboolean is_muc); +void log_database_add(ProfMessage *message, const char *const type); void log_database_close(void); #endif // DATABASE_H diff --git a/src/event/server_events.c b/src/event/server_events.c index 86176078..6e03725c 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -327,7 +327,7 @@ sv_ev_room_message(ProfMessage *message) GList *triggers = prefs_message_get_triggers(message->plain); _clean_incoming_message(message); - log_database_add(message, TRUE); + log_database_add(message, "muc"); mucwin_incoming_msg(mucwin, message, mentions, triggers, TRUE); g_slist_free(mentions); @@ -401,6 +401,7 @@ sv_ev_incoming_private_message(ProfMessage *message) } _clean_incoming_message(message); + log_database_add(message, "mucpm"); privwin_incoming_msg(privatewin, message); chat_log_msg_in(message); @@ -536,7 +537,7 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message if (message->plain) { message->enc = PROF_MSG_ENC_PGP; _clean_incoming_message(message); - log_database_add(message, FALSE); + log_database_add(message, "chat"); chatwin_incoming_msg(chatwin, message, new_win); if (logit) { chat_log_pgp_msg_in(message); @@ -552,7 +553,7 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message message->enc = PROF_MSG_ENC_PLAIN; message->plain = strdup(message->body); _clean_incoming_message(message); - log_database_add(message, FALSE); + log_database_add(message, "chat"); chatwin_incoming_msg(chatwin, message, new_win); chat_log_msg_in(message); chatwin->pgp_recv = FALSE; @@ -575,7 +576,7 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message } _clean_incoming_message(message); - log_database_add(message, FALSE); + log_database_add(message, "chat"); chatwin_incoming_msg(chatwin, message, new_win); chat_log_otr_msg_in(message); @@ -591,7 +592,7 @@ static void _sv_ev_incoming_omemo(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message, gboolean logit) { _clean_incoming_message(message); - log_database_add(message, FALSE); + log_database_add(message, "chat"); chatwin_incoming_msg(chatwin, message, new_win); if (logit) { chat_log_omemo_msg_in(message); @@ -607,7 +608,7 @@ _sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, ProfMessage *messa message->enc = PROF_MSG_ENC_PLAIN; message->plain = strdup(message->body); _clean_incoming_message(message); - log_database_add(message, FALSE); + log_database_add(message, "chat"); chatwin_incoming_msg(chatwin, message, new_win); if (logit) { chat_log_msg_in(message);