aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-theme-adium.c
diff options
context:
space:
mode:
Diffstat (limited to 'libempathy-gtk/empathy-theme-adium.c')
-rw-r--r--libempathy-gtk/empathy-theme-adium.c163
1 files changed, 136 insertions, 27 deletions
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index 06410c528..b62b017c9 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -61,6 +61,9 @@ typedef struct {
guint pages_loading;
/* Queue of GValue* containing an EmpathyMessage or string */
GQueue message_queue;
+ /* Queue of owned gchar* of message token to remove unread
+ * marker for when we lose focus. */
+ GQueue acked_messages;
GtkWidget *inspector_window;
GSettings *gsettings_chat;
gboolean has_focus;
@@ -569,32 +572,10 @@ theme_adium_append_event_escaped (EmpathyChatView *view,
}
static void
-theme_adium_remove_focus_marks (EmpathyThemeAdium *theme)
+theme_adium_remove_focus_marks (EmpathyThemeAdium *theme,
+ WebKitDOMNodeList *nodes)
{
- EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
- WebKitDOMDocument *dom;
- WebKitDOMNodeList *nodes;
guint i;
- GError *error = NULL;
-
- if (!priv->has_unread_message)
- return;
-
- priv->has_unread_message = FALSE;
-
- dom = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (theme));
- if (dom == NULL) {
- return;
- }
-
- /* Get all nodes with focus class */
- nodes = webkit_dom_document_query_selector_all (dom, ".focus", &error);
- if (nodes == NULL) {
- DEBUG ("Error getting focus nodes: %s",
- error ? error->message : "No error");
- g_clear_error (&error);
- return;
- }
/* Remove focus and firstFocus class */
for (i = 0; i < webkit_dom_node_list_get_length (nodes); i++) {
@@ -632,12 +613,43 @@ theme_adium_remove_focus_marks (EmpathyThemeAdium *theme)
}
static void
+theme_adium_remove_all_focus_marks (EmpathyThemeAdium *theme)
+{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+ WebKitDOMDocument *dom;
+ WebKitDOMNodeList *nodes;
+ GError *error = NULL;
+
+ if (!priv->has_unread_message)
+ return;
+
+ priv->has_unread_message = FALSE;
+
+ dom = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (theme));
+ if (dom == NULL) {
+ return;
+ }
+
+ /* Get all nodes with focus class */
+ nodes = webkit_dom_document_query_selector_all (dom, ".focus", &error);
+ if (nodes == NULL) {
+ DEBUG ("Error getting focus nodes: %s",
+ error ? error->message : "No error");
+ g_clear_error (&error);
+ return;
+ }
+
+ theme_adium_remove_focus_marks (theme, nodes);
+}
+
+static void
theme_adium_append_message (EmpathyChatView *view,
EmpathyMessage *msg)
{
EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
EmpathyContact *sender;
+ TpMessage *tp_msg;
TpAccount *account;
gchar *body_escaped;
const gchar *body;
@@ -759,6 +771,20 @@ theme_adium_append_message (EmpathyChatView *view,
* %status% - See %status% in theme_adium_append_html ()
*/
+ /* This is slightly a hack, but it's the only way to add
+ * arbitrary data to messages in the HTML. We add another
+ * class called "x-empathy-message-id-*" to the message. This
+ * way, we can remove the unread marker for this specific
+ * message later. */
+ tp_msg = empathy_message_get_tp_message (msg);
+ if (tp_msg != NULL) {
+ gchar *tmp = tp_escape_as_identifier (
+ tp_message_get_token (tp_msg));
+ g_string_append_printf (message_classes,
+ " x-empathy-message-id-%s", tmp);
+ g_free (tmp);
+ }
+
/* Define javascript function to use */
if (consecutive) {
func = priv->allow_scrolling ? "appendNextMessage" : "appendNextMessageNoScroll";
@@ -777,7 +803,7 @@ theme_adium_append_message (EmpathyChatView *view,
}
/* remove all the unread marks when we are sending a message */
- theme_adium_remove_focus_marks (theme);
+ theme_adium_remove_all_focus_marks (theme);
} else {
/* in */
if (is_backlog) {
@@ -927,16 +953,93 @@ theme_adium_copy_clipboard (EmpathyChatView *view)
}
static void
+theme_adium_remove_mark_from_message (EmpathyThemeAdium *self,
+ const gchar *token)
+{
+ WebKitDOMDocument *dom;
+ WebKitDOMNodeList *nodes;
+ gchar *class, *tmp;
+ GError *error = NULL;
+
+ dom = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (self));
+ if (dom == NULL) {
+ return;
+ }
+
+ tmp = tp_escape_as_identifier (token);
+ class = g_strdup_printf (".x-empathy-message-id-%s", tmp);
+ g_free (tmp);
+
+ /* Get all nodes with focus class */
+ nodes = webkit_dom_document_query_selector_all (dom, class, &error);
+ g_free (class);
+
+ if (nodes == NULL) {
+ DEBUG ("Error getting focus nodes: %s",
+ error ? error->message : "No error");
+ g_clear_error (&error);
+ return;
+ }
+
+ theme_adium_remove_focus_marks (self, nodes);
+}
+
+static void
+theme_adium_remove_acked_message_unread_mark_foreach (gpointer data,
+ gpointer user_data)
+{
+ EmpathyThemeAdium *self = user_data;
+ gchar *token = data;
+
+ theme_adium_remove_mark_from_message (self, token);
+ g_free (token);
+}
+
+static void
theme_adium_focus_toggled (EmpathyChatView *view,
gboolean has_focus)
{
- EmpathyThemeAdium *self = (EmpathyThemeAdium *) view;
EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
priv->has_focus = has_focus;
if (!priv->has_focus) {
- theme_adium_remove_focus_marks (self);
+ /* We've lost focus, so let's make sure all the acked
+ * messages have lost their unread marker. */
+ g_queue_foreach (&priv->acked_messages,
+ theme_adium_remove_acked_message_unread_mark_foreach,
+ view);
+ g_queue_clear (&priv->acked_messages);
+
+ priv->has_unread_message = FALSE;
+ }
+}
+
+static void
+theme_adium_message_acknowledged (EmpathyChatView *view,
+ EmpathyMessage *message)
+{
+ EmpathyThemeAdium *self = (EmpathyThemeAdium *) view;
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
+ TpMessage *tp_msg;
+
+ tp_msg = empathy_message_get_tp_message (message);
+
+ if (tp_msg == NULL) {
+ return;
}
+
+ /* We only want to actually remove the unread marker if the
+ * view doesn't have focus. If we did it all the time we would
+ * never see the unread markers, ever! So, we'll queue these
+ * up, and when we lose focus, we'll remove the markers. */
+ if (priv->has_focus) {
+ g_queue_push_tail (&priv->acked_messages,
+ g_strdup (tp_message_get_token (tp_msg)));
+ return;
+ }
+
+ theme_adium_remove_mark_from_message (self,
+ tp_message_get_token (tp_msg));
}
static void
@@ -1059,6 +1162,7 @@ theme_adium_iface_init (EmpathyChatViewIface *iface)
iface->highlight = theme_adium_highlight;
iface->copy_clipboard = theme_adium_copy_clipboard;
iface->focus_toggled = theme_adium_focus_toggled;
+ iface->message_acknowledged = theme_adium_message_acknowledged;
}
static void
@@ -1124,6 +1228,11 @@ theme_adium_dispose (GObject *object)
priv->inspector_window = NULL;
}
+ if (priv->acked_messages.length > 0) {
+ g_queue_foreach (&priv->acked_messages, (GFunc) g_free, NULL);
+ g_queue_clear (&priv->acked_messages);
+ }
+
G_OBJECT_CLASS (empathy_theme_adium_parent_class)->dispose (object);
}