1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Show history from day that session started

This commit is contained in:
James Booth 2012-10-14 17:23:38 +01:00
parent 3129500528
commit c4fd08c430

View File

@ -97,13 +97,20 @@ GSList *
chat_log_get_previous(const gchar * const login, gchar *recipient, chat_log_get_previous(const gchar * const login, gchar *recipient,
GSList *history) GSList *history)
{ {
GDateTime *now = g_date_time_new_now_local(); GTimeZone *tz = g_time_zone_new_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 GDateTime *now = g_date_time_new_now_local();
if (day_now == session_started_day) { GDateTime *log_date = g_date_time_new(tz,
char *filename = _get_log_filename(recipient, login, now); 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_get_day_of_year(log_date) <= g_date_time_get_day_of_year(now)) {
char *filename = _get_log_filename(recipient, login, log_date);
FILE *logp = fopen(filename, "r"); FILE *logp = fopen(filename, "r");
char *line = NULL; char *line = NULL;
@ -120,18 +127,19 @@ chat_log_get_previous(const gchar * const login, gchar *recipient,
read = 0; read = 0;
length = getline(&line, &read, logp); length = getline(&line, &read, logp);
} }
fclose(logp);
} }
free(filename); free(filename);
g_date_time_unref(now); GDateTime *next = g_date_time_add_days(log_date, 1);
g_date_time_unref(log_date);
log_date = g_date_time_ref(next);
}
g_time_zone_unref(tz);
return history; return history;
// session started before today
} else {
return NULL;
}
} }
void void