# HG changeset patch
# Node ID d91f9aba7b7d
# Parent  9c0a6010fbc5
diff --git a/libpurple/protocols/demo/meson.build b/libpurple/protocols/demo/meson.build
--- a/libpurple/protocols/demo/meson.build
+++ b/libpurple/protocols/demo/meson.build
@@ -13,8 +13,8 @@
 	'purpledemoprotocolclient.h',
 	'purpledemoprotocolcontacts.c',
 	'purpledemoprotocolcontacts.h',
-	'purpledemoprotocolim.c',
-	'purpledemoprotocolim.h',
+	'purpledemoprotocolconversation.c',
+	'purpledemoprotocolconversation.h',
 	'purpledemoprotocolmedia.c',
 	'purpledemoprotocolmedia.h',
 ]
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
@@ -24,7 +24,7 @@
 #include "purpledemoprotocolactions.h"
 #include "purpledemoprotocolclient.h"
 #include "purpledemoprotocolcontacts.h"
-#include "purpledemoprotocolim.h"
+#include "purpledemoprotocolconversation.h"
 #include "purpledemoprotocolmedia.h"
 
 struct _PurpleDemoProtocol {
@@ -102,8 +102,8 @@
 	                              purple_demo_protocol_client_init)
 	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CONTACTS,
 	                              purple_demo_protocol_contacts_init)
-	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_IM,
-	                              purple_demo_protocol_im_init)
+	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CONVERSATION,
+	                              purple_demo_protocol_conversation_init)
 	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_MEDIA,
 	                              purple_demo_protocol_media_init))
 
diff --git a/libpurple/protocols/demo/purpledemoprotocolconversation.h b/libpurple/protocols/demo/purpledemoprotocolconversation.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoprotocolconversation.h
@@ -0,0 +1,28 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef PURPLE_DEMO_PROTOCOL_CONVERSATION_H
+#define PURPLE_DEMO_PROTOCOL_CONVERSATION_H
+
+#include <glib.h>
+
+#include <purple.h>
+
+G_GNUC_INTERNAL void purple_demo_protocol_conversation_init(PurpleProtocolConversationInterface *iface);
+
+#endif /* PURPLE_DEMO_PROTOCOL_CONVERSATION_H */
diff --git a/libpurple/protocols/demo/purpledemoprotocolconversation.c b/libpurple/protocols/demo/purpledemoprotocolconversation.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoprotocolconversation.c
@@ -0,0 +1,112 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n-lib.h>
+
+#include "purpledemoprotocol.h"
+#include "purpledemoprotocolconversation.h"
+
+/******************************************************************************
+ * PurpleProtocolConversation Implementation
+ *****************************************************************************/
+typedef struct {
+	PurpleConversation *conversation;
+	PurpleMessage *message;
+} PurpleDemoProtocolIMInfo;
+
+static void
+purple_demo_protocol_im_info_free(PurpleDemoProtocolIMInfo *info) {
+	g_clear_object(&info->conversation);
+	g_clear_object(&info->message);
+	g_free(info);
+}
+
+static gboolean
+purple_demo_protocol_echo_im_cb(gpointer data) {
+	PurpleDemoProtocolIMInfo *info = data;
+	PurpleMessage *message = NULL;
+	PurpleMessageFlags flags;
+	const char *who = NULL;
+
+	/* Turn outgoing message back incoming. */
+	who = purple_conversation_get_name(info->conversation);
+
+	flags = purple_message_get_flags(info->message);
+	flags &= ~PURPLE_MESSAGE_SEND;
+	flags |= PURPLE_MESSAGE_RECV;
+
+	message = purple_message_new_incoming(who,
+	                                      purple_message_get_contents(info->message),
+	                                      flags, 0);
+
+	purple_conversation_write_message(info->conversation, message);
+	g_clear_object(&message);
+
+	return G_SOURCE_REMOVE;
+}
+
+static void
+purple_demo_protocol_send_message_async(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
+                                        PurpleConversation *conversation,
+                                        PurpleMessage *message,
+                                        GCancellable *cancellable,
+                                        GAsyncReadyCallback callback,
+                                        gpointer data)
+{
+	GTask *task = NULL;
+	const char *who = NULL;
+
+	who = purple_conversation_get_name(conversation);
+	if(purple_strempty(who)) {
+		who = purple_message_get_recipient(message);
+	}
+
+	if(purple_strequal(who, "Echo")) {
+		PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);
+
+		info->conversation = g_object_ref(conversation);
+		info->message = g_object_ref(message);
+
+		g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+		                purple_demo_protocol_echo_im_cb, info,
+		                (GDestroyNotify)purple_demo_protocol_im_info_free);
+	}
+
+	purple_conversation_write_message(conversation, message);
+
+	task = g_task_new(protocol, cancellable, callback, data);
+	g_task_return_boolean(task, TRUE);
+
+	g_clear_object(&task);
+}
+
+static gboolean
+purple_demo_protocol_send_message_finish(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
+                                         GAsyncResult *result,
+                                         GError **error)
+{
+	g_return_val_if_fail(G_IS_TASK(result), FALSE);
+
+	return g_task_propagate_boolean(G_TASK(result), error);
+}
+
+void
+purple_demo_protocol_conversation_init(PurpleProtocolConversationInterface *iface) {
+	iface->send_message_async = purple_demo_protocol_send_message_async;
+	iface->send_message_finish = purple_demo_protocol_send_message_finish;
+}
diff --git a/libpurple/protocols/demo/purpledemoprotocolim.h b/libpurple/protocols/demo/purpledemoprotocolim.h
deleted file mode 100644
--- a/libpurple/protocols/demo/purpledemoprotocolim.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Purple - Internet Messaging Library
- * Copyright (C) Pidgin Developers <devel@pidgin.im>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <https://www.gnu.org/licenses/>.
- */
-
-#ifndef PURPLE_DEMO_PROTOCOL_IM_H
-#define PURPLE_DEMO_PROTOCOL_IM_H
-
-#include <glib.h>
-
-#include <purple.h>
-
-G_GNUC_INTERNAL void purple_demo_protocol_im_init(PurpleProtocolIMInterface *iface);
-
-#endif /* PURPLE_DEMO_PROTOCOL_IM_H */
diff --git a/libpurple/protocols/demo/purpledemoprotocolim.c b/libpurple/protocols/demo/purpledemoprotocolim.c
deleted file mode 100644
--- a/libpurple/protocols/demo/purpledemoprotocolim.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Purple - Internet Messaging Library
- * Copyright (C) Pidgin Developers <devel@pidgin.im>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <https://www.gnu.org/licenses/>.
- */
-
-#include <glib/gi18n-lib.h>
-
-#include "purpledemoprotocol.h"
-#include "purpledemoprotocolim.h"
-
-/******************************************************************************
- * 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));
-
-	return FALSE;
-}
-
-static gint
-purple_demo_protocol_send_im(G_GNUC_UNUSED PurpleProtocolIM *im,
-                             PurpleConnection *conn,
-                             G_GNUC_UNUSED PurpleConversation *conversation,
-                             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;
-}
-
-void
-purple_demo_protocol_im_init(PurpleProtocolIMInterface *iface) {
-	iface->send = purple_demo_protocol_send_im;
-}
