# HG changeset patch
# Node ID 929344d62caf
# Parent  8bdccbde0536
diff --git a/libpurple/protocols/ircv3/meson.build b/libpurple/protocols/ircv3/meson.build
--- a/libpurple/protocols/ircv3/meson.build
+++ b/libpurple/protocols/ircv3/meson.build
@@ -1,14 +1,19 @@
 IRCV3_SOURCES = [
 	'purpleircv3connection.c',
+	'purpleircv3core.c',
+	'purpleircv3messagehandlers.c',
+	'purpleircv3parser.c',
+	'purpleircv3protocol.c',
+	'purpleircv3protocolim.c',
+]
+
+IRCV3_HEADERS = [
 	'purpleircv3connection.h',
-	'purpleircv3core.c',
 	'purpleircv3core.h',
-	'purpleircv3messagehandlers.c',
 	'purpleircv3messagehandlers.h',
-	'purpleircv3parser.c',
 	'purpleircv3parser.h',
-	'purpleircv3protocol.c',
 	'purpleircv3protocol.h',
+	'purpleircv3protocolim.h',
 ]
 
 if DYNAMIC_IRCV3
@@ -18,7 +23,7 @@
 		c_name : 'purple_ircv3')
 	IRCV3_SOURCES += ircv3_resources
 
-	ircv3_prpl = shared_library('ircv3', IRCV3_SOURCES,
+	ircv3_prpl = shared_library('ircv3', IRCV3_SOURCES + IRCV3_HEADERS,
 	    c_args : ['-DG_LOG_USE_STRUCTURED', '-DG_LOG_DOMAIN="Purple-IRCv3"'],
 	    dependencies : [sasl, libpurple_dep, glib, gio, ws2_32],
 	    install : true, install_dir : PURPLE_PLUGINDIR)
diff --git a/libpurple/protocols/ircv3/purpleircv3messagehandlers.c b/libpurple/protocols/ircv3/purpleircv3messagehandlers.c
--- a/libpurple/protocols/ircv3/purpleircv3messagehandlers.c
+++ b/libpurple/protocols/ircv3/purpleircv3messagehandlers.c
@@ -180,7 +180,7 @@
 		if(target[0] == '#') {
 			conversation = purple_chat_conversation_new(account, target);
 		} else {
-			conversation = purple_im_conversation_new(account, target);
+			conversation = purple_im_conversation_new(account, source);
 		}
 
 		purple_conversation_manager_register(conversation_manager,
diff --git a/libpurple/protocols/ircv3/purpleircv3protocol.c b/libpurple/protocols/ircv3/purpleircv3protocol.c
--- a/libpurple/protocols/ircv3/purpleircv3protocol.c
+++ b/libpurple/protocols/ircv3/purpleircv3protocol.c
@@ -22,6 +22,7 @@
 
 #include "purpleircv3connection.h"
 #include "purpleircv3core.h"
+#include "purpleircv3protocolim.h"
 
 /******************************************************************************
  * PurpleProtocol Implementation
@@ -137,8 +138,13 @@
 /******************************************************************************
  * GObject Implementation
  *****************************************************************************/
-G_DEFINE_DYNAMIC_TYPE(PurpleIRCv3Protocol, purple_ircv3_protocol,
-                      PURPLE_TYPE_PROTOCOL)
+G_DEFINE_DYNAMIC_TYPE_EXTENDED(
+	PurpleIRCv3Protocol,
+	purple_ircv3_protocol,
+	PURPLE_TYPE_PROTOCOL,
+	G_TYPE_FLAG_DERIVABLE,
+	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_IM,
+	                              purple_ircv3_protocol_im_init))
 
 static void
 purple_ircv3_protocol_init(PurpleIRCv3Protocol *protocol) {
diff --git a/libpurple/protocols/ircv3/purpleircv3protocolim.h b/libpurple/protocols/ircv3/purpleircv3protocolim.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/ircv3/purpleircv3protocolim.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_IRCV3_PROTOCOL_IM_H
+#define PURPLE_IRCV3_PROTOCOL_IM_H
+
+#include <glib.h>
+
+#include <purple.h>
+
+G_GNUC_INTERNAL void purple_ircv3_protocol_im_init(PurpleProtocolIMInterface *iface);
+
+#endif /* PURPLE_IRCV3_PROTOCOL_IM_H */
diff --git a/libpurple/protocols/ircv3/purpleircv3protocolim.c b/libpurple/protocols/ircv3/purpleircv3protocolim.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/ircv3/purpleircv3protocolim.c
@@ -0,0 +1,49 @@
+/*
+ * 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 "purpleircv3protocolim.h"
+
+#include "purpleircv3connection.h"
+
+/******************************************************************************
+ * PurpleProtocolIM Implementation
+ *****************************************************************************/
+static gint
+purple_ircv3_protocol_send_im(PurpleProtocolIM *im,
+                              PurpleConnection *conn,
+                              PurpleMessage *message)
+{
+	PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(conn);
+	const char *contents = NULL;
+	const char *recipient = NULL;
+
+	contents = purple_message_get_contents(message);
+	recipient = purple_message_get_recipient(message);
+
+	purple_ircv3_connection_writef(connection, "PRIVMSG %s :%s", recipient,
+	                               contents);
+
+	return 1;
+}
+
+void
+purple_ircv3_protocol_im_init(PurpleProtocolIMInterface *iface) {
+	iface->send = purple_ircv3_protocol_send_im;
+}
