From 997336d0f9c77afa7bd229d96e60979fb4eaf23c Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Fri, 6 Mar 2009 11:51:25 +0000 Subject: Make get_dates check whether a date is already in the GList before adding it now in order. (Jonny Lamb) Signed-off-by: Jonny Lamb svn path=/trunk/; revision=2580 --- libempathy/empathy-log-manager.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'libempathy/empathy-log-manager.c') diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c index f734a184d..54e9a62f3 100644 --- a/libempathy/empathy-log-manager.c +++ b/libempathy/empathy-log-manager.c @@ -173,6 +173,17 @@ empathy_log_manager_exists (EmpathyLogManager *manager, return FALSE; } +static void +log_manager_get_dates_foreach (gpointer data, + gpointer user_data) +{ + /* g_list_first is needed in case an older date was last inserted */ + GList *orig = g_list_first (user_data); + + if (g_list_find_custom (orig, data, (GCompareFunc) strcmp)) + orig = g_list_insert_sorted (orig, g_strdup (data), (GCompareFunc) strcmp); +} + GList * empathy_log_manager_get_dates (EmpathyLogManager *manager, McAccount *account, @@ -198,9 +209,16 @@ empathy_log_manager_get_dates (EmpathyLogManager *manager, if (!out) out = source->get_dates (manager, account, chat_id, chatroom); else - /* TODO fix this */ - out = g_list_concat (out, source->get_dates (manager, account, - chat_id, chatroom)); + { + GList *new = source->get_dates (manager, account, chat_id, chatroom); + g_list_foreach (new, log_manager_get_dates_foreach, out); + + g_list_foreach (new, (GFunc) g_free, NULL); + g_list_free (new); + + /* Similar reason for using g_list_first here as before */ + out = g_list_first (out); + } } return out; -- cgit v1.2.3