aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2009-03-06 19:52:48 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2009-03-06 19:52:48 +0800
commit6d3c3b4e7ae6c3d9fc7328607e903938d5679395 (patch)
tree25581679fc147a853de4ab104f798c9adc194b1b
parent282a13ac548f033339396dcc0fae8e76e8103cbd (diff)
downloadgsoc2013-empathy-6d3c3b4e7ae6c3d9fc7328607e903938d5679395.tar
gsoc2013-empathy-6d3c3b4e7ae6c3d9fc7328607e903938d5679395.tar.gz
gsoc2013-empathy-6d3c3b4e7ae6c3d9fc7328607e903938d5679395.tar.bz2
gsoc2013-empathy-6d3c3b4e7ae6c3d9fc7328607e903938d5679395.tar.lz
gsoc2013-empathy-6d3c3b4e7ae6c3d9fc7328607e903938d5679395.tar.xz
gsoc2013-empathy-6d3c3b4e7ae6c3d9fc7328607e903938d5679395.tar.zst
gsoc2013-empathy-6d3c3b4e7ae6c3d9fc7328607e903938d5679395.zip
Replaced get_last_messages with get_filtered_messages.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk> svn path=/trunk/; revision=2605
-rw-r--r--libempathy/empathy-log-manager.c75
-rw-r--r--libempathy/empathy-log-manager.h8
2 files changed, 60 insertions, 23 deletions
diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c
index 30c31f92a..b8a346268 100644
--- a/libempathy/empathy-log-manager.c
+++ b/libempathy/empathy-log-manager.c
@@ -262,41 +262,74 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
return out;
}
+static gint
+log_manager_sort_message_by_date (gconstpointer a,
+ gconstpointer b)
+{
+ EmpathyMessage *one = (EmpathyMessage *) a;
+ EmpathyMessage *two = (EmpathyMessage *) b;
+ time_t one_time, two_time;
+ gint ret = 0;
+
+ one_time = empathy_message_get_timestamp (one);
+ two_time = empathy_message_get_timestamp (two);
+
+ if (one_time < two_time) {
+ ret = -1;
+ } else if (one_time == two_time) {
+ ret = 0;
+ } else if (one_time > two_time) {
+ ret = 1;
+ }
+
+ return ret;
+}
+
GList *
-empathy_log_manager_get_last_messages (EmpathyLogManager *manager,
- McAccount *account,
- const gchar *chat_id,
- gboolean chatroom)
+empathy_log_manager_get_filtered_messages (EmpathyLogManager *manager,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom,
+ guint num_messages,
+ EmpathyLogMessageFilter filter,
+ gpointer user_data)
{
- GList *messages = NULL;
- GList *dates;
+ EmpathyLogManagerPriv *priv;
+ GList *out = NULL;
GList *l;
+ guint out_size, i;
g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL);
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (chat_id != NULL, NULL);
- dates = empathy_log_manager_get_dates (manager, account, chat_id, chatroom);
+ priv = GET_PRIV (manager);
- l = g_list_last (dates);
- if (l)
+ /* Get num_messages from each log store */
+ for (l = priv->stores; l; l = l->next)
{
- messages = empathy_log_manager_get_messages_for_date (manager, account,
- chat_id, chatroom, l->data);
+ EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data);
- /* The latest date will always be today as messages are logged immediately. */
- l = g_list_previous (l);
- if (l)
- {
- messages = g_list_concat (messages, empathy_log_manager_get_messages_for_date (
- manager, account, chat_id, chatroom, l->data));
- }
+ out = g_list_concat (out, empathy_log_store_get_filtered_messages (store,
+ account, chat_id, chatroom, num_messages, filter, user_data));
}
- g_list_foreach (dates, (GFunc) g_free, NULL);
- g_list_free (dates);
+ /* Sort the list by time */
+ out = g_list_sort (out, log_manager_sort_message_by_date);
+
+ /* Cut list down to num_messages length */
+ out_size = g_list_length (out);
+
+ for (i = 0; out_size - i > num_messages; i++)
+ {
+ EmpathyMessage *message;
- return messages;
+ message = out->data;
+ out = g_list_remove (out, message);
+ g_object_unref (message);
+ }
+
+ return out;
}
GList *
diff --git a/libempathy/empathy-log-manager.h b/libempathy/empathy-log-manager.h
index 4ec2c9019..f6a9290bd 100644
--- a/libempathy/empathy-log-manager.h
+++ b/libempathy/empathy-log-manager.h
@@ -72,6 +72,9 @@ struct _EmpathyLogSearchHit
gchar *date;
};
+typedef gboolean (*EmpathyLogMessageFilter) (EmpathyMessage *message,
+ gpointer user_data);
+
GType empathy_log_manager_get_type (void) G_GNUC_CONST;
EmpathyLogManager *empathy_log_manager_dup_singleton (void);
gboolean empathy_log_manager_add_message (EmpathyLogManager *manager,
@@ -84,8 +87,9 @@ GList *empathy_log_manager_get_dates (EmpathyLogManager *manager,
GList *empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
McAccount *account, const gchar *chat_id, gboolean chatroom,
const gchar *date);
-GList *empathy_log_manager_get_last_messages (EmpathyLogManager *manager,
- McAccount *account, const gchar *chat_id, gboolean chatroom);
+GList *empathy_log_manager_get_filtered_messages (EmpathyLogManager *manager,
+ McAccount *account, const gchar *chat_id, gboolean chatroom,
+ guint num_messages, EmpathyLogMessageFilter filter, gpointer user_data);
GList *empathy_log_manager_get_chats (EmpathyLogManager *manager,
McAccount *account);
GList *empathy_log_manager_search_new (EmpathyLogManager *manager,