empathy r2608 - trunk/libempathy-gtk



Author: xclaesse
Date: Fri Mar  6 11:52:57 2009
New Revision: 2608
URL: http://svn.gnome.org/viewvc/empathy?rev=2608&view=rev

Log:
Use get_filtered_messages in EmpathyChat.

Signed-off-by: Jonny Lamb <jonny lamb collabora co uk>

Modified:
   trunk/libempathy-gtk/empathy-chat.c

Modified: trunk/libempathy-gtk/empathy-chat.c
==============================================================================
--- trunk/libempathy-gtk/empathy-chat.c	(original)
+++ trunk/libempathy-gtk/empathy-chat.c	Fri Mar  6 11:52:57 2009
@@ -1026,14 +1026,31 @@
 	}
 }
 
+static gboolean
+chat_log_filter (EmpathyMessage *message,
+		 gpointer user_data)
+{
+	EmpathyChat *chat = (EmpathyChat *) user_data;
+	EmpathyChatPriv *priv = GET_PRIV (chat);
+	const GList *pending;
+
+	pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
+
+	for (; pending; pending = g_list_next (pending)) {
+		if (empathy_message_equal (message, pending->data)) {
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
+
 static void
 chat_add_logs (EmpathyChat *chat)
 {
 	EmpathyChatPriv *priv = GET_PRIV (chat);
 	gboolean         is_chatroom;
 	GList           *messages, *l;
-	guint            i = 0;
-	const GList     *pending_messages, *m;
 
 	if (!priv->id) {
 		return;
@@ -1044,28 +1061,17 @@
 
 	/* Add messages from last conversation */
 	is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
-	messages = empathy_log_manager_get_last_messages (priv->log_manager,
-							  priv->account,
-							  priv->id,
-							  is_chatroom);
-
-	pending_messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
-
-	for (l = g_list_last (messages); l; l = g_list_previous (l)) {
-		if (i < 10) {
-			gboolean found = FALSE;
-
-			for (m = pending_messages; m; m = g_list_next (m)) {
-				if (empathy_message_equal (l->data, m->data)) {
-					found = TRUE;
-				}
-			}
-
-			if (!found) {
-				empathy_chat_view_append_message (chat->view, l->data);
-				i++;
-			}
-		}
+
+	messages = empathy_log_manager_get_filtered_messages (priv->log_manager,
+							      priv->account,
+							      priv->id,
+							      is_chatroom,
+							      5,
+							      chat_log_filter,
+							      chat);
+
+	for (l = messages; l; l = g_list_next (l)) {
+		empathy_chat_view_append_message (chat->view, l->data);
 		g_object_unref (l->data);
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]