mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Show log if session started today
This commit is contained in:
parent
460b244048
commit
3129500528
@ -33,7 +33,7 @@
|
|||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
static GHashTable *logs;
|
static GHashTable *logs;
|
||||||
static GDateTime *started;
|
static GDateTime *session_started;
|
||||||
|
|
||||||
struct dated_chat_log {
|
struct dated_chat_log {
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
@ -50,7 +50,7 @@ static char * _get_log_filename(char *other, const char * const login,
|
|||||||
void
|
void
|
||||||
chat_log_init(void)
|
chat_log_init(void)
|
||||||
{
|
{
|
||||||
started = g_date_time_new_now_local();
|
session_started = g_date_time_new_now_local();
|
||||||
log_info("Initialising chat logs");
|
log_info("Initialising chat logs");
|
||||||
logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free,
|
logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free,
|
||||||
(GDestroyNotify)_free_chat_log);
|
(GDestroyNotify)_free_chat_log);
|
||||||
@ -98,6 +98,11 @@ chat_log_get_previous(const gchar * const login, gchar *recipient,
|
|||||||
GSList *history)
|
GSList *history)
|
||||||
{
|
{
|
||||||
GDateTime *now = g_date_time_new_now_local();
|
GDateTime *now = g_date_time_new_now_local();
|
||||||
|
gint session_started_day = g_date_time_get_day_of_year(session_started);
|
||||||
|
gint day_now = g_date_time_get_day_of_year(now);
|
||||||
|
|
||||||
|
// session started today
|
||||||
|
if (day_now == session_started_day) {
|
||||||
char *filename = _get_log_filename(recipient, login, now);
|
char *filename = _get_log_filename(recipient, login, now);
|
||||||
|
|
||||||
FILE *logp = fopen(filename, "r");
|
FILE *logp = fopen(filename, "r");
|
||||||
@ -121,13 +126,19 @@ chat_log_get_previous(const gchar * const login, gchar *recipient,
|
|||||||
g_date_time_unref(now);
|
g_date_time_unref(now);
|
||||||
|
|
||||||
return history;
|
return history;
|
||||||
|
|
||||||
|
// session started before today
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
chat_log_close(void)
|
chat_log_close(void)
|
||||||
{
|
{
|
||||||
g_hash_table_remove_all(logs);
|
g_hash_table_remove_all(logs);
|
||||||
g_date_time_unref(started);
|
g_date_time_unref(session_started);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dated_chat_log *
|
static struct dated_chat_log *
|
||||||
|
Loading…
Reference in New Issue
Block a user