From 0942d98c6116dc4b9b608e7483f1d6a8f62c84d7 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 6 Apr 2020 14:42:52 +0200 Subject: [PATCH] Remove chat_log_get_previous() We now dont get the log files from the text files via chat_log_get_previous() anymore. We use the sql backend via log_database_get_previous_chat(). So far it just has the same behaviour like chat_log_get_previous(), except that in _chatwin_history() we don't pass the sender to win_print_history() which should be fixed in a commit soon. And log_database_get_previous_chat() can later easily be expanded to fix https://github.com/profanity-im/profanity/issues/205. --- src/database.c | 4 +-- src/database.h | 2 +- src/log.c | 48 ---------------------------------- src/log.h | 1 - src/ui/chatwin.c | 10 +++---- tests/unittests/log/stub_log.c | 5 ---- 6 files changed, 6 insertions(+), 64 deletions(-) diff --git a/src/database.c b/src/database.c index f72ea5a0..52403805 100644 --- a/src/database.c +++ b/src/database.c @@ -283,12 +283,12 @@ _add_to_db(ProfMessage *message, const char * const type, const Jid * const from } GSList* -log_database_get_previous_chat(const gchar *const login, const gchar *const recipient) +log_database_get_previous_chat(const gchar *const contact_barejid) { sqlite3_stmt *stmt = NULL; char *query; - if (asprintf(&query, "SELECT `message`, `timestamp`, `from_jid` from `ChatLogs` WHERE `from_jid` = '%s' OR `to_jid` = '%s' ORDER BY `id` ASC LIMIT 10", recipient, recipient) == -1) { + if (asprintf(&query, "SELECT `message`, `timestamp`, `from_jid` from `ChatLogs` WHERE `from_jid` = '%s' OR `to_jid` = '%s' ORDER BY `id` ASC LIMIT 10", contact_barejid, contact_barejid) == -1) { log_error("log_database_get_previous_chat(): could not allocate memory"); return NULL; } diff --git a/src/database.h b/src/database.h index d0f6eb69..4401e430 100644 --- a/src/database.h +++ b/src/database.h @@ -47,7 +47,7 @@ void log_database_add_incoming_muc_pm(ProfMessage *message); void log_database_add_outgoing_chat(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc); void log_database_add_outgoing_muc(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc); void log_database_add_outgoing_muc_pm(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc); -GSList* log_database_get_previous_chat(const gchar *const login, const gchar *const recipient); +GSList* log_database_get_previous_chat(const gchar *const contact_barejid); void log_database_close(void); #endif // DATABASE_H diff --git a/src/log.c b/src/log.c index cd7802ef..e35fb460 100644 --- a/src/log.c +++ b/src/log.c @@ -619,54 +619,6 @@ _groupchat_log_chat(const gchar *const login, const gchar *const room, const gch g_date_time_unref(dt); } -GSList* -chat_log_get_previous(const gchar *const login, const gchar *const recipient) -{ - GSList *history = NULL; - GDateTime *now = g_date_time_new_now_local(); - GDateTime *log_date = g_date_time_new(tz, - g_date_time_get_year(session_started), - g_date_time_get_month(session_started), - g_date_time_get_day_of_month(session_started), - g_date_time_get_hour(session_started), - g_date_time_get_minute(session_started), - g_date_time_get_second(session_started)); - - // get data from all logs from the day the session was started to today - while (g_date_time_compare(log_date, now) != 1) { - char *filename = _get_log_filename(recipient, login, log_date, FALSE); - - FILE *logp = fopen(filename, "r"); - if (logp) { - GString *header = g_string_new(""); - g_string_append_printf(header, "%d/%d/%d:", - g_date_time_get_day_of_month(log_date), - g_date_time_get_month(log_date), - g_date_time_get_year(log_date)); - history = g_slist_append(history, header->str); - g_string_free(header, FALSE); - - char *line; - while ((line = file_getline(logp)) != NULL) { - history = g_slist_append(history, line); - } - - fclose(logp); - } - - free(filename); - - GDateTime *next = g_date_time_add_days(log_date, 1); - g_date_time_unref(log_date); - log_date = next; - } - - g_date_time_unref(log_date); - g_date_time_unref(now); - - return history; -} - void chat_log_close(void) { diff --git a/src/log.h b/src/log.h index 592c4039..3e29e8ca 100644 --- a/src/log.h +++ b/src/log.h @@ -82,7 +82,6 @@ void chat_log_pgp_msg_in(ProfMessage *message); void chat_log_omemo_msg_in(ProfMessage *message); void chat_log_close(void); -GSList* chat_log_get_previous(const gchar *const login, const gchar *const recipient); void groupchat_log_init(void); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 41e70b40..93cc9525 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -57,7 +57,7 @@ #include "omemo/omemo.h" #endif -static void _chatwin_history(ProfChatWin *chatwin, const char *const contact); +static void _chatwin_history(ProfChatWin *chatwin, const char *const contact_barejid); static void _chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message); ProfChatWin* @@ -478,14 +478,10 @@ chatwin_unset_outgoing_char(ProfChatWin *chatwin) } static void -_chatwin_history(ProfChatWin *chatwin, const char *const contact) +_chatwin_history(ProfChatWin *chatwin, const char *const contact_barejid) { if (!chatwin->history_shown) { - Jid *jid = jid_create(connection_get_fulljid()); - //GSList *history = chat_log_get_previous(jid->barejid, contact); - // TODO: jid not needed - GSList *history = log_database_get_previous_chat(jid->barejid, contact); - jid_destroy(jid); + GSList *history = log_database_get_previous_chat(contact_barejid); GSList *curr = history; while (curr) { diff --git a/tests/unittests/log/stub_log.c b/tests/unittests/log/stub_log.c index ecf415d0..5861a895 100644 --- a/tests/unittests/log/stub_log.c +++ b/tests/unittests/log/stub_log.c @@ -67,11 +67,6 @@ void chat_log_pgp_msg_in(ProfMessage *message) {} void chat_log_omemo_msg_in(ProfMessage *message) {} void chat_log_close(void) {} -GSList * chat_log_get_previous(const gchar * const login, - const gchar * const recipient) -{ - return mock_ptr_type(GSList *); -} void groupchat_log_init(void) {} void groupchat_log_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg) {}