commit 6c7366ddc98e9f97962f73ffdced85911cf876fa
Author: Ken VanDine <ken.vandine@canonical.com>
Date:   Tue Jan 19 09:11:48 2010 -0500

     * Adds support for the "x-canonical-append" hint from notify-osd, which appends notifications when possible.  bz# 607446
     * Only attach the notification to the status icon if the status icon is displayed.

diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c
index 2dabc54..cc3c8a7 100644
--- a/src/empathy-status-icon.c
+++ b/src/empathy-status-icon.c
@@ -85,6 +85,32 @@ activate_event (EmpathyEvent *event)
 	return FALSE;
 }
 
+/* Query whether the notification server supports the "append"
+ * extension to the notifications specification.
+ */
+static gboolean
+notification_server_supports_append (void)
+{
+        GList *caps = notify_get_server_caps ();
+        GList *l;
+        gboolean ret = FALSE;
+
+        for (l = caps; l; l = l->next) {
+                gchar *cap = (gchar *) l->data;
+                if (!cap) {
+                        continue;
+                }
+                if (!tp_strdiff (cap, "x-canonical-append")) {
+                        ret = TRUE;
+                        break;
+                }
+        }
+        g_list_foreach (caps, (GFunc)g_free, NULL);
+        g_list_free (caps);
+
+        return ret;
+}
+
 static void
 status_icon_notification_closed_cb (NotifyNotification *notification,
 				    EmpathyStatusIcon  *icon)
@@ -158,13 +184,18 @@ status_icon_update_notification (EmpathyStatusIcon *icon)
 		if (priv->event->message != NULL)
 			message_esc = g_markup_escape_text (priv->event->message, -1);
 
-		if (priv->notification) {
+		if ((priv->notification) && (!notification_server_supports_append ())) {
 			notify_notification_update (priv->notification,
 						    priv->event->header, message_esc,
 						    NULL);
 		} else {
-			priv->notification = notify_notification_new_with_status_icon
-				(priv->event->header, message_esc, NULL, priv->icon);
+			if (gtk_status_icon_get_visible (priv->icon)) {
+				priv->notification = notify_notification_new_with_status_icon
+					(priv->event->header, message_esc, "notification-message-im", priv->icon);
+			} else {
+				priv->notification = notify_notification_new
+					(priv->event->header, message_esc, "notification-message-im", NULL);
+			}
 			notify_notification_set_timeout (priv->notification,
 							 NOTIFY_EXPIRES_DEFAULT);
 
@@ -192,6 +223,10 @@ status_icon_update_notification (EmpathyStatusIcon *icon)
 			g_object_unref (pixbuf);
 		}
 
+		if (notification_server_supports_append ()) {
+			notify_notification_set_hint_string (priv->notification,
+				"x-canonical-append", "");
+		}
 		notify_notification_show (priv->notification, NULL);
 
 		g_free (message_esc);
