1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

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.
This commit is contained in:
Michael Vetter 2020-04-06 14:42:52 +02:00
parent 5d54bb228f
commit 0942d98c61
6 changed files with 6 additions and 64 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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)
{

View File

@ -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);

View File

@ -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) {

View File

@ -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) {}