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:
parent
3129500528
commit
c4fd08c430
@ -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;
|
||||||
@ -111,27 +118,28 @@ chat_log_get_previous(const gchar * const login, gchar *recipient,
|
|||||||
if (logp != NULL) {
|
if (logp != NULL) {
|
||||||
size_t length = getline(&line, &read, logp);
|
size_t length = getline(&line, &read, logp);
|
||||||
while (length != -1) {
|
while (length != -1) {
|
||||||
char *copy = malloc(length);
|
char *copy = malloc(length);
|
||||||
copy = strncpy(copy, line, length);
|
copy = strncpy(copy, line, length);
|
||||||
copy[length -1] = '\0';
|
copy[length -1] = '\0';
|
||||||
history = g_slist_append(history, copy);
|
history = g_slist_append(history, copy);
|
||||||
free(line);
|
free(line);
|
||||||
line = NULL;
|
line = NULL;
|
||||||
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);
|
||||||
return history;
|
log_date = g_date_time_ref(next);
|
||||||
|
|
||||||
// session started before today
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_time_zone_unref(tz);
|
||||||
|
|
||||||
|
return history;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user