mirror of
https://github.com/profanity-im/profanity.git
synced 2025-06-05 06:33:37 -04: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:
parent
5d54bb228f
commit
0942d98c61
@ -283,12 +283,12 @@ _add_to_db(ProfMessage *message, const char * const type, const Jid * const from
|
|||||||
}
|
}
|
||||||
|
|
||||||
GSList*
|
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;
|
sqlite3_stmt *stmt = NULL;
|
||||||
char *query;
|
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");
|
log_error("log_database_get_previous_chat(): could not allocate memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -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_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(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);
|
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);
|
void log_database_close(void);
|
||||||
|
|
||||||
#endif // DATABASE_H
|
#endif // DATABASE_H
|
||||||
|
48
src/log.c
48
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);
|
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
|
void
|
||||||
chat_log_close(void)
|
chat_log_close(void)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,6 @@ void chat_log_pgp_msg_in(ProfMessage *message);
|
|||||||
void chat_log_omemo_msg_in(ProfMessage *message);
|
void chat_log_omemo_msg_in(ProfMessage *message);
|
||||||
|
|
||||||
void chat_log_close(void);
|
void chat_log_close(void);
|
||||||
GSList* chat_log_get_previous(const gchar *const login, const gchar *const recipient);
|
|
||||||
|
|
||||||
void groupchat_log_init(void);
|
void groupchat_log_init(void);
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
#include "omemo/omemo.h"
|
#include "omemo/omemo.h"
|
||||||
#endif
|
#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);
|
static void _chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message);
|
||||||
|
|
||||||
ProfChatWin*
|
ProfChatWin*
|
||||||
@ -478,14 +478,10 @@ chatwin_unset_outgoing_char(ProfChatWin *chatwin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_chatwin_history(ProfChatWin *chatwin, const char *const contact)
|
_chatwin_history(ProfChatWin *chatwin, const char *const contact_barejid)
|
||||||
{
|
{
|
||||||
if (!chatwin->history_shown) {
|
if (!chatwin->history_shown) {
|
||||||
Jid *jid = jid_create(connection_get_fulljid());
|
GSList *history = log_database_get_previous_chat(contact_barejid);
|
||||||
//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 *curr = history;
|
GSList *curr = history;
|
||||||
|
|
||||||
while (curr) {
|
while (curr) {
|
||||||
|
@ -67,11 +67,6 @@ void chat_log_pgp_msg_in(ProfMessage *message) {}
|
|||||||
void chat_log_omemo_msg_in(ProfMessage *message) {}
|
void chat_log_omemo_msg_in(ProfMessage *message) {}
|
||||||
|
|
||||||
void chat_log_close(void) {}
|
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_init(void) {}
|
||||||
void groupchat_log_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg) {}
|
void groupchat_log_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user