diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-03-28 00:50:32 +0100 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-04-06 10:50:20 +0200 |
commit | def212321636b13a72fdff71431fc003ad791482 (patch) | |
tree | 440e33682f4a5fcda8fa2e859507cbc1d0ceb143 /src/database.c | |
parent | 628b86f57e25a3804a6d8c1bd370e0ac69ced43d (diff) | |
download | profani-tty-def212321636b13a72fdff71431fc003ad791482.tar.gz |
db: log outgoing message in one case
Not all cases covered yet.
Diffstat (limited to 'src/database.c')
-rw-r--r-- | src/database.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/src/database.c b/src/database.c index ae450f84..a7910b4d 100644 --- a/src/database.c +++ b/src/database.c @@ -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 : "", |