aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy-gtk/empathy-theme-adium.c131
-rw-r--r--libempathy/empathy-log-store-empathy.c1
-rw-r--r--libempathy/empathy-message.c36
-rw-r--r--libempathy/empathy-message.h3
4 files changed, 150 insertions, 21 deletions
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index f37c98841..d513c91ae 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -52,6 +52,7 @@ typedef struct {
EmpathySmileyManager *smiley_manager;
EmpathyContact *last_contact;
time_t last_timestamp;
+ gboolean last_is_backlog;
gboolean page_loaded;
GList *message_queue;
} EmpathyThemeAdiumPriv;
@@ -66,12 +67,20 @@ struct _EmpathyAdiumData {
gchar *template_html;
gchar *in_content_html;
gsize in_content_len;
+ gchar *in_context_html;
+ gsize in_context_len;
gchar *in_nextcontent_html;
gsize in_nextcontent_len;
+ gchar *in_nextcontext_html;
+ gsize in_nextcontext_len;
gchar *out_content_html;
gsize out_content_len;
+ gchar *out_context_html;
+ gsize out_context_len;
gchar *out_nextcontent_html;
gsize out_nextcontent_len;
+ gchar *out_nextcontext_html;
+ gsize out_nextcontext_len;
gchar *status_html;
gsize status_len;
GHashTable *info;
@@ -405,7 +414,8 @@ theme_adium_append_message (EmpathyChatView *view,
gsize len = 0;
const gchar *func;
const gchar *service_name;
- const gchar *message_classes = NULL;
+ GString *message_classes = NULL;
+ gboolean is_backlog;
if (!priv->page_loaded) {
priv->message_queue = g_list_prepend (priv->message_queue,
@@ -458,46 +468,103 @@ theme_adium_append_message (EmpathyChatView *view,
avatar_filename = priv->data->default_avatar_filename;
}
}
+
+ is_backlog = empathy_message_is_backlog (msg);
/* Get the right html/func to add the message */
func = "appendMessage";
+
+ message_classes = g_string_new ("message");
+
+ /* eventually append the "history" class */
+ if (is_backlog) {
+ g_string_append (message_classes, " history");
+ }
+
+ /* check the sender of the message and append the appropriate class */
+ if (empathy_contact_is_user (sender)) {
+ g_string_append (message_classes, " outgoing");
+ }
+ else {
+ g_string_append (message_classes, " incoming");
+ }
+
/*
* To mimick Adium's behavior, we only want to join messages
- * sent within a 5 minute time frame.
+ * sent by the same contact within a 5 minute time frame.
*/
if (empathy_contact_equal (priv->last_contact, sender) &&
- (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD)) {
+ (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) &&
+ (is_backlog == priv->last_is_backlog)) {
+ /* the messages can be appended */
func = "appendNextMessage";
+ g_string_append (message_classes, " consecutive");
+
+ /* check who is the sender of the message to use the correct html file */
if (empathy_contact_is_user (sender)) {
- message_classes = "consecutive incoming message";
- html = priv->data->out_nextcontent_html;
- len = priv->data->out_nextcontent_len;
+ /* check if this is a backlog message and use NextContext.html */
+ if (is_backlog) {
+ html = priv->data->out_nextcontext_html;
+ len = priv->data->out_nextcontext_len;
+ }
+
+ /*
+ * html is null if this is not a backlog message or
+ * if we have to fallback (NextContext.html missing).
+ * use NextContent.html
+ */
+ if (html == NULL) {
+ html = priv->data->out_nextcontent_html;
+ len = priv->data->out_nextcontent_len;
+ }
}
- if (!html) {
- message_classes = "consecutive message outgoing";
- html = priv->data->in_nextcontent_html;
- len = priv->data->in_nextcontent_len;
+ else {
+ if (is_backlog) {
+ html = priv->data->in_nextcontext_html;
+ len = priv->data->in_nextcontext_len;
+ }
+
+ if (html == NULL) {
+ html = priv->data->in_nextcontent_html;
+ len = priv->data->in_nextcontent_len;
+ }
}
}
- if (!html) {
+
+ /*
+ * we have html == NULL here if:
+ * 1. the message didn't have to be appended because
+ * the sender was different or the timestamp was too far
+ * 2. NextContent.html file does not exist, so we must
+ * not forget to fallback to the correct Content.html
+ */
+ if (html == NULL) {
if (empathy_contact_is_user (sender)) {
- if (!message_classes) {
- message_classes = "incoming message";
+ if (is_backlog) {
+ html = priv->data->out_context_html;
+ len = priv->data->out_context_len;
+ }
+
+ if (html == NULL) {
+ html = priv->data->out_content_html;
+ len = priv->data->out_content_len;
}
- html = priv->data->out_content_html;
- len = priv->data->out_content_len;
}
- if (!html) {
- if (!message_classes) {
- message_classes = "message outgoing";
+ else {
+ if (is_backlog) {
+ html = priv->data->in_context_html;
+ len = priv->data->in_context_len;
+ }
+
+ if (html == NULL) {
+ html = priv->data->in_content_html;
+ len = priv->data->in_content_len;
}
- html = priv->data->in_content_html;
- len = priv->data->in_content_len;
}
}
theme_adium_append_html (theme, func, html, len, body, avatar_filename,
- name, contact_id, service_name, message_classes,
+ name, contact_id, service_name, message_classes->str,
timestamp);
/* Keep the sender of the last displayed message */
@@ -506,8 +573,10 @@ theme_adium_append_message (EmpathyChatView *view,
}
priv->last_contact = g_object_ref (sender);
priv->last_timestamp = timestamp;
+ priv->last_is_backlog = is_backlog;
g_free (dup_body);
+ g_string_free (message_classes, TRUE);
}
static void
@@ -914,6 +983,14 @@ empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL);
g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL);
g_free (file);
+
+ file = g_build_filename (data->basedir, "Incoming", "Context.html", NULL);
+ g_file_get_contents (file, &data->in_context_html, &data->in_context_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Incoming", "NextContext.html", NULL);
+ g_file_get_contents (file, &data->in_nextcontext_html, &data->in_nextcontext_len, NULL);
+ g_free (file);
file = g_build_filename (data->basedir, "Outgoing", "Content.html", NULL);
g_file_get_contents (file, &data->out_content_html, &data->out_content_len, NULL);
@@ -923,6 +1000,14 @@ empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
g_file_get_contents (file, &data->out_nextcontent_html, &data->out_nextcontent_len, NULL);
g_free (file);
+ file = g_build_filename (data->basedir, "Outgoing", "Context.html", NULL);
+ g_file_get_contents (file, &data->out_context_html, &data->out_context_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Outgoing", "NextContext.html", NULL);
+ g_file_get_contents (file, &data->out_nextcontext_html, &data->out_nextcontext_len, NULL);
+ g_free (file);
+
file = g_build_filename (data->basedir, "Status.html", NULL);
g_file_get_contents (file, &data->status_html, &data->status_len, NULL);
g_free (file);
@@ -1042,8 +1127,12 @@ empathy_adium_data_unref (EmpathyAdiumData *data)
g_free (data->template_html);
g_free (data->in_content_html);
g_free (data->in_nextcontent_html);
+ g_free (data->in_context_html);
+ g_free (data->in_nextcontext_html);
g_free (data->out_content_html);
g_free (data->out_nextcontent_html);
+ g_free (data->out_context_html);
+ g_free (data->out_nextcontext_html);
g_free (data->default_avatar_filename);
g_free (data->default_incoming_avatar_filename);
g_free (data->default_outgoing_avatar_filename);
diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c
index 7e50cb12f..b73c7218c 100644
--- a/libempathy/empathy-log-store-empathy.c
+++ b/libempathy/empathy-log-store-empathy.c
@@ -497,6 +497,7 @@ log_store_empathy_get_messages_for_file (EmpathyLogStore *self,
empathy_message_set_sender (message, sender);
empathy_message_set_timestamp (message, t);
empathy_message_set_tptype (message, msg_type);
+ empathy_message_set_is_backlog (message, TRUE);
if (cm_id_str)
empathy_message_set_id (message, cm_id);
diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c
index d020b72e4..41b44bfb3 100644
--- a/libempathy/empathy-message.c
+++ b/libempathy/empathy-message.c
@@ -39,6 +39,7 @@ typedef struct {
EmpathyContact *receiver;
gchar *body;
time_t timestamp;
+ gboolean is_backlog;
guint id;
} EmpathyMessagePriv;
@@ -61,6 +62,7 @@ enum {
PROP_RECEIVER,
PROP_BODY,
PROP_TIMESTAMP,
+ PROP_IS_BACKLOG,
};
static void
@@ -112,6 +114,13 @@ empathy_message_class_init (EmpathyMessageClass *class)
G_MAXLONG,
-1,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_IS_BACKLOG,
+ g_param_spec_boolean ("is-backlog",
+ "History message",
+ "If the message belongs to history",
+ FALSE,
+ G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (EmpathyMessagePriv));
@@ -387,6 +396,33 @@ empathy_message_set_timestamp (EmpathyMessage *message,
g_object_notify (G_OBJECT (message), "timestamp");
}
+gboolean
+empathy_message_is_backlog (EmpathyMessage *message)
+{
+ EmpathyMessagePriv *priv;
+
+ g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
+
+ priv = GET_PRIV (message);
+
+ return priv->is_backlog;
+}
+
+void
+empathy_message_set_is_backlog (EmpathyMessage *message,
+ gboolean is_backlog)
+{
+ EmpathyMessagePriv *priv;
+
+ g_return_if_fail (EMPATHY_IS_MESSAGE (message));
+
+ priv = GET_PRIV (message);
+
+ priv->is_backlog = is_backlog;
+
+ g_object_notify (G_OBJECT (message), "is-backlog");
+}
+
#define IS_SEPARATOR(ch) (ch == ' ' || ch == ',' || ch == '.' || ch == ':')
gboolean
empathy_message_should_highlight (EmpathyMessage *message)
diff --git a/libempathy/empathy-message.h b/libempathy/empathy-message.h
index 2172c9784..00064df57 100644
--- a/libempathy/empathy-message.h
+++ b/libempathy/empathy-message.h
@@ -68,6 +68,9 @@ void empathy_message_set_body (EmpathyMessage
time_t empathy_message_get_timestamp (EmpathyMessage *message);
void empathy_message_set_timestamp (EmpathyMessage *message,
time_t timestamp);
+gboolean empathy_message_is_backlog (EmpathyMessage *message);
+void empathy_message_set_is_backlog (EmpathyMessage *message,
+ gboolean is_backlog);
gboolean empathy_message_should_highlight (EmpathyMessage *message);
TpChannelTextMessageType empathy_message_type_from_str (const gchar *type_str);
const gchar * empathy_message_type_to_str (TpChannelTextMessageType type);