[empathy] group messages only if the delay is short



commit 77fd33616f44a907342651a5a2d7e326ad5ccf55
Author: Felix Kaser <f kaser gmx net>
Date:   Wed Apr 7 13:19:08 2010 +0200

    group messages only if the delay is short
    
    messages from the same sender should not be grouped when the delay between two messages is too long (5min). fixes bug #604475

 libempathy-gtk/empathy-chat-text-view.c |   10 ++++++++++
 libempathy-gtk/empathy-chat-text-view.h |   25 +++++++++++++------------
 libempathy-gtk/empathy-theme-boxes.c    |   15 +++++++++++----
 3 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/libempathy-gtk/empathy-chat-text-view.c b/libempathy-gtk/empathy-chat-text-view.c
index 7f16ab9..137a77a 100644
--- a/libempathy-gtk/empathy-chat-text-view.c
+++ b/libempathy-gtk/empathy-chat-text-view.c
@@ -1308,6 +1308,16 @@ empathy_chat_text_view_get_last_contact (EmpathyChatTextView *view)
 	return priv->last_contact;
 }
 
+time_t
+empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view)
+{
+	EmpathyChatTextViewPriv *priv = GET_PRIV (view);
+
+	g_return_val_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view), 0);
+
+	return priv->last_timestamp;
+}
+
 void
 empathy_chat_text_view_set_only_if_date (EmpathyChatTextView *view,
 					 gboolean             only_if_date)
diff --git a/libempathy-gtk/empathy-chat-text-view.h b/libempathy-gtk/empathy-chat-text-view.h
index 0180f21..7ee7ba8 100644
--- a/libempathy-gtk/empathy-chat-text-view.h
+++ b/libempathy-gtk/empathy-chat-text-view.h
@@ -68,18 +68,19 @@ struct _EmpathyChatTextViewClass {
 #define EMPATHY_CHAT_TEXT_VIEW_TAG_EVENT "event"
 #define EMPATHY_CHAT_TEXT_VIEW_TAG_LINK "link"
 
-GType                empathy_chat_text_view_get_type         (void) G_GNUC_CONST;
-EmpathyContact *     empathy_chat_text_view_get_last_contact (EmpathyChatTextView *view);
-void                 empathy_chat_text_view_set_only_if_date (EmpathyChatTextView *view,
-							      gboolean             only_if_date);
-void                 empathy_chat_text_view_append_body      (EmpathyChatTextView *view,
-							      const gchar         *body,
-							      const gchar         *tag);
-void                 empathy_chat_text_view_append_spacing   (EmpathyChatTextView *view);
-GtkTextTag *         empathy_chat_text_view_tag_set          (EmpathyChatTextView *view,
-							      const gchar         *tag_name,
-							      const gchar         *first_property_name,
-							      ...);
+GType                empathy_chat_text_view_get_type           (void) G_GNUC_CONST;
+EmpathyContact *     empathy_chat_text_view_get_last_contact   (EmpathyChatTextView *view);
+time_t               empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view);
+void                 empathy_chat_text_view_set_only_if_date   (EmpathyChatTextView *view,
+							        gboolean             only_if_date);
+void                 empathy_chat_text_view_append_body        (EmpathyChatTextView *view,
+							        const gchar         *body,
+							        const gchar         *tag);
+void                 empathy_chat_text_view_append_spacing     (EmpathyChatTextView *view);
+GtkTextTag *         empathy_chat_text_view_tag_set            (EmpathyChatTextView *view,
+							        const gchar         *tag_name,
+							        const gchar         *first_property_name,
+							        ...);
 
 G_END_DECLS
 
diff --git a/libempathy-gtk/empathy-theme-boxes.c b/libempathy-gtk/empathy-theme-boxes.c
index e6a606d..3a600a8 100644
--- a/libempathy-gtk/empathy-theme-boxes.c
+++ b/libempathy-gtk/empathy-theme-boxes.c
@@ -41,6 +41,9 @@
 #define MARGIN 4
 #define HEADER_PADDING 2
 
+/* "Join" consecutive messages with timestamps within five minutes */
+#define MESSAGE_JOIN_PERIOD 5*60
+
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeBoxes)
 typedef struct {
 	gboolean show_avatars;
@@ -200,18 +203,23 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
 	GtkTextTagTable      *table;
 	GtkTextTag           *tag;
 	GString              *str_obj;
+	gboolean              consecutive;
 
 	contact = empathy_message_get_sender (msg);
 	name = empathy_contact_get_name (contact);
 	last_contact = empathy_chat_text_view_get_last_contact (view);
 	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme));
+	time_ = empathy_message_get_timestamp (msg);
+	consecutive = (time_ - empathy_chat_text_view_get_last_timestamp (view)
+		< MESSAGE_JOIN_PERIOD);
 
 	DEBUG ("Maybe add fancy header");
 
-	/* Only insert a header if the previously inserted block is not the same
-	 * as this one.
+	/* Only insert a header if
+	 *   - the previously inserted block is not the same as this one.
+	 *   - the delay between two messages is lower then MESSAGE_JOIN_PERIOD
 	 */
-	if (empathy_contact_equal (last_contact, contact)) {
+	if (empathy_contact_equal (last_contact, contact) && consecutive) {
 		return;
 	}
 
@@ -259,7 +267,6 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
 	g_free (str);
 
 	/* Add the message receive time */
-	time_ = empathy_message_get_timestamp (msg);
 	tmp = empathy_time_to_string_local (time_,
 					   EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
 	str = g_strdup_printf ("<i>%s</i>", tmp);



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