# HG changeset patch
# Node ID 0644fd919b94
# Parent  3c11bbd93e97
diff --git a/libpurple/protocols/demo/purpledemoprotocol.c b/libpurple/protocols/demo/purpledemoprotocol.c
--- a/libpurple/protocols/demo/purpledemoprotocol.c
+++ b/libpurple/protocols/demo/purpledemoprotocol.c
@@ -29,6 +29,69 @@ struct _PurpleDemoProtocol {
 };
 
 /******************************************************************************
+ * PurpleProtocolIM Implementation
+ *****************************************************************************/
+typedef struct {
+	PurpleConnection *connection;
+	PurpleMessage *message;
+} PurpleDemoProtocolIMInfo;
+
+static void
+purple_demo_protocol_im_info_free(PurpleDemoProtocolIMInfo *info) {
+	g_object_unref(info->message);
+	g_free(info);
+}
+
+static gboolean
+purple_demo_protocol_echo_im_cb(gpointer data)
+{
+	PurpleDemoProtocolIMInfo *info = data;
+	const char *who = NULL;
+	PurpleMessageFlags flags;
+	GDateTime *timestamp = NULL;
+
+	/* Turn outgoing message back incoming. */
+	who = purple_message_get_recipient(info->message);
+	flags = purple_message_get_flags(info->message);
+	flags &= ~PURPLE_MESSAGE_SEND;
+	flags |= PURPLE_MESSAGE_RECV;
+	timestamp = purple_message_get_timestamp(info->message);
+
+	purple_serv_got_im(info->connection, who,
+	                   purple_message_get_contents(info->message), flags,
+	                   g_date_time_to_unix(timestamp));
+
+	g_date_time_unref(timestamp);
+
+	return FALSE;
+}
+
+static gint
+purple_demo_protocol_send_im(PurpleProtocolIM *im, PurpleConnection *conn,
+                             PurpleMessage *msg)
+{
+	const gchar *who = purple_message_get_recipient(msg);
+
+	if(purple_strequal(who, "Echo")) {
+		PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);
+
+		info->connection = conn;
+		info->message = g_object_ref(msg);
+
+		g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+		                purple_demo_protocol_echo_im_cb, info,
+		                (GDestroyNotify)purple_demo_protocol_im_info_free);
+	}
+
+	return 1;
+}
+
+static void
+purple_demo_protocol_im_iface_init(PurpleProtocolIMInterface *iface) {
+	iface->send = purple_demo_protocol_send_im;
+}
+
+/******************************************************************************
  * PurpleProtocolClient Implementation
  *****************************************************************************/
 static gchar *
@@ -107,6 +170,8 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED(
 	0,
 	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CLIENT,
 	                              purple_demo_protocol_client_init)
+        G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_IM,
+                                      purple_demo_protocol_im_iface_init)
 )
 
 static void
diff --git a/libpurple/protocols/demo/resources/buddy_icons/Echo.png b/libpurple/protocols/demo/resources/buddy_icons/Echo.png
new file mode 100644
index 0000000000000000000000000000000000000000..5e412282f91b9eea8163e3deb5c13510f6171353
GIT binary patch
diff --git a/libpurple/protocols/demo/resources/contacts.json b/libpurple/protocols/demo/resources/contacts.json
--- a/libpurple/protocols/demo/resources/contacts.json
+++ b/libpurple/protocols/demo/resources/contacts.json
@@ -43,5 +43,14 @@
 				"message": "Writing crazy patches!"
 			}
 		}]
+	}],
+	"Nymphs": [{
+		"buddies": [{
+			"name": "Echo",
+			"status": {
+				"id": "available",
+				"message": "Cursed to speak the last words spoken to me"
+			}
+		}]
 	}]
 }
diff --git a/libpurple/protocols/demo/resources/purpledemo.gresource.xml b/libpurple/protocols/demo/resources/purpledemo.gresource.xml
--- a/libpurple/protocols/demo/resources/purpledemo.gresource.xml
+++ b/libpurple/protocols/demo/resources/purpledemo.gresource.xml
@@ -6,6 +6,7 @@
     <file>icons/22x22/apps/im-purple-demo.png</file>
     <file>icons/48x48/apps/im-purple-demo.png</file>
     <file>icons/scalable/apps/im-purple-demo.svg</file>
+    <file>buddy_icons/Echo.png</file>
     <file>buddy_icons/Eion.png</file>
     <file>buddy_icons/Elliott.png</file>
     <file>buddy_icons/Gary.png</file>
