1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

db: log outgoing message in one case

Not all cases covered yet.
This commit is contained in:
Michael Vetter 2020-03-28 00:50:32 +01:00
parent 628b86f57e
commit def2123216
3 changed files with 46 additions and 11 deletions

View File

@ -45,7 +45,7 @@
static sqlite3 *g_chatlog_database;
static void _add_incoming(ProfMessage *message, const char * const type);
static void _add_to_db(ProfMessage *message, const char * const type, const char * const from_jid, const char * const to_jid);
static char* _get_db_filename(ProfAccount *account);
static char*
@ -158,21 +158,56 @@ log_database_close(void)
void
log_database_add_incoming_chat(ProfMessage *message) {
_add_incoming(message, "chat");
const char *jid = connection_get_fulljid();
Jid *myjid = jid_create(jid);
_add_to_db(message, "chat", message->jid->barejid, myjid->barejid);
jid_destroy(myjid);
}
void
log_database_add_incoming_muc(ProfMessage *message) {
_add_incoming(message, "muc");
const char *jid = connection_get_fulljid();
Jid *myjid = jid_create(jid);
_add_to_db(message, "muc", message->jid->barejid, myjid->barejid);
jid_destroy(myjid);
}
void
log_database_add_incoming_muc_pm(ProfMessage *message) {
_add_incoming(message, "mucpm");
const char *jid = connection_get_fulljid();
Jid *myjid = jid_create(jid);
_add_to_db(message, "mucpm", message->jid->barejid, myjid->barejid);
jid_destroy(myjid);
}
void
log_database_add_outgoing(const char * const id, const char * const barejid, const char * const message, const char *const replace_id)
{
ProfMessage *msg = message_init();
msg->id = id ? strdup(id) : NULL;
msg->jid = jid_create(barejid);
msg->plain = message ? strdup(message) : NULL;
msg->replace_id = replace_id ? strdup(replace_id) : NULL;
msg->timestamp = g_date_time_new_now_local(); //TODO: get from outside. best to have whole ProfMessage from outside
const char *jid = connection_get_fulljid();
Jid *myjid = jid_create(jid);
_add_to_db(msg, "chat", myjid->barejid, msg->jid->barejid);
jid_destroy(myjid);
message_free(msg);
}
static void
_add_incoming(ProfMessage *message, const char * const type)
_add_to_db(ProfMessage *message, const char * const type, const char * const from_jid, const char * const to_jid)
{
if (!g_chatlog_database) {
log_debug("log_database_add() called but db is not initialized");
@ -182,15 +217,12 @@ _add_incoming(ProfMessage *message, const char * const type)
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` (`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,
from_jid,
"test" /*message->jid->resourcepart*/,
to_jid,
message->plain,
date_fmt,
message->id ? message->id : "",

View File

@ -44,6 +44,7 @@ gboolean log_database_init(ProfAccount *account);
void log_database_add_incoming_chat(ProfMessage *message);
void log_database_add_incoming_muc(ProfMessage *message);
void log_database_add_incoming_muc_pm(ProfMessage *message);
void log_database_add_outgoing(const char * const id, const char * const barejid, const char * const message, const char *const replace_id);
void log_database_close(void);
#endif // DATABASE_H

View File

@ -40,6 +40,7 @@
#include <glib.h>
#include "log.h"
#include "database.h"
#include "config/preferences.h"
#include "event/common.h"
#include "plugins/plugins.h"
@ -295,6 +296,7 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing(id, chatwin->barejid, plugin_msg, replace_id);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
free(id);
}