--- empathy-2.29.93/src/empathy-chat-window.c	2010-03-23 17:31:13.961088570 +0100
+++ empathy-2.29.93/src/empathy-chat-window.c	2010-03-23 17:32:44.553587269 +0100
@@ -78,6 +78,7 @@
 	EmpathyNotifyManager *notify_mgr;
 	GtkWidget   *dialog;
 	GtkWidget   *notebook;
+	GMutex      *notification_mutex;
 	NotifyNotification *notification;
 	NotificationData *notification_data;
 
@@ -1210,9 +1211,16 @@
 	}
 
 	g_object_unref (notify);
-	priv->notification = NULL;
 	free_notification_data (cb_data);
-	priv->notification_data = NULL;
+
+	g_mutex_lock (priv->notification_mutex);
+
+	if (priv->notification == notify) {
+		priv->notification = NULL;
+		priv->notification_data = NULL;
+	}
+
+	g_mutex_unlock (priv->notification_mutex);
 }
 
 static void
@@ -1226,7 +1234,7 @@
 	const char *body;
 	GdkPixbuf *pixbuf;
 	EmpathyChatWindowPriv *priv = GET_PRIV (window);
-	gboolean res;
+	gboolean res, has_x_canonical_append;
 
 	if (!empathy_notify_manager_notification_is_enabled (priv->notify_mgr)) {
 		return;
@@ -1242,11 +1250,19 @@
 	header = empathy_contact_get_name (sender);
 	body = empathy_message_get_body (message);
 	escaped = g_markup_escape_text (body, -1);
+	has_x_canonical_append = empathy_notify_manager_has_capability (priv->notify_mgr,
+		EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND);
 
-	if (priv->notification != NULL) {
+	g_mutex_lock (priv->notification_mutex);
+	
+	if (priv->notification != NULL && ! has_x_canonical_append) {
 		notify_notification_update (priv->notification,
 					    header, escaped, NULL);
 	} else {
+		if (priv->notification != NULL) {
+			g_object_unref (priv->notification);
+		}
+		
 		NotificationData *cb_data = cb_data = g_slice_new0 (NotificationData);
 
 		cb_data->chat = g_object_ref (chat);
@@ -1258,6 +1274,11 @@
 
 		g_signal_connect (priv->notification, "closed",
 				  G_CALLBACK (chat_window_notification_closed_cb), cb_data);
+
+		if (has_x_canonical_append) {
+			notify_notification_set_hint_string (priv->notification,
+				EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND, "");
+		}
 	}
 
 	pixbuf = empathy_notify_manager_get_pixbuf_for_notification (priv->notify_mgr,
@@ -1269,6 +1290,7 @@
 	}
 
 	notify_notification_show (priv->notification, NULL);
+	g_mutex_unlock (priv->notification_mutex);
 
 	g_free (escaped);
 }
@@ -1760,9 +1782,10 @@
 	g_object_unref (priv->chatroom_manager);
 	g_object_unref (priv->notify_mgr);
 
+	g_mutex_lock (priv->notification_mutex);
+
 	if (priv->notification != NULL) {
 		notify_notification_close (priv->notification, NULL);
-		g_object_unref (priv->notification);
 		priv->notification = NULL;
 		if (priv->notification_data != NULL)
 			{
@@ -1771,6 +1794,9 @@
 			}
 	}
 
+	g_mutex_unlock (priv->notification_mutex);
+	g_mutex_free (priv->notification_mutex);
+
 	if (priv->contact_targets) {
 		gtk_target_list_unref (priv->contact_targets);
 	}
@@ -1957,6 +1983,9 @@
 	chat_windows = g_list_prepend (chat_windows, window);
 
 	/* Set up private details */
+	g_thread_init (NULL);
+	priv->notification_mutex = g_mutex_new ();
+	priv->notification = NULL;
 	priv->chats = NULL;
 	priv->chats_new_msg = NULL;
 	priv->chats_composing = NULL;
