#include <libempathy/empathy-utils.h>
#include "empathy-theme-boxes.h"
#include "empathy-ui-utils.h"
-#include "empathy-conf.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include <libempathy/empathy-debug.h>
#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;
- guint notify_show_avatars_id;
} EmpathyThemeBoxesPriv;
G_DEFINE_TYPE (EmpathyThemeBoxes, empathy_theme_boxes, EMPATHY_TYPE_CHAT_TEXT_VIEW);
typedef struct {
GdkPixbuf *pixbuf;
- gchar *token;
+ gchar *filename;
} AvatarData;
static void
AvatarData *data = ptr;
g_object_unref (data->pixbuf);
- g_free (data->token);
+ g_free (data->filename);
g_slice_free (AvatarData, data);
}
avatar = empathy_contact_get_avatar (contact);
data = g_object_get_data (G_OBJECT (contact), "chat-view-avatar-cache");
if (data) {
- if (avatar && !tp_strdiff (avatar->token, data->token)) {
+ if (avatar && !tp_strdiff (avatar->filename, data->filename)) {
/* We have the avatar in cache */
return data->pixbuf;
}
return NULL;
}
- /* Insert new pixbuf in cache */
+ /* Insert new pixbuf in cache. We store the filename as it's unique
+ * for each version of an avatar, so we can use it to perform change
+ * detection (as above). */
data = g_slice_new0 (AvatarData);
- data->token = g_strdup (avatar->token);
+ data->filename = g_strdup (avatar->filename);
data->pixbuf = pixbuf;
g_object_set_data_full (G_OBJECT (contact), "chat-view-avatar-cache",
GtkTextChildAnchor *anchor;
GtkWidget *box;
gchar *str;
- time_t time;
+ gint64 time_;
gchar *tmp;
GtkTextIter start;
gboolean color_set;
GtkTextTagTable *table;
GtkTextTag *tag;
GString *str_obj;
+ gboolean consecutive;
contact = empathy_message_get_sender (msg);
- name = empathy_contact_get_name (contact);
+ name = empathy_contact_get_logged_alias (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;
}
/* Create a hbox for the header and resize it when the view allocation
* changes */
- box = gtk_hbox_new (FALSE, 0);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
g_signal_connect_object (view, "size-allocate",
G_CALLBACK (table_size_allocate_cb),
box, 0);
g_free (str);
/* Add the message receive time */
- time = empathy_message_get_timestamp (msg);
- tmp = empathy_time_to_string_local (time,
+ tmp = empathy_time_to_string_local (time_,
EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
str = g_strdup_printf ("<i>%s</i>", tmp);
label2 = g_object_new (GTK_TYPE_LABEL,
static void
theme_boxes_append_message (EmpathyChatTextView *view,
- EmpathyMessage *message)
+ EmpathyMessage *message,
+ gboolean should_highlight)
{
EmpathyContact *sender;
gchar *body;
body = g_strdup_printf (" * %s %s",
- empathy_contact_get_name (sender),
+ empathy_contact_get_logged_alias (sender),
empathy_message_get_body (message));
empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view),
body,
}
}
-static void
-theme_boxes_notify_show_avatars_cb (EmpathyConf *conf,
- const gchar *key,
- gpointer user_data)
-{
- EmpathyThemeBoxesPriv *priv = GET_PRIV (user_data);
-
- empathy_conf_get_bool (conf, key, &priv->show_avatars);
-}
-
-static void
-theme_boxes_finalize (GObject *object)
-{
- EmpathyThemeBoxesPriv *priv = GET_PRIV (object);
-
- empathy_conf_notify_remove (empathy_conf_get (),
- priv->notify_show_avatars_id);
-
- G_OBJECT_CLASS (empathy_theme_boxes_parent_class)->finalize (object);
-}
-
static void
empathy_theme_boxes_class_init (EmpathyThemeBoxesClass *class)
{
object_class = G_OBJECT_CLASS (class);
chat_text_view_class = EMPATHY_CHAT_TEXT_VIEW_CLASS (class);
- object_class->finalize = theme_boxes_finalize;
chat_text_view_class->append_message = theme_boxes_append_message;
g_type_class_add_private (object_class, sizeof (EmpathyThemeBoxesPriv));
theme->priv = priv;
- theme_boxes_create_tags (theme);
-
- priv->notify_show_avatars_id =
- empathy_conf_notify_add (empathy_conf_get (),
- EMPATHY_PREFS_UI_SHOW_AVATARS,
- theme_boxes_notify_show_avatars_cb,
- theme);
+ /* This is just hard-coded to TRUE until someone adds a tickybox in the
+ * Theme tab for it. */
+ priv->show_avatars = TRUE;
- empathy_conf_get_bool (empathy_conf_get (),
- EMPATHY_PREFS_UI_SHOW_AVATARS,
- &priv->show_avatars);
+ theme_boxes_create_tags (theme);
/* Define margin */
g_object_set (theme,