about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-04-06 14:42:52 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-04-06 14:42:52 +0200
commit0942d98c6116dc4b9b608e7483f1d6a8f62c84d7 (patch)
treed8a95379d8ae95f8bedfae740c9cb6cba01ed924 /src
parent5d54bb228f4ef750edefdd9423f8f672d045ff6c (diff)
downloadprofani-tty-0942d98c6116dc4b9b608e7483f1d6a8f62c84d7.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/database.c4
-rw-r--r--src/database.h2
-rw-r--r--src/log.c48
-rw-r--r--src/log.h1
-rw-r--r--src/ui/chatwin.c10
5 files changed, 6 insertions, 59 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) {