diff -ur telepathy-logger-0.1.7/telepathy-logger/datetime.c telepathy-logger-0.1.7.patched//telepathy-logger/datetime.c --- telepathy-logger-0.1.7/telepathy-logger/datetime.c 2010-08-11 15:35:33.000000000 +0400 +++ telepathy-logger-0.1.7.patched//telepathy-logger/datetime.c 2010-12-26 00:41:36.000000000 +0300 @@ -125,3 +125,24 @@ return g_strdup (stamp); } + +/* Converts the UTC timestamp to a local timestamp. */ +time_t +_tpl_time_to_local (time_t t) +{ + return _tpl_time_get_local_time (gmtime (&t)); +} + + +/* Returns offset in seconds between the local time and UTC. */ +double +_tpl_time_get_tz_offset (void) +{ + struct tm *tm; + time_t t; + + t = time (NULL); + tm = localtime (&t); + + return difftime (_tpl_time_get_local_time (tm), t); +} diff -ur telepathy-logger-0.1.7/telepathy-logger/datetime-internal.h telepathy-logger-0.1.7.patched//telepathy-logger/datetime-internal.h --- telepathy-logger-0.1.7/telepathy-logger/datetime-internal.h 2010-08-11 15:35:33.000000000 +0400 +++ telepathy-logger-0.1.7.patched//telepathy-logger/datetime-internal.h 2010-12-25 21:13:34.000000000 +0300 @@ -37,6 +37,8 @@ time_t _tpl_time_parse (const gchar * str); gchar *_tpl_time_to_string_utc (time_t t, const gchar * format); gchar *_tpl_time_to_string_local (time_t t, const gchar * format); +time_t _tpl_time_to_local (time_t t); +double _tpl_time_get_tz_offset (void); G_END_DECLS #endif /* __TPL_TIME_H__ */ diff -ur telepathy-logger-0.1.7/telepathy-logger/log-manager.c telepathy-logger-0.1.7.patched//telepathy-logger/log-manager.c --- telepathy-logger-0.1.7/telepathy-logger/log-manager.c 2010-11-29 15:30:59.000000000 +0300 +++ telepathy-logger-0.1.7.patched//telepathy-logger/log-manager.c 2010-12-26 16:56:23.000000000 +0300 @@ -419,6 +419,29 @@ return FALSE; } +static GList * +log_manager_insert_proved_date (TplLogManager *manager, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom, + GList *out, + GDate *date) +{ + GList *messages; + + messages = _tpl_log_manager_get_messages_for_date (manager, + account, chat_id, chatroom, date); + if (messages) + { + if (g_list_find_custom (out, date, (GCompareFunc) g_date_compare)) + g_date_free (date); + else + out = g_list_insert_sorted (out, date, (GCompareFunc) g_date_compare); + g_list_free (messages); + } + + return out; +} /** * _tpl_log_manager_get_dates: @@ -447,6 +470,8 @@ { GList *l, *out = NULL; TplLogManagerPriv *priv; + double tz_offset; + GDate *additional_date; g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); g_return_val_if_fail (chat_id != NULL, NULL); @@ -461,16 +486,24 @@ /* Insert dates of each store in the out list. Keep the out list sorted * and avoid to insert dups. */ new = _tpl_log_store_get_dates (store, account, chat_id, chatroom); + tz_offset = _tpl_time_get_tz_offset(); while (new) { - if (g_list_find_custom (out, new->data, - (GCompareFunc) g_date_compare)) - g_date_free (new->data); - else - out = - g_list_insert_sorted (out, new->data, - (GCompareFunc) g_date_compare); + if (tz_offset != 0) + { + additional_date = + g_date_new_julian (g_date_get_julian (new->data)); + if (tz_offset > 0) + g_date_add_days (additional_date, 1); + else + g_date_subtract_days (additional_date, 1); + + out = log_manager_insert_proved_date (manager, + account, chat_id, chatroom, out, additional_date); + } + out = log_manager_insert_proved_date (manager, + account, chat_id, chatroom, out, new->data); new = g_list_delete_link (new, new); } } @@ -479,6 +512,26 @@ } +static gint +log_manager_message_date_cmp (gconstpointer a, + gconstpointer b) +{ + TplEntry *one = (TplEntry *) a; + TplEntry *two = (TplEntry *) b; + gint64 one_time, two_time; + + g_assert (TPL_IS_ENTRY (one)); + g_assert (TPL_IS_ENTRY (two)); + + one_time = tpl_entry_get_timestamp (one); + two_time = tpl_entry_get_timestamp (two); + + /* return -1, o or 1 depending on message1 is newer, the same or older than + * message2 */ + return CLAMP (one_time - two_time, -1, 1); +} + + GList * _tpl_log_manager_get_messages_for_date (TplLogManager *manager, TpAccount *account, @@ -486,8 +539,10 @@ gboolean chatroom, const GDate *date) { - GList *l, *out = NULL; + GList *l, *out = NULL, *redundant = NULL; TplLogManagerPriv *priv; + GDate *additional_date, *entry_date; + double tz_offset; g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); g_return_val_if_fail (chat_id != NULL, NULL); @@ -502,27 +557,48 @@ account, chat_id, chatroom, date)); } - return out; -} + tz_offset = _tpl_time_get_tz_offset(); + if (tz_offset != 0) + { + redundant = out; + out = NULL; -static gint -log_manager_message_date_cmp (gconstpointer a, - gconstpointer b) -{ - TplEntry *one = (TplEntry *) a; - TplEntry *two = (TplEntry *) b; - gint64 one_time, two_time; + additional_date = g_date_new_julian (g_date_get_julian (date)); + if (tz_offset < 0) + g_date_add_days (additional_date, 1); + else + g_date_subtract_days (additional_date, 1); - g_assert (TPL_IS_ENTRY (one)); - g_assert (TPL_IS_ENTRY (two)); + for (l = priv->readable_stores; l != NULL; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); - one_time = tpl_entry_get_timestamp (one); - two_time = tpl_entry_get_timestamp (two); + redundant = g_list_concat (redundant, + _tpl_log_store_get_messages_for_date (store, account, chat_id, + chatroom, additional_date)); + } - /* return -1, o or 1 depending on message1 is newer, the same or older than - * message2 */ - return CLAMP (one_time - two_time, -1, 1); + entry_date = g_date_new (); + + for (l = redundant; l; l = l->next) + { + g_date_set_time_t (entry_date, + _tpl_time_to_local (tpl_entry_get_timestamp (l->data))); + + if (!g_date_compare (entry_date, date)) + out = g_list_insert_sorted (out, l->data, + (GCompareFunc) log_manager_message_date_cmp); + else + g_object_unref (l->data); + } + + g_date_free (additional_date); + g_date_free (entry_date); + g_list_free (redundant); + } + + return out; }